Patterns & OO Design - Database Design Pattern

hi all,

I am developing a J2SE application which is communicating with two DB schemas.

Do any one suggest any good design pattern to manage these type of situation.

I was thinking to create two DAO classess for two different DB schemas?

I am using oracle 10g as database.

Regards

[317 byte] By [emmi@javaa] at [2007-11-26 23:30:39]
# 1
I think it would be better to design your DAO's around your tables and/or logical and business relationships between them. A schema is a somewhat arbitrary grouping. I would not organize my DAO's around them.- Saish
Saisha at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
hi saish,Then how i manage my connection/datasource with those db schema i think i will require two datasources.Please help me how i will write my connection manger class and how i call it from other DAO.Regards,
emmi@javaa at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
What RDBMS are you using? Normally a connection pool is dedicated to a specific database instance not a mere schema.- Saish
Saisha at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 4
Meaning that the same connection pool will ordinarily service multiple schemas without issues.- Saish
Saisha at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 5

I am using oracle 10g as database.

Keep in mind that Oracle is not a database. Oracle is a database management system (DBMS).

Oracle is a tool used to manage relational databases.

Applications are designed to connect to their databases via Oracle.

Again for clarity, Oracle is not a database.

GhostRadioTwoa at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 6
maybe useful, http://www.rampant-books.com/book_2006_1_sql_coding_styles.htm
mchan0a at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 7
Keep in mind that Oracle is not a database. Oracle is a database management system (DBMS).RDBMS, no? Then what is the official name for the database itself? - Saish
Saisha at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 8

Keep in mind that Oracle is not a database. Oracle

is a database management system (DBMS).

RDBMS, no?

Both acronyms apply; Oracle is a DBMS and a RDBMS.

Then what is the official name for the

database itself?

There is no official name for "the" database, because Oracle is not a database. Oracle, SQL Server, etc. are software for managing relational databases. They provide users with the ability to create relational databases. They provide various transactional and security features related to relational databases. They host a query language interpreter so that users can search relational databases. They have internal systems databases for managing the databases that users create.

GhostRadioTwoa at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 9
hi,how i can connect with one db because we provide URL , username and password, and my schemas have different username and password.Regards,Imran
emmi@javaa at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 10
Are you using the term "schema" to describe a relational database?Are you using the term "schema" to describe a relational table?
GhostRadioTwoa at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 11

I am using oracle 10g as database.

Keep in mind that Oracle is not a database. Oracle is

a database management system (DBMS).

Oracle is a tool used to manage relational

databases.

Applications are designed to connect to their

databases via Oracle.

Again for clarity, Oracle is not a database.

Interesting. I always had the fuzzy idea what was going on but I never could conceptualize the idea. (Now if I can just remember it.)

jschella at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 12

how i can connect with one db because we provide URL

, username and password, and my schemas have

different username and password.

This one I can answer - you need two different pools.

Regardless of that I suspect that your data model entites will still come from a single source. So each implementation of a data entity will use the correct pool.

jschella at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 13

I also think that you should use 2 different pools.

If you are going to use some frameworks that inject the datasource in the DAO objects you will need at least one DAO for each schema. This kind of frameworks (Spring, Hibernate) expect to handle only one Datasource per DAO (which is a good design even you do not use them).

I say at least one because it would be a good practice to have more DAO for a bigger schema, each one related to a certain aspect of the database. A DAO could handle the tables related to a central table (pivot table).

Also keep in mind that you have to use global transaction (look for JTA and XA Oracle driver) when using multiple databases simultaneously (in same business method).

abc0xyza at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 14

hi saish,

Then how i manage my connection/datasource with those

db schema i think i will require two datasources.

Please help me how i will write my connection manger

class and how i call it from other DAO.

Regards,

You can just use one datasource and two session factories. Just specify the defaultSchema property when defining the session factories.

Torajiroua at 2007-7-10 14:41:57 > top of Java-index,Other Topics,Patterns & OO Design...
# 15
That is, if you're using Hibernate...I don't know why I assumed you are... ^^
Torajiroua at 2007-7-21 19:26:12 > top of Java-index,Other Topics,Patterns & OO Design...
# 16

hi,

I am not using hibernate infact my application have its own DB and i am using other DB for querying different information like user profile and its status.

infact i want to know how we keep our datasource that they should avaiable in whole application, either define them as static and access from any class or any other good suggetions?

regards

emmi@javaa at 2007-7-21 19:26:12 > top of Java-index,Other Topics,Patterns & OO Design...
# 17

> Both acronyms apply; Oracle is a DBMS and a RDBMS.

