{
JavaTypeMapping embFieldMapping = embMapping.getJavaTypeMapping(i);
IndexMetaData imd = embFieldMapping.getFieldMetaData().getIndexMetaData();
if (imd != null)
{
Index index = TableUtils.getIndexForField(this, imd, embFieldMapping);
if (index != null)
{
indices.add(index);
}
}
}
}
else
{
// Add any required index for this field
IndexMetaData imd = fmd.getIndexMetaData();
if (imd != null)
{
Index index = TableUtils.getIndexForField(this, imd, fieldMapping);
if (index != null)
{
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() != null ? idxmd.isUnique().booleanValue() : false,
idxmd.getValueForExtension("extended-setting"));
if (idxmd.getName() != null)
{
index.setName(idxmd.getName());
}
int countVersionFields = versionMapping.getNumberOfDatastoreFields();
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() != null ? idxmd.isUnique().booleanValue() : false,
idxmd.getValueForExtension("extended-setting"));
if (idxmd.getName() != null)
{
index.setName(idxmd.getName());
}
int countDiscrimFields = discriminatorMapping.getNumberOfDatastoreFields();
for (int i=0; i<countDiscrimFields; i++)
{
index.addDatastoreField(discriminatorMapping.getDataStoreMapping(i).getDatastoreField());
}
indices.add(index);
}
}
// Add on any order fields (for lists, arrays, collections) that need indexing
Set orderMappingsEntries = getExternalOrderMappings().entrySet();
Iterator orderMappingsEntriesIter = orderMappingsEntries.iterator();
while (orderMappingsEntriesIter.hasNext())
{
Map.Entry entry = (Map.Entry)orderMappingsEntriesIter.next();
AbstractMemberMetaData fmd = (AbstractMemberMetaData)entry.getKey();
JavaTypeMapping mapping = (JavaTypeMapping)entry.getValue();
OrderMetaData omd = fmd.getOrderMetaData();
if (omd != null && omd.getIndexMetaData() != null)
{
Index index = getIndexForIndexMetaDataAndMapping(omd.getIndexMetaData(), mapping);
if (index != null)
{
indices.add(index);
}
}
}
// Add on any user-required indices for the class(es) as a whole (subelement of <class>)
Iterator cmdIter = managedClassMetaData.iterator();
while (cmdIter.hasNext())
{
ClassMetaData thisCmd = (ClassMetaData)cmdIter.next();
IndexMetaData[] classIndices = thisCmd.getIndexMetaData();
if (classIndices != null)
{
for (int i=0;i<classIndices.length;i++)
{
Index index = getIndexForIndexMetaData(classIndices[i]);
if (index != null)
{
indices.add(index);
}
}