Search in sources :

Example 11 with UniqueMetaData

use of org.datanucleus.metadata.UniqueMetaData in project datanucleus-api-jdo by datanucleus.

the class ValueMetadataImpl method newUniqueMetadata.

/* (non-Javadoc)
     * @see javax.jdo.metadata.ValueMetadata#newUniqueMetadata()
     */
public UniqueMetadata newUniqueMetadata() {
    UniqueMetaData internalUnimd = getInternal().newUniqueMetaData();
    UniqueMetadataImpl unimd = new UniqueMetadataImpl(internalUnimd);
    unimd.parent = this;
    return unimd;
}
Also used : UniqueMetaData(org.datanucleus.metadata.UniqueMetaData)

Example 12 with UniqueMetaData

use of org.datanucleus.metadata.UniqueMetaData in project datanucleus-rdbms by datanucleus.

the class ElementContainerTable method getExpectedCandidateKeys.

/**
 * Accessor for the candidate keys for this table.
 * @return The indices
 */
protected List getExpectedCandidateKeys() {
    // The indices required by foreign keys (BaseTable)
    List candidateKeys = super.getExpectedCandidateKeys();
    if (elementMapping instanceof EmbeddedElementPCMapping) {
        // Add all candidate keys required by fields of the embedded element
        EmbeddedElementPCMapping embMapping = (EmbeddedElementPCMapping) elementMapping;
        for (int i = 0; i < embMapping.getNumberOfJavaTypeMappings(); i++) {
            JavaTypeMapping embFieldMapping = embMapping.getJavaTypeMapping(i);
            UniqueMetaData umd = embFieldMapping.getMemberMetaData().getUniqueMetaData();
            if (umd != null) {
                CandidateKey ck = TableUtils.getCandidateKeyForField(this, umd, embFieldMapping);
                if (ck != null) {
                    candidateKeys.add(ck);
                }
            }
        }
    }
    if (mmd.getJoinMetaData() != null && mmd.getJoinMetaData().getUniqueMetaData() != null) {
        // User has defined a unique key on the join table
        UniqueMetaData unimd = mmd.getJoinMetaData().getUniqueMetaData();
        if (unimd.getNumberOfColumns() > 0) {
            String[] columnNames = unimd.getColumnNames();
            CandidateKey uniKey = new CandidateKey(this, null);
            String unimdName = unimd.getName();
            if (!StringUtils.isWhitespace(unimdName)) {
                uniKey.setName(unimd.getName());
            }
            IdentifierFactory idFactory = storeMgr.getIdentifierFactory();
            for (String columnName : columnNames) {
                Column col = getColumn(idFactory.newColumnIdentifier(columnName));
                if (col != null) {
                    uniKey.addColumn(col);
                } else {
                    throw new NucleusUserException("Unique key on join-table " + this + " has column " + columnName + " that is not found");
                }
            }
            candidateKeys.add(uniKey);
        }
    }
    return candidateKeys;
}
Also used : JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) ArrayList(java.util.ArrayList) List(java.util.List) UniqueMetaData(org.datanucleus.metadata.UniqueMetaData) IdentifierFactory(org.datanucleus.store.rdbms.identifier.IdentifierFactory) EmbeddedElementPCMapping(org.datanucleus.store.rdbms.mapping.java.EmbeddedElementPCMapping) CandidateKey(org.datanucleus.store.rdbms.key.CandidateKey)

Example 13 with UniqueMetaData

use of org.datanucleus.metadata.UniqueMetaData in project datanucleus-rdbms by datanucleus.

the class MapTable method getExpectedCandidateKeys.

/**
 * Accessor for the candidate keys for this table.
 * @return The indices
 */
