/** * Accessor for the indices for this table. This includes both the user-defined indices (via * MetaData), and the ones required by foreign keys. * * @param clr The ClassLoaderResolver * @return The indices */ protected Set getExpectedIndices(ClassLoaderResolver clr) { Set indices = new HashSet(); // Index for FK back to owner if (mmd.getIndexMetaData() != null) { Index index = TableUtils.getIndexForField(this, mmd.getIndexMetaData(), ownerMapping); if (index != null) { indices.add(index); } } else if (mmd.getJoinMetaData() != null && mmd.getJoinMetaData().getIndexMetaData() != null) { Index index = TableUtils.getIndexForField(this, mmd.getJoinMetaData().getIndexMetaData(), ownerMapping); if (index != null) { indices.add(index); } } else { // Fallback to an index for the foreign-key to the owner Index index = TableUtils.getIndexForField(this, null, ownerMapping); if (index != null) { indices.add(index); } } // Index for the key FK (if required) if (keyMapping instanceof EmbeddedKeyPCMapping) { // Add all indices required by fields of the embedded key EmbeddedKeyPCMapping embMapping = (EmbeddedKeyPCMapping) keyMapping; 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 { KeyMetaData keymd = mmd.getKeyMetaData(); if (keymd != null && keymd.getIndexMetaData() != null) { IndexMetaData idxmd = mmd.getKeyMetaData().getIndexMetaData(); Index index = TableUtils.getIndexForField(this, idxmd, keyMapping); if (index != null) { indices.add(index); } } else { // Fallback to an index for any foreign-key to the key if (keyMapping instanceof PersistableMapping) { Index index = TableUtils.getIndexForField(this, null, keyMapping); if (index != null) { indices.add(index); } } } } // Index for the value FK (if required) if (valueMapping instanceof EmbeddedValuePCMapping) { // Add all indices required by fields of the embedded value EmbeddedValuePCMapping embMapping = (EmbeddedValuePCMapping) valueMapping; 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 { ValueMetaData valmd = mmd.getValueMetaData(); if (valmd != null && valmd.getIndexMetaData() != null) { IndexMetaData idxmd = mmd.getValueMetaData().getIndexMetaData(); Index index = TableUtils.getIndexForField(this, idxmd, valueMapping); if (index != null) { indices.add(index); } } else { // Fallback to an index for any foreign-key to the value if (valueMapping instanceof PersistableMapping) { Index index = TableUtils.getIndexForField(this, null, valueMapping); if (index != null) { indices.add(index); } } } } return indices; }