I agree. And it is also a 'thing'. Looking for the most precise term. But probably being a pain in the *** for doing so. :^)

> There is no official name for "the" database, because Oracle is not a database. Oracle, SQL Server, etc. are software for managing relational databases. They provide users with the ability to create relational databases. They provide various transactional and security features related to relational databases. They host a query language interpreter so that users can search relational databases. They have internal systems databases for managing the databases that users create.

Okay, I see where you are coming from now. I'll try to re-phrase what you are saying. Oracle represents a suite of tools to manage relational databases. What you mean by a database is what I normally term an 'instance', typically mapped to a given host, port and SID.

So far so good?

- Saish

Saisha at 2007-7-21 19:26:12 > top of Java-index,Other Topics,Patterns & OO Design...
# 18

> Okay, I see where you are coming from now. I'll try

> to re-phrase what you are saying. Oracle represents

> a suite of tools to manage relational databases.

Yes, Oracle is a (management system | set of tools | thing) that is used to create and manage relational databases.

When you are building a database for your application, you use Oracle to do it. When you verbally describe the database, you might say, "The application has a Oracle database." Take note, that you are using the word 'Oracle' as an adjective, not a noun. The only nouns in this sentence are 'application' and 'database'.

If someone has a cloudy understanding of what a relational database is, then they can be thinking that Oracle is the database, but it is not. This is understandable.

> What you mean by a database is what I normally term

> an 'instance', typically mapped to a given host,

> port and SID.

A relational database is a set of information in relational format. It consists of one or more relations (tables) which consist of one or more tuples (records | rows).

A relational database is (hosted | lives) in a RDBMS.

A RDBMS can (host | contain) many relational databases.

A RDBMS is installed on a (machine | node | computer). During the installation, the RDBMS is assigned a port number.

A Java-based application uses the JDBC API to communicate with the RDBMS and its API.

An example, in a recent application we created a relational database to store customer information. The name of the database is 'CRMREPORTDB'. This database consist of tables, e.g. CUSTOMER, PRODUCT, CONTACT, REGION. Each of the tables has fields (columns) which contain data.

The CRMREPORTDB relational database was created with SQL Server 2005. This database can accuratley be described as a SQL Server database. Take note that we are using SQL Server as an adjective not a noun. :o) The name of the database is: CRMREPORTDB. The official name of the database is: CRMREPORTDB.

The name of the database management system is SQL Server 2005

GhostRadioTwoa at 2007-7-21 19:26:12 > top of Java-index,Other Topics,Patterns & OO Design...
# 19

> Are you using the term "schema" to describe a

> relational database?

>

> Are you using the term "schema" to describe a

> relational table?

I think the OP is using the term schema to mean a 'schema'. In the Oracle DBMS (why we need to make this distinction in this context escapes me) a database may have many schemata. Each schema has tables. The table names between schemata can overlap. A schema can be made to inherit from another schema such that if the sub-schema does not contain a table, the parent schema's table is used.

To answer the OPs question, you can create a user that has access to both schemata and either explicitly reference the schema in your queries or have the user setup to map to the proper schema for each table (I beleive this can be done to fit most needs, talk to your DBA.) If you do this, you do not need two connections. If you do not want to use the schema names in your queries, then you will need multiple connections (if the table names are not distinct or you cannot configure as I describe above.)

dubwaia at 2007-7-21 19:26:13 > top of Java-index,Other Topics,Patterns & OO Design...
# 20

Can someone explain to me why it's important to note that Oracle is a DBMS and not a database? We can ignore that Oracle is actually a company that makes a DBMS that shares it's name.

Was there really anyone who was confused by what the OP was asking when the term Oracle Database was used? Does anyone think they are modifying Oracle's software when they write a record to the database?

dubwaia at 2007-7-21 19:26:13 > top of Java-index,Other Topics,Patterns & OO Design...
# 21
Oracle is registered trademark with the U.S. Library of Congress. When using Oracle in a sentence you should indicate the trademark with a (TM) or a (R), e.g. Oracle (TM).
GhostRadioTwoa at 2007-7-21 19:26:13 > top of Java-index,Other Topics,Patterns & OO Design...
# 22
Well, Larry Ellison can sue me if he likes because I don't attach ™ or ® when I talk about Oracle here. But I don't think it's going to happen.
DrClapa at 2007-7-21 19:26:13 > top of Java-index,Other Topics,Patterns & OO Design...
# 23
Fancy Smancy
GhostRadioTwoa at 2007-7-21 19:26:13 > top of Java-index,Other Topics,Patterns & OO Design...