Search in sources :

Example 6 with UniqueMetaData

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

the class JoinMetadataImpl method getUniqueMetadata.

/* (non-Javadoc)
     * @see javax.jdo.metadata.JoinMetadata#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 7 with UniqueMetaData

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

the class JDOAnnotationUtils method getUniqueMetaData.

/**
 * Convenience method to create a UniqueMetaData from the annotations data.
 * @param name Name of the constraint
 * @param table Name of the table (optional)
 * @param deferred Whether the constraint is deferred
 * @param fields Fields to apply the constraint across (optional)
 * @param columns Columns to apply the constraint across (optional)
 * @return The UniqueMetaData
 */
public static UniqueMetaData getUniqueMetaData(String name, String table, String deferred, String[] fields, Column[] columns) {
    UniqueMetaData unimd = new UniqueMetaData();
    unimd.setName(name);
    unimd.setTable(table);
    if (!StringUtils.isWhitespace(deferred)) {
        unimd.setDeferred(Boolean.valueOf(deferred));
    }
    if (fields != null && fields.length > 0) {
        for (int j = 0; j < fields.length; j++) {
            unimd.addMember(fields[j]);
        }
    }
    if (unimd.getNumberOfMembers() == 0 && columns != null && columns.length > 0) {
        for (int j = 0; j < columns.length; j++) {
            unimd.addColumn(columns[j].name());
        }
    }
    return unimd;
}
Also used : UniqueMetaData(org.datanucleus.metadata.UniqueMetaData)

Example 8 with UniqueMetaData

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

the class JDOMetaDataHelper method getXMLForMetaData.

/**
 * Method to convert an internal class/interface metadata into the associated JDO XML metadata.
 * @param cmd Metadata for the class/interface
 * @param prefix Prefix for the XML (e.g "    ")
 * @param indent Indent for each block of XML (e.g "    ")
 * @return The XML
 */