protected List getExpectedCandidateKeys() {
    // The indices required by foreign keys (BaseTable)
    List candidateKeys = super.getExpectedCandidateKeys();
    if (keyMapping instanceof EmbeddedKeyPCMapping) {
        // Add all candidate keys required by fields of the embedded key
        EmbeddedKeyPCMapping embMapping = (EmbeddedKeyPCMapping) keyMapping;
        for (int i = 0; i < embMapping.getNumberOfJavaTypeMappings(); i++) {
            JavaTypeMapping embFieldMapping = embMapping.getJavaTypeMapping(i);
            UniqueMetaData umd = embFieldMapping.getMemberMetaData().getUniqueMetaData();
            if (umd != null) {
                CandidateKey ck = TableUtils.getCandidateKeyForField(this, umd, embFieldMapping);
                if (ck != null) {
                    candidateKeys.add(ck);
                }
            }
        }
    } else if (mmd.getKeyMetaData() != null) {
        UniqueMetaData unimd = mmd.getKeyMetaData().getUniqueMetaData();
        if (unimd != null) {
            CandidateKey ck = TableUtils.getCandidateKeyForField(this, unimd, keyMapping);
            if (ck != null) {
                candidateKeys.add(ck);
            }
        }
    }
    if (valueMapping instanceof EmbeddedValuePCMapping) {
        // Add all candidate keys required by fields of the embedded value
        EmbeddedValuePCMapping embMapping = (EmbeddedValuePCMapping) valueMapping;
        for (int i = 0; i < embMapping.getNumberOfJavaTypeMappings(); i++) {
            JavaTypeMapping embFieldMapping = embMapping.getJavaTypeMapping(i);
            UniqueMetaData umd = embFieldMapping.getMemberMetaData().getUniqueMetaData();
            if (umd != null) {
                CandidateKey ck = TableUtils.getCandidateKeyForField(this, umd, embFieldMapping);
                if (ck != null) {
                    candidateKeys.add(ck);
                }
            }
        }
    } else if (mmd.getValueMetaData() != null) {
        UniqueMetaData unimd = mmd.getValueMetaData().getUniqueMetaData();
        if (unimd != null) {
            CandidateKey ck = TableUtils.getCandidateKeyForField(this, unimd, valueMapping);
            if (ck != null) {
                candidateKeys.add(ck);
            }
        }
    }
    return candidateKeys;
}
Also used : JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) ArrayList(java.util.ArrayList) List(java.util.List) UniqueMetaData(org.datanucleus.metadata.UniqueMetaData) EmbeddedValuePCMapping(org.datanucleus.store.rdbms.mapping.java.EmbeddedValuePCMapping) CandidateKey(org.datanucleus.store.rdbms.key.CandidateKey) EmbeddedKeyPCMapping(org.datanucleus.store.rdbms.mapping.java.EmbeddedKeyPCMapping)

Example 14 with UniqueMetaData

use of org.datanucleus.metadata.UniqueMetaData in project datanucleus-api-jdo by datanucleus.

the class KeyMetadataImpl method getUniqueMetadata.

/* (non-Javadoc)
     * @see javax.jdo.metadata.KeyMetadata#getUniqueMetadata()
     */
public UniqueMetadata getUniqueMetadata() {
    UniqueMetaData internalUnimd = getInternal().getUniqueMetaData();
    if (internalUnimd == null) {
        return null;
    }
    UniqueMetadataImpl unimd = new UniqueMetadataImpl(internalUnimd);
    unimd.parent = this;
    return unimd;
}
Also used : UniqueMetaData(org.datanucleus.metadata.UniqueMetaData)

Example 15 with UniqueMetaData

use of org.datanucleus.metadata.UniqueMetaData in project datanucleus-api-jdo by datanucleus.

the class KeyMetadataImpl method newUniqueMetadata.

/* (non-Javadoc)
     * @see javax.jdo.metadata.KeyMetadata#newUniqueMetadata()
     */
public UniqueMetadata newUniqueMetadata() {
    UniqueMetaData internalUnimd = getInternal().newUniqueMetaData();
    UniqueMetadataImpl unimd = new UniqueMetadataImpl(internalUnimd);
    unimd.parent = this;
    return unimd;
}
Also used : UniqueMetaData(org.datanucleus.metadata.UniqueMetaData)

Aggregations

UniqueMetaData (org.datanucleus.metadata.UniqueMetaData)25 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)4 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)4 ForeignKeyMetaData (org.datanucleus.metadata.ForeignKeyMetaData)4 IndexMetaData (org.datanucleus.metadata.IndexMetaData)4 JoinMetaData (org.datanucleus.metadata.JoinMetaData)4 CandidateKey (org.datanucleus.store.rdbms.key.CandidateKey)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CacheUniqueKey (org.datanucleus.cache.CacheUniqueKey)3 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)3 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)3 DiscriminatorMetaData (org.datanucleus.metadata.DiscriminatorMetaData)3 FetchGroupMetaData (org.datanucleus.metadata.FetchGroupMetaData)3 InvalidMetaDataException (org.datanucleus.metadata.InvalidMetaDataException)3 AttributeConverter (javax.jdo.AttributeConverter)2 Column (javax.jdo.annotations.Column)2 Extension (javax.jdo.annotations.Extension)2 ForeignKeyAction (javax.jdo.annotations.ForeignKeyAction)2 Persistent (javax.jdo.annotations.Persistent)2