Search in sources :

Example 61 with ColumnMetaData

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

the class JDOMetaDataHelper method getXMLForMetaData.

public String getXMLForMetaData(AbstractMemberMetaData mmd, String prefix, String indent) {
    if (mmd.isStatic() || mmd.isFinal()) {
        // If this field is static or final, don't bother with MetaData since we will ignore it anyway.
        return "";
    }
    boolean field = (mmd instanceof FieldMetaData);
    // Field needs outputting so generate metadata
    StringBuilder str = new StringBuilder();
    if (field) {
        str.append(prefix).append("<field name=\"" + mmd.getName() + "\"");
    } else {
        str.append(prefix).append("<property name=\"" + mmd.getName() + "\"");
    }
    if (mmd.getPersistenceModifier() != null && !StringUtils.isWhitespace(mmd.getPersistenceModifier().toString())) {
        str.append("\n").append(prefix).append("       persistence-modifier=\"" + mmd.getPersistenceModifier() + "\"");
    }
    if (!StringUtils.isWhitespace(mmd.getTable())) {
        str.append("\n").append(prefix).append("       table=\"" + mmd.getTable() + "\"");
    }
    if (mmd.isPrimaryKey()) {
        str.append("\n").append(prefix).append("       primary-key=\"" + mmd.isPrimaryKey() + "\"");
    }
    str.append("\n").append(prefix).append("       null-value=\"" + mmd.getNullValue() + "\"");
    if (mmd.isDefaultFetchGroup()) {
        str.append("\n").append(prefix).append("       default-fetch-group=\"" + mmd.isDefaultFetchGroup() + "\"");
    }
    if (mmd.isEmbedded()) {
        str.append("\n").append(prefix).append("       embedded=\"" + mmd.isEmbedded() + "\"");
    }
    if (mmd.isSerialized()) {
        str.append("\n").append(prefix).append("       serialized=\"" + mmd.isSerialized() + "\"");
    }
    if (mmd.isDependent()) {
        str.append("\n").append(prefix).append("       dependent=\"" + mmd.isDependent() + "\"");
    }
    if (mmd.getMappedBy() != null) {
        str.append("\n").append(prefix).append("       mapped-by=\"" + mmd.getMappedBy() + "\"");
    }
    String[] fieldTypes = mmd.getFieldTypes();
    if (fieldTypes != null) {
        str.append("\n").append(prefix).append("       field-type=\"");
        for (int i = 0; i < fieldTypes.length; i++) {
            str.append(fieldTypes[i]);
        }
        str.append("\"");
    }
    if (!StringUtils.isWhitespace(mmd.getLoadFetchGroup())) {
        str.append("\n").append(prefix).append("       load-fetch-group=\"" + mmd.getLoadFetchGroup() + "\"");
    }
    if (mmd.getRecursionDepth() != AbstractMemberMetaData.DEFAULT_RECURSION_DEPTH && mmd.getRecursionDepth() != AbstractMemberMetaData.UNDEFINED_RECURSION_DEPTH) {
        str.append("\n").append(prefix).append("       recursion-depth=\"" + mmd.getRecursionDepth() + "\"");
    }
    if (mmd.getValueStrategy() != null) {
        str.append("\n").append(prefix).append("       value-strategy=\"" + mmd.getValueStrategy() + "\"");
    }
    if (mmd.getSequence() != null) {
        str.append("\n").append(prefix).append("       sequence=\"" + mmd.getSequence() + "\"");
    }
    if (!field) {
        PropertyMetaData propmd = (PropertyMetaData) mmd;
        if (propmd.getFieldName() != null) {
            str.append("\n").append(prefix).append("       field-name=\"" + propmd.getFieldName() + "\"");
        }
    }
    if (mmd.getIndexMetaData() == null && mmd.getIndexed() != null) {
        str.append("\n").append(prefix).append("       indexed=\"" + mmd.getIndexed() + "\"");
    }
    if (mmd.getUniqueMetaData() == null) {
        str.append("\n").append(prefix).append("       unique=\"" + mmd.isUnique() + "\"");
    }
    str.append(">\n");
    // Add field containers
    ContainerMetaData contmd = mmd.getContainer();
    if (contmd != null) {
        if (contmd instanceof CollectionMetaData) {
            CollectionMetaData c = (CollectionMetaData) contmd;
            str.append(getXMLForMetaData(c, prefix + indent, indent));
        } else if (contmd instanceof ArrayMetaData) {
            ArrayMetaData c = (ArrayMetaData) contmd;
            str.append(getXMLForMetaData(c, prefix + indent, indent));
        } else if (contmd instanceof MapMetaData) {
            MapMetaData c = (MapMetaData) contmd;
            str.append(getXMLForMetaData(c, prefix + indent, indent));
        }
    }
    // Add columns
    ColumnMetaData[] columnMetaData = mmd.getColumnMetaData();
    if (columnMetaData != null) {
        for (int i = 0; i < columnMetaData.length; i++) {
            str.append(getXMLForMetaData(columnMetaData[i], prefix + indent, indent));
        }
    }
    // Add join
    if (mmd.getJoinMetaData() != null) {
        str.append(getXMLForMetaData(mmd.getJoinMetaData(), prefix + indent, indent));
    }
    // Add element
    if (mmd.getElementMetaData() != null) {
        str.append(getXMLForMetaData(mmd.getElementMetaData(), prefix + indent, indent));
    }
    // Add key
    if (mmd.getKeyMetaData() != null) {
        str.append(getXMLForMetaData(mmd.getKeyMetaData(), prefix + indent, indent));
    }
    // Add value
    if (mmd.getValueMetaData() != null) {
        str.append(getXMLForMetaData(mmd.getValueMetaData(), prefix + indent, indent));
    }
    // Add order
    if (mmd.getOrderMetaData() != null) {
        str.append(getXMLForMetaData(mmd.getOrderMetaData(), prefix + indent, indent));
    }
    // Add embedded
    if (mmd.getEmbeddedMetaData() != null) {
        str.append(getXMLForMetaData(mmd.getEmbeddedMetaData(), prefix + indent, indent));
    }
    // Add index
    if (mmd.getIndexMetaData() != null) {
        str.append(getXMLForMetaData(mmd.getIndexMetaData(), prefix + indent, indent));
    }
    // Add unique
    if (mmd.getUniqueMetaData() != null) {
        str.append(getXMLForMetaData(mmd.getUniqueMetaData(), prefix + indent, indent));
    }
    // Add foreign-key
    if (mmd.getForeignKeyMetaData() != null) {
        str.append(getXMLForMetaData(mmd.getForeignKeyMetaData(), prefix + indent, indent));
    }
    // Add extensions
    processExtensions(mmd.getExtensions(), str, prefix, indent);
    if (field) {
        str.append(prefix).append("</field>\n");
    } else {
        str.append(prefix).append("</property>\n");
    }
    return str.toString();
}
Also used : PropertyMetaData(org.datanucleus.metadata.PropertyMetaData) CollectionMetaData(org.datanucleus.metadata.CollectionMetaData) MapMetaData(org.datanucleus.metadata.MapMetaData) FieldMetaData(org.datanucleus.metadata.FieldMetaData) ArrayMetaData(org.datanucleus.metadata.ArrayMetaData) ColumnMetaData(org.datanucleus.metadata.ColumnMetaData) ContainerMetaData(org.datanucleus.metadata.ContainerMetaData)