public String getXMLForMetaData(AbstractClassMetaData cmd, String prefix, String indent) {
    StringBuilder str = new StringBuilder();
    boolean intf = (cmd instanceof InterfaceMetaData);
    if (intf) {
        str.append(prefix).append("<interface name=\"" + cmd.getName() + "\"");
    } else {
        str.append(prefix).append("<class name=\"" + cmd.getName() + "\"");
    }
    if (cmd.getIdentityType() != null) {
        str.append("\n").append(prefix).append("       identity-type=\"" + cmd.getIdentityType() + "\"");
    }
    if (cmd.getObjectidClass() != null) {
        str.append("\n").append(prefix).append("       objectid-class=\"" + cmd.getObjectidClass() + "\"");
    }
    if (!cmd.isRequiresExtent()) {
        str.append("\n").append(prefix).append("       requires-extent=\"" + cmd.isRequiresExtent() + "\"");
    }
    if (cmd.isEmbeddedOnly()) {
        str.append("\n").append(prefix).append("       embedded-only=\"" + cmd.isEmbeddedOnly() + "\"");
    }
    if (cmd.getPersistenceModifier() != null) {
        str.append("\n").append(prefix).append("       persistence-modifier=\"" + cmd.getPersistenceModifier() + "\"");
    }
    if (cmd.getCatalog() != null) {
        str.append("\n").append(prefix).append("       catalog=\"" + cmd.getCatalog() + "\"");
    }
    if (cmd.getSchema() != null) {
        str.append("\n").append(prefix).append("       schema=\"" + cmd.getSchema() + "\"");
    }
    if (cmd.getTable() != null) {
        str.append("\n").append(prefix).append("       table=\"" + cmd.getTable() + "\"");
    }
    if (cmd.isDetachable()) {
        str.append("\n").append(prefix).append("       detachable=\"" + cmd.isDetachable() + "\"");
    }
    str.append(">\n");
    // Identity
    if (cmd.getIdentityMetaData() != null) {
        str.append(getXMLForMetaData(cmd.getIdentityMetaData(), prefix + indent, indent));
    }
    // PrimaryKey
    if (cmd.getPrimaryKeyMetaData() != null) {
        str.append(getXMLForMetaData(cmd.getPrimaryKeyMetaData(), prefix + indent, indent));
    }
    // Inheritance
    if (cmd.getInheritanceMetaData() != null) {
        str.append(getXMLForMetaData(cmd.getInheritanceMetaData(), prefix + indent, indent));
    }
    // Add Version
    if (cmd.getVersionMetaData() != null) {
        str.append(getXMLForMetaData(cmd.getVersionMetaData(), prefix + indent, indent));
    }
    // Add joins
    List<JoinMetaData> joins = cmd.getJoinMetaData();
    if (joins != null) {
        for (JoinMetaData joinmd : joins) {
            str.append(getXMLForMetaData(joinmd, prefix + indent, indent));
        }
    }
    // Add foreign-keys
    List<ForeignKeyMetaData> foreignKeys = cmd.getForeignKeyMetaData();
    if (foreignKeys != null) {
        for (ForeignKeyMetaData fkmd : foreignKeys) {
            str.append(getXMLForMetaData(fkmd, prefix + indent, indent));
        }
    }
    // Add indexes
    List<IndexMetaData> indexes = cmd.getIndexMetaData();
    if (indexes != null) {
        for (IndexMetaData idxmd : indexes) {
            str.append(getXMLForMetaData(idxmd, prefix + indent, indent));
        }
    }
    // Add unique constraints
    List<UniqueMetaData> uniqueConstraints = cmd.getUniqueMetaData();
    if (uniqueConstraints != null) {
        for (UniqueMetaData unimd : uniqueConstraints) {
            str.append(getXMLForMetaData(unimd, prefix + indent, indent));
        }
    }
    // Add members
    int numMembers = cmd.getNoOfMembers();
    for (int i = 0; i < numMembers; i++) {
        AbstractMemberMetaData mmd = cmd.getMetaDataForMemberAtRelativePosition(i);
        str.append(getXMLForMetaData(mmd, prefix + indent, indent));
    }
    // Add unmapped columns
    List<ColumnMetaData> unmappedColumns = cmd.getUnmappedColumns();
    if (unmappedColumns != null) {
        for (int i = 0; i < unmappedColumns.size(); i++) {
            ColumnMetaData col = unmappedColumns.get(i);
            str.append(getXMLForMetaData(col, prefix + indent, indent));
        }
    }
    // Add queries
    QueryMetaData[] queries = cmd.getQueries();
    if (queries != null) {
        for (int i = 0; i < queries.length; i++) {
            QueryMetaData q = queries[i];
            str.append(getXMLForMetaData(q, prefix + indent, indent));
        }
    }
    // Add fetch-groups
    Set<FetchGroupMetaData> fetchGroups = cmd.getFetchGroupMetaData();
    if (fetchGroups != null) {
        for (FetchGroupMetaData fgmd : fetchGroups) {
            str.append(getXMLForMetaData(fgmd, prefix + indent, indent));
        }
    }
    // Add extensions
    processExtensions(cmd.getExtensions(), str, prefix, indent);
    if (intf) {
        str.append(prefix + "</interface>\n");
    } else {
        str.append(prefix + "</class>\n");
    }
    return str.toString();
}
Also used : UniqueMetaData(org.datanucleus.metadata.UniqueMetaData) IndexMetaData(org.datanucleus.metadata.IndexMetaData) QueryMetaData(org.datanucleus.metadata.QueryMetaData) InterfaceMetaData(org.datanucleus.metadata.InterfaceMetaData) JoinMetaData(org.datanucleus.metadata.JoinMetaData) ForeignKeyMetaData(org.datanucleus.metadata.ForeignKeyMetaData) ColumnMetaData(org.datanucleus.metadata.ColumnMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) FetchGroupMetaData(org.datanucleus.metadata.FetchGroupMetaData)

Example 9 with UniqueMetaData

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

the class MemberMetadataImpl method 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 10 with UniqueMetaData

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

the class TypeMetadataImpl method 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