final Mapping mapping) throws HibernateException {
super(persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, factory);
if ( log.isTraceEnabled() ) {
log.tracef( "Creating OgmEntityPersister for %s", persistentClass.getClassName() );
}
ServiceRegistryImplementor serviceRegistry = factory.getServiceRegistry();
this.gridDialect = serviceRegistry.getService( DatastoreServices.class ).getGridDialect();
tableName = persistentClass.getTable().getQualifiedName(
factory.getDialect(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName()
);
discriminatorValue = persistentClass.getSubclassId();
discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() );
// SUBCLASSES
//We do not need a discriminator as each entity type will be in its own key "space" roughly like a
//UnionSubclassEntityPersister / table-per-concrete-class implementation
subclassByDiscriminatorValue.put(
persistentClass.getSubclassId(),
persistentClass.getEntityName()
);
if ( persistentClass.isPolymorphic() ) {
@SuppressWarnings( "unchecked" )
Iterator<Subclass> iter = persistentClass.getSubclassIterator();
while ( iter.hasNext() ) {
Subclass sc = iter.next();
subclassByDiscriminatorValue.put( sc.getSubclassId(), sc.getEntityName() );
}
}
//SPACES
//TODO: i'm not sure, but perhaps we should exclude
// abstract denormalized tables?
int spacesSize = 1 + persistentClass.getSynchronizedTables().size();
spaces = new String[spacesSize];
spaces[0] = tableName;
@SuppressWarnings( "unchecked" )
Iterator<String> syncTablesIter = persistentClass.getSynchronizedTables().iterator();
for ( int i=1; i<spacesSize; i++ ) {
spaces[i] = syncTablesIter.next();
}
HashSet<String> subclassTables = new HashSet<String>();
Iterator<Table> tableIter = persistentClass.getSubclassTableClosureIterator();
while ( tableIter.hasNext() ) {
Table table = tableIter.next();
subclassTables.add( table.getQualifiedName(
factory.getDialect(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName()
) );
}
subclassSpaces = ArrayHelper.toStringArray( subclassTables );
if ( isMultiTable() ) {
int idColumnSpan = getIdentifierColumnSpan();
ArrayList<String> tableNames = new ArrayList<String>();
ArrayList<String[]> keyColumns = new ArrayList<String[]>();
if ( !isAbstract() ) {
tableNames.add( tableName );
keyColumns.add( getIdentifierColumnNames() );
}
@SuppressWarnings( "unchecked" )
Iterator<Table> iter = persistentClass.getSubclassTableClosureIterator();
while ( iter.hasNext() ) {
Table tab = iter.next();
if ( !tab.isAbstractUnionTable() ) {
String tableName = tab.getQualifiedName(
factory.getDialect(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName()
);
tableNames.add( tableName );
String[] key = new String[idColumnSpan];
@SuppressWarnings( "unchecked" )
Iterator<Column> citer = tab.getPrimaryKey().getColumnIterator();
for ( int k=0; k<idColumnSpan; k++ ) {
key[k] = citer.next().getQuotedName( factory.getDialect() );
}
keyColumns.add( key );
}
}
constraintOrderedTableNames = ArrayHelper.toStringArray( tableNames );
constraintOrderedKeyColumnNames = ArrayHelper.to2DStringArray( keyColumns );
}
else {
constraintOrderedTableNames = new String[] { tableName };
constraintOrderedKeyColumnNames = new String[][] { getIdentifierColumnNames() };
}
initPropertyPaths(mapping);
//Grid related metadata
TypeTranslator typeTranslator = serviceRegistry.getService(TypeTranslator.class);
final Type[] types = getPropertyTypes();
final int length = types.length;
gridPropertyTypes = new GridType[length];
for (int index = 0 ; index < length ; index++) {
gridPropertyTypes[index] = typeTranslator.getType( types[index] );