Example 62 with ColumnMetaData

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

the class JDOMetaDataHelper method getXMLForMetaData.

public String getXMLForMetaData(ElementMetaData elemmd, String prefix, String indent) {
    StringBuilder str = new StringBuilder();
    str.append(prefix).append("<element");
    if (elemmd.getMappedBy() != null) {
        str.append(" mapped-by=\"" + elemmd.getMappedBy() + "\"");
    }
    if (!StringUtils.isWhitespace(elemmd.getTable())) {
        str.append(" table=\"" + elemmd.getTable() + "\"");
    }
    if (!StringUtils.isWhitespace(elemmd.getColumnName())) {
        str.append(" column=\"" + elemmd.getColumnName() + "\"");
    }
    str.append(">\n");
    // Add columns
    ColumnMetaData[] columns = elemmd.getColumnMetaData();
    if (columns != null) {
        for (ColumnMetaData colmd : columns) {
            str.append(getXMLForMetaData(colmd, prefix + indent, indent));
        }
    }
    // Add index metadata
    if (elemmd.getIndexMetaData() != null) {
        str.append(getXMLForMetaData(elemmd.getIndexMetaData(), prefix + indent, indent));
    }
    // Add unique metadata
    if (elemmd.getUniqueMetaData() != null) {
        str.append(getXMLForMetaData(elemmd.getUniqueMetaData(), prefix + indent, indent));
    }
    // Add embedded metadata
    if (elemmd.getEmbeddedMetaData() != null) {
        str.append(getXMLForMetaData(elemmd.getEmbeddedMetaData(), prefix + indent, indent));
    }
    // Add foreign-key metadata
    if (elemmd.getForeignKeyMetaData() != null) {
        str.append(getXMLForMetaData(elemmd.getForeignKeyMetaData(), prefix + indent, indent));
    }
    // Add extensions
    processExtensions(elemmd.getExtensions(), str, prefix, indent);
    str.append(prefix).append("</element>\n");
    return str.toString();
}
Also used : ColumnMetaData(org.datanucleus.metadata.ColumnMetaData)

