making a generic data access class wrapper for underlying classes

  • Thread starter Thread starter Milsnips
  • Start date Start date
M

Milsnips

Hi there,

this is what i'm trying to achieve, i have separate identical classes for
SqlClient, OracleClient, Odbc and OleDb, what i want is to create a Wrapper
class that calls any of these 4 based on the user connection.... so what i
had in mind was something like this:


Application starts and prompts user to create a database connection.

User selects "Oracle" connect, so i set a parameter in the generic wrapper,
"activeConnection" = oracle (or from enum selection).

Now from here on, i should only have to access the generic wrapper,
eg..something like:

//assuming this is all i need to point the wrapper in the right direction//
GenericDataWrapper x = new GenericDataWrapper();
x.activeConnection = ConnectType.Oracle

x.Connect("connectionstring goes here"...); - we stop here..

So, at the point where x references a procedure, i want the generic wrapper
to go to MyClass.Data.OracleClient.Connect(), if you get the drift of where
i'm coming from.

Does this mean that in the generic class i have to use a switch statement
for every function call, so i point it internally to the right class or is
there a cleaner way with less code here?

any help appreciated.
thanks,
Paul
 
Hi,

Milsnips said:
Hi there,

this is what i'm trying to achieve, i have separate identical classes for
SqlClient, OracleClient, Odbc and OleDb, what i want is to create a
Wrapper class that calls any of these 4 based on the user connection....
so what i had in mind was something like this:


Have you take a look at the Abstract Factory pattern?

http://en.wikipedia.org/wiki/Abstract_factory_pattern

I thnk it will help you
 
Hi Ignacio,

no i havent seen this. i'll have a look now and hope its what i'm after.
Paul
thanks,
 
In addition to the above, if you poke around System.Data, you'll notice
that System.Data.OleDB.OleDBConnection, odbc.odbcConnection,
SqlClient.SqlConnection all derive from the same base type
IdbConnection. Command, recordset, adapter, everything each derive from
a general interface. This is useful as the actual data is agnostic,
DataSet lives in System.Data, so any IdbConnection, etc can be used to
obtain a DataSet.
We don't use oracle here, so I can't confirm their library conforms,
but it would be a bit bloody minded of them not to.
 
Thanks also for your reply. I looked at the abstract factory pattern in the
first reply and its pretty heavy stuff for me, although i think i can half
understand it, but much to go.

This idbConnection seems like what i'm after, i'll see how far i can get
with this.

thanks,
Paul
 
Hi Paul,

you can use the DbProviderFactory and DbPrvoviderFactories classes.

Christof
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top