Search in sources :

Example 16 with PropertyMetaData

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

the class ClassTable method getMemberMapping.

/**
 * Accessor for the field mapping for the specified field.
 * The field can be managed by a supertable of this table.
 * @param mmd MetaData for this field/property
 * @return the Mapping for the field/property
 */
public JavaTypeMapping getMemberMapping(AbstractMemberMetaData mmd) {
    if (mmd == null) {
        return null;
    }
    if (mmd instanceof PropertyMetaData && mmd.getAbstractClassMetaData() instanceof InterfaceMetaData) {
        // TODO Fix Persistent Interfaces lookup
        return getMemberMapping(mmd.getName());
    }
    if (mmd.isPrimaryKey()) {
        assertIsPKInitialized();
    } else {
        assertIsInitialized();
    }
    // Check if we manage this field
    JavaTypeMapping m = memberMappingsMap.get(mmd);
    if (m != null) {
        return m;
    }
    if (mmd.isPrimaryKey() && pkMappings != null) {
        // pkMappings aren't in memberMappingsMap when in subclasses
        for (int i = 0; i < pkMappings.length; i++) {
            if (pkMappings[i].getMemberMetaData().equals(mmd)) {
                return pkMappings[i];
            }
        }
    }
    Iterator<Map.Entry<AbstractMemberMetaData, JavaTypeMapping>> memberMapIter = memberMappingsMap.entrySet().iterator();
    while (memberMapIter.hasNext()) {
        // If we have overridden this member then it may have a different AbstractMemberMetaData passed in (i.e the override)
        Map.Entry<AbstractMemberMetaData, JavaTypeMapping> entry = memberMapIter.next();
        if (entry.getKey().getFullFieldName().equals(mmd.getFullFieldName())) {
            return entry.getValue();
        }
    }
    // Check supertable
    int ifc = cmd.getNoOfInheritedManagedMembers();
    if (mmd.getAbsoluteFieldNumber() < ifc) {
        if (supertable != null) {
            m = supertable.getMemberMapping(mmd);
            if (m != null) {
                return m;
            }
        }
    }
    // Check secondary tables
    if (secondaryTables != null) {
        Collection secTables = secondaryTables.values();
        Iterator iter = secTables.iterator();
        while (iter.hasNext()) {
            SecondaryTable secTable = (SecondaryTable) iter.next();
            m = secTable.getMemberMapping(mmd);
            if (m != null) {
                return m;
            }
        }
    }
    return null;
}
Also used : JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) Iterator(java.util.Iterator) Collection(java.util.Collection) PropertyMetaData(org.datanucleus.metadata.PropertyMetaData) InterfaceMetaData(org.datanucleus.metadata.InterfaceMetaData) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData)

Example 17 with PropertyMetaData

use of org.datanucleus.metadata.PropertyMetaData 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 18 with PropertyMetaData

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

the class TypeMetadataImpl method newPropertyMetadata.

/* (non-Javadoc)
     * @see javax.jdo.metadata.ComponentMetadata#newPropertyMetadata(java.lang.reflect.Method)
     */
public PropertyMetadata newPropertyMetadata(Method method) {
    String methodName = method.getName();
    String name = null;
    if (methodName.startsWith("set")) {
        name = methodName.substring(3);
    } else if (methodName.startsWith("get")) {
        name = methodName.substring(3);
    } else if (methodName.startsWith("is")) {
        name = methodName.substring(2);
    } else {
        throw new JDOUserException("Method " + methodName + " is not a Java-bean method");
    }
    String propertyName = name.substring(0, 1).toLowerCase() + name.substring(1);
    PropertyMetaData internalPmd = getInternal().newPropertyMetadata(propertyName);
    PropertyMetadataImpl pmd = new PropertyMetadataImpl(internalPmd);
    pmd.parent = this;
    return pmd;
}
Also used : PropertyMetaData(org.datanucleus.metadata.PropertyMetaData) JDOUserException(javax.jdo.JDOUserException)

Example 19 with PropertyMetaData

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

the class TypeMetadataImpl method newPropertyMetadata.

/* (non-Javadoc)
     * @see javax.jdo.metadata.ComponentMetadata#newPropertyMetadata(java.lang.String)
     */
public PropertyMetadata newPropertyMetadata(String name) {
    PropertyMetaData internalPmd = getInternal().newPropertyMetadata(name);
    PropertyMetadataImpl pmd = new PropertyMetadataImpl(internalPmd);
    pmd.parent = this;
    return pmd;
}
Also used : PropertyMetaData(org.datanucleus.metadata.PropertyMetaData)

Example 20 with PropertyMetaData

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

the class IndexMetadataImpl method newPropertyMetadata.

/* (non-Javadoc)
     * @see javax.jdo.metadata.IndexMetadata#newPropertyMetadata(java.lang.String)
     */
public PropertyMetadata newPropertyMetadata(String name) {
    PropertyMetaData internalPmd = new PropertyMetaData(getInternal(), name);
    PropertyMetadataImpl pmd = new PropertyMetadataImpl(internalPmd);
    pmd.parent = this;
    return pmd;
}
Also used : PropertyMetaData(org.datanucleus.metadata.PropertyMetaData)

Aggregations

PropertyMetaData (org.datanucleus.metadata.PropertyMetaData)26 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)18 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)9 Label (org.datanucleus.enhancer.asm.Label)8 ClassMetaData (org.datanucleus.metadata.ClassMetaData)6 FieldMetaData (org.datanucleus.metadata.FieldMetaData)5 AttributeConverter (javax.jdo.AttributeConverter)3 PersistenceNucleusContext (org.datanucleus.PersistenceNucleusContext)3 JDOTypeConverter (org.datanucleus.api.jdo.JDOTypeConverter)3 FieldPersistenceModifier (org.datanucleus.metadata.FieldPersistenceModifier)3 InvalidMetaDataException (org.datanucleus.metadata.InvalidMetaDataException)3 Iterator (java.util.Iterator)2 Column (javax.jdo.annotations.Column)2 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)2 ArrayMetaData (org.datanucleus.metadata.ArrayMetaData)2 CollectionMetaData (org.datanucleus.metadata.CollectionMetaData)2 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)2 InterfaceMetaData (org.datanucleus.metadata.InterfaceMetaData)2 MapMetaData (org.datanucleus.metadata.MapMetaData)2 TypeManager (org.datanucleus.store.types.TypeManager)2