Example 63 with ColumnMetaData

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

the class JDOMetaDataHelper method getXMLForMetaData.

public String getXMLForMetaData(PrimaryKeyMetaData pkmd, String prefix, String indent) {
    StringBuilder str = new StringBuilder();
    str.append(prefix).append("<primary-key" + (pkmd.getName() != null ? (" name=\"" + pkmd.getName() + "\"") : "") + (pkmd.getColumnName() != null ? (" column=\"" + pkmd.getColumnName() + "\"") : "") + ">\n");
    // Add columns
    ColumnMetaData[] columns = pkmd.getColumnMetaData();
    if (columns != null) {
        for (ColumnMetaData colmd : columns) {
            str.append(getXMLForMetaData(colmd, prefix + indent, indent));
        }
    }
    // Add extensions
    processExtensions(pkmd.getExtensions(), str, prefix, indent);
    str.append(prefix).append("</primary-key>\n");
    return str.toString();
}
Also used : ColumnMetaData(org.datanucleus.metadata.ColumnMetaData)

Example 64 with ColumnMetaData

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

the class JDOMetaDataHelper method getXMLForMetaData.

public String getXMLForMetaData(ForeignKeyMetaData fkmd, String prefix, String indent) {
    if (!StringUtils.isWhitespace(fkmd.getFkDefinition())) {
        return "<foreign-key name=\"" + fkmd.getName() + "\" definition=\"" + fkmd.getFkDefinition() + "\" definition-applies=" + fkmd.getFkDefinitionApplies() + "/>";
    }
    // Field needs outputting so generate metadata
    StringBuilder str = new StringBuilder();
    str.append(prefix).append("<foreign-key deferred=\"" + fkmd.isDeferred() + "\"\n");
    str.append(prefix).append("       unique=\"" + fkmd.isUnique() + "\"");
    if (fkmd.getUpdateAction() != null) {
        str.append("\n").append(prefix).append("       update-action=\"" + fkmd.getUpdateAction() + "\"");
    }
    if (fkmd.getDeleteAction() != null) {
        str.append("\n").append(prefix).append("       delete-action=\"" + fkmd.getDeleteAction() + "\"");
    }
    if (fkmd.getTable() != null) {
        str.append("\n").append(prefix).append("       table=\"" + fkmd.getTable() + "\"");
    }
    if (fkmd.getName() != null) {
        str.append("\n").append(prefix).append("       name=\"" + fkmd.getName() + "\"");
    }
    str.append(">\n");
    String[] memberNames = fkmd.getMemberNames();
    if (memberNames != null) {
        for (String memberName : memberNames) {
            str.append(prefix).append(indent).append("<field name=\"" + memberName + "\"/>\n");
        }
    }
    ColumnMetaData[] columns = fkmd.getColumnMetaData();
    if (columns != null) {
        for (ColumnMetaData colmd : columns) {
            str.append(getXMLForMetaData(colmd, prefix + indent, indent));
        }
    }
    // Add extensions
    processExtensions(fkmd.getExtensions(), str, prefix, indent);
    str.append(prefix).append("</foreign-key>\n");
    return str.toString();
}
Also used : ColumnMetaData(org.datanucleus.metadata.ColumnMetaData)

