New Posts New Posts RSS Feed: Source table for an Entity Type
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Source table for an Entity Type

 Post Reply Post Reply
Author
TimClamp View Drop Down
Newbie
Newbie
Avatar

Joined: 08-Jul-2008
Location: Houston, TX
Posts: 4
Post Options Post Options   Quote TimClamp Quote  Post ReplyReply Direct Link To This Post Topic: Source table for an Entity Type
    Posted: 06-Oct-2008 at 8:28pm
I'm currently experiencing some sluggishness in the area of Entity to source table mapping. Our code is utilizing the GetTable(pEntityType) method on the PersistenceManager to determine the source table name for a given Entity type.
 
While inspecting this call through multiple performance trace utilities I have found that this method consumes a large amount of resources (processing time) the first time it is called. Subsequent calls appear to cache information and appear faster. Do others have a requirement to use this...and if so are you seeing similar issues?
 
Perhaps there is an alternative to using this method outside of rolling my own solution?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 07-Oct-2008 at 11:19am

The first time PM.GetTable() is called for an EntityType, DevForce will initialize some metadata, create a "prototype" table for the Entity, and set default values. Probing for an IIdGenerator and DataSourceMappingInterceptor can also be triggered if those haven't been previously probed.  All EntityRelations within the model will also be loaded if not already.  So, the first GetTable() call can be sluggish, but the metadata is cached once loaded, and probing and EntityRelation loading occur once only.  GetTable() is used extensively within DevForce, since it ensures that the necessary metadata is loaded in order to do queries and saves.

Two questions for you: 

  1. Do you nee to perform custom entity to source mapping?  
    If so, take a look at the DataSourceMappingInterceptor too.
  2. What do you need from the GetTable() call? 
    Depending on what your needs are, you might be able to use EntityTypeInfo.GetByType().  The EntityTypeInfo gives you access to the PrototypeEntityTable and to TableMappingInfo, but the GetByType() call might also be sluggish if it's the first time metadata for the EntityType is being requested.
Back to Top
TimClamp View Drop Down
Newbie
Newbie
Avatar

Joined: 08-Jul-2008
Location: Houston, TX
Posts: 4
Post Options Post Options   Quote TimClamp Quote  Post ReplyReply Direct Link To This Post Posted: 07-Oct-2008 at 8:29pm
Hi Kim,
 
Thanks for the reply. What I really need is the source database table name for the entity type. Here is what I have tried:
 
#1) return ((RdbTableMappingInfo)EntityTypeInfo.GetByType(pEntityType).PrototypeEntityTable.TableMappingInfo).SourceTableName;

#2) return ((RdbTableMappingInfo)CobraSessionManager.Instance.CobraPersistenceManager.GetTable(pEntityType).TableMappingInfo).SourceTableName

#2 actually seems to perform just a slight bit better, but it could be because of the nature of profiling.

Our application seems to compound the issue because we are building view descriptors when it is launched. Building the view descriptors requires that we set up field lengths, which will go all the way back to our data dictionary for each entity. I have logged this happening for 64 entities, so if you could imagine 1 call to GetTable being just a bit sluggish, this will only make the issue look worse.
 
With that said, I have a couple of options to resolve the issue. One solution is to build the view descriptors as they are needed, which reduce the number of times GetTable is called significantly. Another solution that would require more maintenance on my end is to roll my own entity/table mapping. This is prone to error should the database schema change, so I believe I will go with option #1.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 08-Oct-2008 at 10:30am

So what you really need is a lightweight way of getting just the source table name...  One other option would be to take advantage of the fact that the generated DataTable classes, which contain the mapping info, are partial.  The CreateTableMappingInfo() method is protected, but you can write your own public accessor.   I haven't tested this and have no idea how it will perform, but it provides access to the mapping info without the overhead of other initialization activities:

public partial class CustomerDataTable {
   public static TableMappingInfo GetMapping() {
      CustomerDataTable t = new CustomerDataTable();
      return t.TableMappingInfo();
   }
}
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down