log.info("Configuring schema export for : " + persistenceUnit);
List<TableInfo> tableInfos = getSchemaInfo(persistenceUnit);
Map<String, EntityMetadata> entityMetadataMap = getEntityMetadataCol(appMetadata, persistenceUnit);
PersistenceUnitMetadata puMetadata = appMetadata.getPersistenceUnitMetadata(persistenceUnit);
// Iterate each entity metadata.
for (EntityMetadata entityMetadata : entityMetadataMap.values())
{
// get entity metadata(table info as well as columns)
// if table info exists, get it from map.
boolean found = false;
Type type = entityMetadata.getType();
Class idClassName = entityMetadata.getIdAttribute() != null ? entityMetadata.getIdAttribute()
.getJavaType() : null;
String idName = entityMetadata.getIdAttribute() != null ? ((AbstractAttribute) entityMetadata
.getIdAttribute()).getJPAColumnName() : null;
TableInfo tableInfo = new TableInfo(entityMetadata.getTableName(), type.name(), idClassName, idName);
// check for tableInfos not empty and contains the present
// tableInfo.
if (!tableInfos.isEmpty() && tableInfos.contains(tableInfo))
{
found = true;
int idx = tableInfos.indexOf(tableInfo);
tableInfo = tableInfos.get(idx);
addColumnToTableInfo(entityMetadata, type, tableInfo);
}
else
{
addColumnToTableInfo(entityMetadata, type, tableInfo);
}
List<Relation> relations = entityMetadata.getRelations();
parseRelations(persistenceUnit, tableInfos, entityMetadata, tableInfo, relations);
if (!found)
{
tableInfos.add(tableInfo);
}
// Add table for GeneratedValue if opted TableStrategy
addTableGenerator(appMetadata, persistenceUnit, tableInfos, entityMetadata);
// Validating entity against counter column family.
validator.validateEntity(entityMetadata.getEntityClazz(), kunderaMetadata);
}
puToSchemaMetadata.put(persistenceUnit, tableInfos);
}
// Need to iterate, as in case of non unary relations
for (String persistenceUnit : persistenceUnits)
{
PersistenceUnitMetadata puMetadata = appMetadata.getPersistenceUnitMetadata(persistenceUnit);
Map externalPuMap = externalPropertyMap;
// in case of polyglot.
if (persistenceUnits.length > 1 && externalPropertyMap != null)
{
externalPuMap = (Map) externalPropertyMap.get(persistenceUnit);
}
if (externalPuMap != null && externalPuMap.get(PersistenceProperties.KUNDERA_DDL_AUTO_PREPARE) != null
|| puMetadata.getProperty(PersistenceProperties.KUNDERA_DDL_AUTO_PREPARE) != null)
{
SchemaManager schemaManager = getSchemaManagerForPu(persistenceUnit);
if (schemaManager != null)
{