467,912 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,912 developers. It's quick & easy.

making a generic data access class wrapper for underlying classes

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

Jan 10 '07 #1
  • viewed: 3092
Share:
6 Replies
Hi,

"Milsnips" <mi******@hotmail.comwrote in message
news:OC**************@TK2MSFTNGP02.phx.gbl...
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

--
Ignacio Machin
machin AT laceupsolutions com
Jan 10 '07 #2
Hi Ignacio,

no i havent seen this. i'll have a look now and hope its what i'm after.
Paul
thanks,

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:Ok*************@TK2MSFTNGP06.phx.gbl...
Hi,

"Milsnips" <mi******@hotmail.comwrote in message
news:OC**************@TK2MSFTNGP02.phx.gbl...
>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

--
Ignacio Machin
machin AT laceupsolutions com

Jan 10 '07 #3
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.

Milsnips wrote:
Hi Ignacio,

no i havent seen this. i'll have a look now and hope its what i'm after.
Paul
thanks,

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:Ok*************@TK2MSFTNGP06.phx.gbl...
Hi,

"Milsnips" <mi******@hotmail.comwrote in message
news:OC**************@TK2MSFTNGP02.phx.gbl...
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

--
Ignacio Machin
machin AT laceupsolutions com
Jan 10 '07 #4
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

"DeveloperX" <nn*****@operamail.comwrote in message
news:11*********************@o58g2000hsb.googlegro ups.com...
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.

Milsnips wrote:
>Hi Ignacio,

no i havent seen this. i'll have a look now and hope its what i'm after.
Paul
thanks,

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote
in
message news:Ok*************@TK2MSFTNGP06.phx.gbl...
Hi,

"Milsnips" <mi******@hotmail.comwrote in message
news:OC**************@TK2MSFTNGP02.phx.gbl...
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

--
Ignacio Machin
machin AT laceupsolutions com

Jan 10 '07 #5
EnterpriseLibrary (Data) has already done most of this.

Don't reinvent the wheel.
You can also read this post:

http://groups.google.com/group/micro...cbbe0ed0c4519a

or
http://groups.google.com/groups/sear...y+&qt_s=Search

find ...

MyDatabaseFactory


"Milsnips" <mi******@hotmail.comwrote in message
news:OC**************@TK2MSFTNGP02.phx.gbl...
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

Jan 10 '07 #6
Hi Paul,

you can use the DbProviderFactory and DbPrvoviderFactories classes.

Christof

"Milsnips" <mi******@hotmail.comschrieb im Newsbeitrag
news:OC**************@TK2MSFTNGP02.phx.gbl...
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

Jan 11 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by D Witherspoon | last post: by
6 posts views Thread by Robin | last post: by
23 posts views Thread by mark.moore | last post: by
351 posts views Thread by CBFalconer | last post: by
3 posts views Thread by markww | last post: by
10 posts views Thread by phancey | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.