Example 65 with ColumnMetaData

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

the class JDOMetaDataHelper method getXMLForMetaData.

public String getXMLForMetaData(JoinMetaData joinmd, String prefix, String indent) {
    StringBuilder str = new StringBuilder();
    str.append(prefix).append("<join");
    if (joinmd.getTable() != null) {
        str.append(" table=\"" + joinmd.getTable() + "\"");
    }
    if (joinmd.getColumnName() != null) {
        str.append(" column=\"" + joinmd.getColumnName() + "\"");
    }
    str.append(" outer=\"" + joinmd.isOuter() + "\"");
    str.append(">\n");
    // Primary-key
    if (joinmd.getPrimaryKeyMetaData() != null) {
        str.append(getXMLForMetaData(joinmd.getPrimaryKeyMetaData(), prefix + indent, indent));
    }
    // Add columns
    ColumnMetaData[] columns = joinmd.getColumnMetaData();
    if (columns != null) {
        for (ColumnMetaData colmd : columns) {
            str.append(getXMLForMetaData(colmd, prefix + indent, indent));
        }
    }
    // Foreign-key
    if (joinmd.getForeignKeyMetaData() != null) {
        str.append(getXMLForMetaData(joinmd.getForeignKeyMetaData(), prefix + indent, indent));
    }
    // Index
    if (joinmd.getIndexMetaData() != null) {
        str.append(getXMLForMetaData(joinmd.getIndexMetaData(), prefix + indent, indent));
    }
    // Unique
    if (joinmd.getUniqueMetaData() != null) {
        str.append(getXMLForMetaData(joinmd.getUniqueMetaData(), prefix + indent, indent));
    }
    // Add extensions
    processExtensions(joinmd.getExtensions(), str, prefix, indent);
    str.append(prefix).append("</join>\n");
    return str.toString();
}
Also used : ColumnMetaData(org.datanucleus.metadata.ColumnMetaData)

Aggregations

ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)85 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)28 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)16 ClassMetaData (org.datanucleus.metadata.ClassMetaData)14 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)13 ElementMetaData (org.datanucleus.metadata.ElementMetaData)13 DatastoreIdentifier (org.datanucleus.store.rdbms.identifier.DatastoreIdentifier)11 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)10 JoinMetaData (org.datanucleus.metadata.JoinMetaData)9 MetaDataManager (org.datanucleus.metadata.MetaDataManager)9 MappingManager (org.datanucleus.store.rdbms.mapping.MappingManager)8 Column (org.datanucleus.store.rdbms.table.Column)8 NucleusContext (org.datanucleus.NucleusContext)7 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)7 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)7 PrimaryKeyMetaData (org.datanucleus.metadata.PrimaryKeyMetaData)7 IdentifierFactory (org.datanucleus.store.rdbms.identifier.IdentifierFactory)7 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)7 DiscriminatorMetaData (org.datanucleus.metadata.DiscriminatorMetaData)6 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)6