// Add indexes for fields of this embedded PC object
EmbeddedPCMapping embMapping = (EmbeddedPCMapping)fieldMapping;
for (int i=0;i<embMapping.getNumberOfJavaTypeMappings();i++)
{
JavaTypeMapping embFieldMapping = embMapping.getJavaTypeMapping(i);
IndexMetaData imd = embFieldMapping.getMemberMetaData().getIndexMetaData();
if (imd != null)
{
Index index = TableUtils.getIndexForField(this, imd, embFieldMapping);
if (index != null)
{
indices.add(index);
}
}
}
}
else if (fieldMapping instanceof SerialisedMapping)
{
// Don't index these
}
else
{
// Add any required index for this field
IndexMetaData imd = fmd.getIndexMetaData();
if (imd != null)
{
// Index defined so add it
Index index = TableUtils.getIndexForField(this, imd, fieldMapping);
if (index != null)
{
indices.add(index);
}
}
else if (autoMode)
{
if (fmd.getIndexed() == null)
{
// Indexing not set, so add where we think it is appropriate
if (!fmd.isPrimaryKey()) // Ignore PKs since they will be indexed anyway
{
int relationType = fmd.getRelationType(clr);
if (relationType == Relation.ONE_TO_ONE_UNI)
{
// 1-1 with FK at this side so index the FK
if (fieldMapping instanceof ReferenceMapping)
{
ReferenceMapping refMapping = (ReferenceMapping)fieldMapping;
if (refMapping.getMappingStrategy() == ReferenceMapping.PER_IMPLEMENTATION_MAPPING)
{
// Cols per implementation : index each of implementations
if (refMapping.getJavaTypeMapping() != null)
{
int colNum = 0;
JavaTypeMapping[] implMappings = refMapping.getJavaTypeMapping();
for (int i=0;i<implMappings.length;i++)
{
int numColsInImpl = implMappings[i].getNumberOfDatastoreMappings();
Index index = new Index(this, false, null);
for (int j=0;j<numColsInImpl;j++)
{
index.setColumn(j,
(Column)fieldMapping.getDatastoreMapping(colNum++).getDatastoreField());
}
indices.add(index);
}
}
}
}
else
{
Index index = new Index(this, false, null);
for (int i=0;i<fieldMapping.getNumberOfDatastoreMappings();i++)
{
index.setColumn(i, (Column)fieldMapping.getDatastoreMapping(i).getDatastoreField());
}
indices.add(index);
}
}
else if (relationType == Relation.ONE_TO_ONE_BI && fmd.getMappedBy() == null)
{
// 1-1 with FK at this side so index the FK
Index index = new Index(this, false, null);
for (int i=0;i<fieldMapping.getNumberOfDatastoreMappings();i++)
{
index.setColumn(i, (Column)fieldMapping.getDatastoreMapping(i).getDatastoreField());
}
indices.add(index);
}
else if (relationType == Relation.MANY_TO_ONE_BI)
{
// N-1 with FK at this side so index the FK
AbstractMemberMetaData relMmd = fmd.getRelatedMemberMetaData(clr)[0];
if (relMmd.getJoinMetaData() == null && fmd.getJoinMetaData() == null)
{
Index index = new Index(this, false, null);
for (int i=0;i<fieldMapping.getNumberOfDatastoreMappings();i++)
{
index.setColumn(i, (Column)fieldMapping.getDatastoreMapping(i).getDatastoreField());
}
indices.add(index);
}
}
}
}
}
}
}
// Check if any version column needs indexing
if (versionMapping != null)
{
IndexMetaData idxmd = getVersionMetaData().getIndexMetaData();
if (idxmd != null)
{
Index index = new Index(this, idxmd.isUnique(),
idxmd.getValueForExtension("extended-setting"));
if (idxmd.getName() != null)
{
index.setName(idxmd.getName());
}
int countVersionFields = versionMapping.getNumberOfDatastoreMappings();
for (int i=0; i<countVersionFields; i++)
{
index.addDatastoreField(versionMapping.getDatastoreMapping(i).getDatastoreField());
}
indices.add(index);
}
}
// Check if any discriminator column needs indexing
if (discriminatorMapping != null)
{
DiscriminatorMetaData dismd = getDiscriminatorMetaData();
IndexMetaData idxmd = dismd.getIndexMetaData();
if (idxmd != null)
{
Index index = new Index(this, idxmd.isUnique(),
idxmd.getValueForExtension("extended-setting"));
if (idxmd.getName() != null)
{
index.setName(idxmd.getName());
}
int countDiscrimFields = discriminatorMapping.getNumberOfDatastoreMappings();
for (int i=0; i<countDiscrimFields; i++)
{
index.addDatastoreField(discriminatorMapping.getDatastoreMapping(i).getDatastoreField());