StrataFrame Forum

How Change TableSchema Programatly ?

http://forum.strataframe.net/Topic20997.aspx

By Elio Reyes - 12/3/2008



HI



I'm using a 3rd party database, in the database design they put Schema as a company and in my SF application I have to change depends to the company I going to work to, but I do when I fill the BO and it still using the TableSchema property made by the BO Build.



Public Overrides ReadOnly Property TableSchema() As String

Get

Return "P_T_P"

End Get

End Property



Any suggestions how to change this are welcome.



Thanks SF
By Edhy Rijo - 12/3/2008

Hi Pedro,

If you are using a base BO you can overwrite the TableSchema property and use whatever schema you want in that method.  I guess you will have the company information somewhere which will be used as the schema. 

Also make sure that any custom FillBy method you create, uses the BO.TableNameAndSchema property.  I have a method I use in all my BOs to get all Records like this:

Public Sub FillAllRecords()

     Using cmd As New SqlCommand()

          cmd.CommandText = String.Format("Select * From {0}", Me.TableNameAndSchema)

          Me.FillDataTable(cmd)

     End Using

End Sub

By Elio Reyes - 12/4/2008

I have the information in a table, how can I OverWrite the all BO Methods with the information in my table, because a do something :



Public Sub FillAll(ByVal cTableSchema As String)



Me.FillDataTable("SELECT * FROM " & cTableSchema & ".OP_OPER_DET_MO WHERE ORDEN_PRODUCCION IN " & _

" (SELECT ORDEN_PRODUCCION FROM " & cTableSchema & ".ORDEN_PRODUCCION WHERE ESTADO='L' ) AND OPERACION = 'GALERA' ORDER BY ORDEN_PRODUCCION")

End Sub




I send to all my filldata the schema, but it does not work.



If you can show me how to averwrite



Thanks SF
By Elio Reyes - 12/4/2008

Sorry it works, the problem is when I save usisng the save method bo.save()
By Trent L. Taylor - 12/4/2008

Well, if you are going to take a base level approach, then you need to create a BaseBO that all of your BOs inherit from instead of directly inheriting from BusinessLayer.  Then you could implement core base logic to redirect the table schema.  Since I don't really know what you are trying to do, I can't give you a straight answer here.  You are talking about a 3rd party database.  So are you creating your own DbDataSourceItem or trying to make an existing one work?  If you are trying to talk to a 3rd party database then I would recommend creating your own DbDataSourceItem that has all of the this logic within it.  If the logic for this database is closest to SqlServer, the copy over the SqlDataSOurceItem class and start from there.  If it is closest to OLEDB the copy over the Vfp ro AccessDataSourceItem and do the same. 

I really don't have enough information to give you any direct answers, but maybe some of these ideas will get you going in the right direction depending upon your needs.

By Edhy Rijo - 12/4/2008

Pedro Hernández (12/04/2008)
Sorry it works, the problem is when I save usisng the save method bo.save()

Pedro,

Probably there are some methods in SF which will use the TableSchema property of the BO, and in your code you are not updating this property, then it will return the schema of the table which was selected at the time of the BO generation by the BOM.

Like I said before, in your base BO class, simply override that property to return the value of your custom schema, something like this:

Public Overridable ReadOnly Property TableSchema()

     Get

          Return GetCustomSchemaName()

     End Get

End Property

Private Function GetCustomSchemaName() As String

     '-- Add your logic here to return your Schema Name from your source.

     Return "Your Schema Name"

End Function

Or if you want to make is simpler, don't create the GetCustomSchemaName() function and add that logic in the "Get" of the TableSchema property.  If you don't have a base BO, then you will need to do the same for all the BO you create, so it is a best practice to have your own base BO class.

And in your Fill command try to use the propertys of the BO available to you like the TableSchema, so your method may look like this:

Public Sub FillAll()

     Me.FillDataTable("SELECT * FROM " & Me.TableSchema & ".OP_OPER_DET_MO WHERE ORDEN_PRODUCCION IN " & _

" (SELECT ORDEN_PRODUCCION FROM " & Me.TableSchema & ".ORDEN_PRODUCCION WHERE ESTADO='L' ) AND OPERACION = 'GALERA' ORDER BY ORDEN_PRODUCCION")

End Sub

Of course, I have not try the above, it is mean to give you an idea to explore.

By Elio Reyes - 12/4/2008

Hi



I'm sorry for my bad exexplanations



I fill the Bo's nice, because I send then a parameter with the Schema, my problem is with SF internals instructions like save(), BrowseDialog..... because I can't tell then wichwhichema use, And of course they use the one when I make with the Business Object Mapper.



I need to change this too.



Thanks SF
By Edhy Rijo - 12/4/2008

Pedro Hernández (12/04/2008)
Hi

I'm sorry for my bad exexplanations

my problem is with SF internals instructions like save(), BrowseDialog..... because I can't tell then wichwhichema use, And of course they use the one when I make with the Business Object Mapper.

Your explanations are OK, but it looks like you are not reading the replies properly Hehe, the answer is right there for you, by working with the TableSchema property.

By Elio Reyes - 12/5/2008

Excellent information, I know that I asking so much, I have VB concept problem, because I need to change the Schema in runtime, I was thinking in a global variable, but I don’t know how to this, is the way that I found to change the schema when the user change the company running the application.



Any suggestion is appreciate



Thanks a Lot for your time and your very important information



SF
By Greg McGuffey - 12/5/2008

Perdo,



I think they are suggesting that in your BaseBO (if you aren't using one, now would be the time), you override the TableSchema property. Within it, you would then code the logic to change the db schema based on company. You could go about getting the company within the TaleSchema property in a number of ways. You would also add a company property to the BaseBO, or you could have a shared class that provide the current company info...I'm sure there are other ways too. Does that make more sense?
By Chris Diesel - 4/30/2010

I know this is an old thread, but I have just come across the need to override the TableSchema property too, but I'm confused.  How can I override this property in a base level class when it's being overridden at a higher level in each business object's designer code?  Doesn't this just override my base class code then? Ermm  Thanks!
By Dustin Taylor - 4/30/2010

You're right, this does at present require the manual step of removing the table schema from the designer file whenever you build the BO mapper. Once it is removed, you can set the table schema as an overridable property on the BO itself (or the base BO) to handle it from there.
By Chris Diesel - 5/3/2010

Thanks for looking!  Is this something you guys would consider changing?  Maybe make the base property so it's read/write, doesn't have to be overridden and set the default value in the constructor?
By Dustin Taylor - 5/3/2010

I believe Trent already has it on the list of Enhancements for our next BO Mapper update Smile. I'll confirm that with him and let you know once I have a more concrete idea of the ifs and whens.