super( persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, factory );
if ( log.isTraceEnabled() ) {
log.tracef( "Creating OgmEntityPersister for %s", persistentClass.getClassName() );
}
ServiceRegistryImplementor serviceRegistry = factory.getServiceRegistry();
this.gridDialect = serviceRegistry.getService( GridDialect.class );
this.identityColumnAwareGridDialect = serviceRegistry.getService( IdentityColumnAwareGridDialect.class );
this.optimisticLockingAwareGridDialect = serviceRegistry.getService( OptimisticLockingAwareGridDialect.class );
this.optionsService = serviceRegistry.getService( OptionsService.class );
if ( factory.getIdentifierGenerator( getEntityName() ) instanceof OgmIdentityGenerator && identityColumnAwareGridDialect == null ) {
throw log.getIdentityGenerationStrategyNotSupportedException( getEntityName() );
}
tableName = persistentClass.getTable().getQualifiedName(
factory.getDialect(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName()
);
this.discriminator = discriminator;
//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];
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] );