Print Page | Close Window

Need to be able to set table owner name at runtime running against Oracle server

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=181
Printed Date: 23-May-2025 at 10:17am


Topic: Need to be able to set table owner name at runtime running against Oracle server
Posted By: Customer
Subject: Need to be able to set table owner name at runtime running against Oracle server
Date Posted: 12-Jul-2007 at 2:22pm

We need an easy way to change which database owner an object points to at run time, ideally for all of the objects in the ORM tool.  Basically, we need the ability for the database to be dynamic, but because the "owner" is more of a user in oracle, its limiting us to one user.

EG, if the owner for all the objects is 'TEST', it currently says 'select * from test.table'. We need the 'test' part to be dynamic.

I remember asking about this before at some point and it was mentioned that the new version of ideablade supports this, but I'm not sure how to go about implementing a change.

Any suggestions are appreciated.




Replies:
Posted By: IdeaBlade
Date Posted: 12-Jul-2007 at 2:23pm
In general what you need to resolve this problem is to implement a class in your business objects assembly that derives from the DataSourceMappingInterceptor class.   Some documentation of this class is found in the Help Reference under the IdeaBlade.Persistence namespace, which this class is part of.  DataSourceMappingInterceptors are also mentioned in the IdeaBlade Developer's Guide.
 
Here is an example of some code that changes the table owner name:
 

public class OracleMappingInterceptor : DataSourceMappingInterceptor {

 

    public override void UpdateSourceMapping(IDataSourceKey pKey, EntityTable pEntityTable) {

      RdbKey aRdbKey = pKey as RdbKey;

      if (aRdbKey == null || aRdbKey.DatabaseDriver.DatabaseProduct != DatabaseProduct.Oracle) {

        return;

      }

 

      RdbTableMappingInfo info = pEntityTable.TableMappingInfo as RdbTableMappingInfo;

      info.SchemaInitializationMode = SchemaInitializationMode.FromDataSource;

      info.SourceOwnerName = "SA";

      info.SourceTableName = info.SourceTableName.ToUpper();

      info.SourceColumnNames = info.SourceColumnNames.ToUpper();

      foreach (DataColumnMapping columnMapping in info.TableMapping.ColumnMappings) {

        columnMapping.SourceColumn = columnMapping.SourceColumn.ToUpper();

      }

      if (info.ColumnInsertMap.ContainsKey("RowVersion")) {

        info.ColumnInsertMap["RowVersion"] = info.ColumnInsertMap["RowVersion"].ToUpper();

      }

      if (info.ColumnUpdateMap.ContainsKey("RowVersion")) {

        info.ColumnUpdateMap["RowVersion"] = info.ColumnUpdateMap["RowVersion"].ToUpper();

      }

    }

 



Print Page | Close Window