public static boolean isEmbeddedField(AbstractMemberMetaData mmd) { return mmd.getEmbeddedMetaData() != null || (mmd.getElementMetaData() != null && mmd.getElementMetaData().getEmbeddedMetaData() != null); }
/** * Returns the owner member meta data * @return the owner member meta data, may be null for an unidirectional relationship */ public AbstractMemberMetaData getOwnerMMD() { if (mmd.getMappedBy() != null) { // mapped-by is always non-owner return otherMmd; } if (mmd.getElementMetaData() != null && !hasColumn) { // element is always non-owner return null; } return mmd; }
/** * Returns the owner member meta data * @return the owner member meta data, may be null for an unidirectional relationship */ public AbstractMemberMetaData getOwnerMMD() { if (mmd.getMappedBy() != null) { // mapped-by is always non-owner return otherMmd; } if (mmd.getElementMetaData() != null && !hasColumn) { // element is always non-owner return null; } return mmd; }
/** * Returns the non-owner member meta data * @return the non-owner member meta data, may be null for an unidirectional relationship */ public AbstractMemberMetaData getNonOwnerMMD() { if (mmd.getMappedBy() != null) { // mapped-by is always non-owner return mmd; } if (mmd.getElementMetaData() != null && !hasColumn) { // element is always non-owner return mmd; } return otherMmd; }
/** * Returns the non-owner member meta data * @return the non-owner member meta data, may be null for an unidirectional relationship */ public AbstractMemberMetaData getNonOwnerMMD() { if (mmd.getMappedBy() != null) { // mapped-by is always non-owner return mmd; } if (mmd.getElementMetaData() != null && !hasColumn) { // element is always non-owner return mmd; } return otherMmd; }
/** * Gets the objects that are embedded from child entries under the current entry. * @param collectionType the collection type * @return the objects */ private Collection<Object> fetchFromChildren(Class collectionType) { // use embedded meta data from element return fetchFromChildren(collectionType, mmd, mmd.getElementMetaData().getEmbeddedMetaData()); }
public ElementMetadata getElementMetadata() { ElementMetaData internalElemmd = getInternal().getElementMetaData(); if (internalElemmd == null) { return null; } ElementMetadataImpl elemmd = new ElementMetadataImpl(internalElemmd); elemmd.parent = this; return elemmd; }
/** * Method to prepare a field mapping for use in the datastore. * This creates the column in the table. */ protected void prepareDatastoreMapping() { MappingManager mmgr = storeMgr.getMappingManager(); ColumnMetaData colmd = null; if (mmd.getElementMetaData() != null && mmd.getElementMetaData().getColumnMetaData() != null && mmd.getElementMetaData().getColumnMetaData().length > 0) { colmd = mmd.getElementMetaData().getColumnMetaData()[0]; } Column col = mmgr.createColumn(this, getType(), colmd); mmgr.createDatastoreMapping(this, mmd, 0, col); } }
public String getOwnerAttributeName() { if (mmd.getMappedBy() != null) { // mapped-by is always non-owner return LDAPUtils.getAttributeNameForField(otherMmd); } if (mmd.getElementMetaData() != null && !hasColumn) { // element is always non-owner return mmd.getElementMetaData().getColumnName(); } return LDAPUtils.getAttributeNameForField(mmd); }
public String getOwnerAttributeName() { if (mmd.getMappedBy() != null) { // mapped-by is always non-owner return LDAPUtils.getAttributeNameForField(otherMmd); } if (mmd.getElementMetaData() != null && !hasColumn) { // element is always non-owner return mmd.getElementMetaData().getColumnName(); } return LDAPUtils.getAttributeNameForField(mmd); }
/** * Convenience method to generate a ForeignKey from this join table to an element table * using the specified mapping. * @param elementTable The element table * @param autoMode Whether we are in auto mode (where we generate the keys regardless of what the metadata says) * @param m The mapping to the element table * @return The ForeignKey */ protected ForeignKey getForeignKeyToElement(DatastoreClass elementTable, boolean autoMode, JavaTypeMapping m) { ForeignKey fk = null; if (elementTable != null) { // Take <foreign-key> from either <field> or <element> ForeignKeyMetaData fkmd = mmd.getForeignKeyMetaData(); if (fkmd == null && mmd.getElementMetaData() != null) { fkmd = mmd.getElementMetaData().getForeignKeyMetaData(); } // TODO If in autoMode and there are multiple possible element tables then don't create a FK if (fkmd != null || autoMode) { fk = new ForeignKey(m, dba, elementTable, true); fk.setForMetaData(fkmd); } } return fk; }
public WrappedMemberMetaData(AbstractMemberMetaData fmd, Class type, ClassLoaderResolver clr) { super(fmd.getParent(), fmd); this.singleCollectionMetadata = fmd; this.type = type; // Use element definition in preference to field since it may be copied to the element in metadata processing this.columnMetaData = (fmd.getElementMetaData() != null) ? fmd.getElementMetaData().getColumnMetaData() : fmd.getColumnMetaData(); this.relationType = fmd.getRelationType(clr); this.relatedMemberMetaData = fmd.getRelatedMemberMetaData(clr); // Copy the Element embedded definition to the field embedded metaData because EmbeddedPCMapping reads it from there. (Maybe it should use EmbeddedElementPCMapping?) ElementMetaData fmdElementMetaData = fmd.getElementMetaData(); if (fmdElementMetaData != null && fmdElementMetaData.getEmbeddedMetaData() != null) { setEmbeddedMetaData(fmdElementMetaData.getEmbeddedMetaData()); } }
/** * Initialize this JavaTypeMapping with the given DatastoreAdapter for * the given FieldMetaData. * @param table The datastore container storing this mapping (if any) * @param clr the ClassLoaderResolver * @param fmd FieldMetaData for the field to be mapped (if any) */ public void initialize(AbstractMemberMetaData fmd, Table table, ClassLoaderResolver clr) { initialize(fmd, table, clr, fmd.getElementMetaData().getEmbeddedMetaData(), fmd.getCollection().getElementType(), ObjectProvider.EMBEDDED_COLLECTION_ELEMENT_PC); } }
/** * * Returns the name of a column as specified in a JPA annotation (can possibly be {@code null}). * * @param ammd the metadata object for the field we're retrieving a name for * @return {@code null} if the field name is not defined by a JPA annotation, otherwise return the field name */ public static String getFieldNameFromJPAAnnotation(AbstractMemberMetaData ammd) { String fieldName = null; // Try the first column if specified ColumnMetaData[] colmds = ammd.getColumnMetaData(); ElementMetaData elemmd; if (colmds != null && colmds.length > 0) { fieldName = colmds[0].getName(); // In some cases (for example Collections and Arrays) // the ColumnMetaData will be embedded in ElementMetaData } else if ((elemmd = ammd.getElementMetaData()) != null) { colmds = elemmd.getColumnMetaData(); if (colmds != null && colmds.length > 0) { fieldName = colmds[0].getName(); } } return fieldName; } }
/** * * Returns the name of a column as specified in a JPA annotation (can possibly be {@code null}). * * @param ammd the metadata object for the field we're retrieving a name for * @return {@code null} if the field name is not defined by a JPA annotation, otherwise return the field name */ public static String getFieldNameFromJPAAnnotation(AbstractMemberMetaData ammd) { String fieldName = null; // Try the first column if specified ColumnMetaData[] colmds = ammd.getColumnMetaData(); ElementMetaData elemmd; if (colmds != null && colmds.length > 0) { fieldName = colmds[0].getName(); // In some cases (for example Collections and Arrays) // the ColumnMetaData will be embedded in ElementMetaData } else if ((elemmd = ammd.getElementMetaData()) != null) { colmds = elemmd.getColumnMetaData(); if (colmds != null && colmds.length > 0) { fieldName = colmds[0].getName(); } } return fieldName; } }
/** * Accessor for the name of the java-type actually used when mapping the particular datastore field. This java-type must have an entry in the datastore mappings. * @param index requested datastore field index. * @return the name of java-type for the requested datastore field. */ public String getJavaTypeForDatastoreMapping(int index) { if (containerIsStoredInSingleColumn()) { if (mmd.hasCollection() || mmd.hasArray()) { ColumnMetaData[] colmds = (mmd.getElementMetaData() != null ? mmd.getElementMetaData().getColumnMetaData() : null); if (colmds != null && colmds.length == 1 && colmds[0].getJdbcType() != null && colmds[0].getJdbcType().equals(JdbcType.ARRAY)) { // Element column using JDBC ARRAY type return Collection.class.getName(); } // Check if they specified just @Column since storing in single column in owner table colmds = mmd.getColumnMetaData(); if (colmds != null && colmds.length == 1 && colmds[0].getJdbcType() != null && colmds[0].getJdbcType().equals(JdbcType.ARRAY)) { // Column using JDBC ARRAY type return Collection.class.getName(); } } // Serialised container so just return serialised return ClassNameConstants.JAVA_IO_SERIALIZABLE; } return super.getJavaTypeForDatastoreMapping(index); }
/** * Method to prepare a field mapping for use in the datastore. * This creates the column in the table. */ protected void prepareDatastoreMapping() { if (containerIsStoredInSingleColumn()) { // Serialised collections/maps/arrays should just create a (typically BLOB) column as normal in the owning table MappingManager mmgr = storeMgr.getMappingManager(); ColumnMetaData colmd = null; ColumnMetaData[] colmds = mmd.getColumnMetaData(); if (colmds != null && colmds.length > 0) { // Try the field column info colmd = colmds[0]; } else if (mmd.hasCollection() || mmd.hasArray()) { // Fallback to the element column info colmds = (mmd.getElementMetaData() != null) ? mmd.getElementMetaData().getColumnMetaData() : null; if (colmds != null && colmds.length > 0) { colmd = colmds[0]; } } Column col = mmgr.createColumn(this, getJavaTypeForDatastoreMapping(0), colmd); mmgr.createDatastoreMapping(this, mmd, 0, col); } }
private String determinePropertyName(AbstractMemberMetaData ammd) { if (ammd.hasExtension(DatastoreManager.PK_ID) || ammd.hasExtension(DatastoreManager.PK_NAME)) { // the datsatore doesn't support filtering or sorting by the individual // components of the key, so if the field corresponds to one of these // components it's a mistake by the user throw new org.datanucleus.exceptions.NucleusFatalUserException(query.getSingleStringQuery() + ": Field " + ammd.getFullFieldName() + " is a sub-component of the primary key. The " + "datastore does not support filtering or sorting by primary key components, only the " + "entire primary key."); } if (ammd.getColumn() != null) { return ammd.getColumn(); } else if (ammd.getColumnMetaData() != null && ammd.getColumnMetaData().length != 0) { return ammd.getColumnMetaData()[0].getName(); } else if (ammd.getElementMetaData() != null && ammd.getElementMetaData().getColumnMetaData() != null && ammd.getElementMetaData().getColumnMetaData().length != 0) { return ammd.getElementMetaData().getColumnMetaData()[0].getName(); } else { return getIdentifierFactory().newDatastoreFieldIdentifier(ammd.getName()).getIdentifierName(); } }
if (mmd.getElementMetaData() != null && mmd.getElementMetaData().getEmbeddedMetaData() != null)
public RelationByDnMetaData(AbstractMemberMetaData mmd, MetaDataManager mmgr) { this.mmd = mmd; AbstractClassMetaData otherClassMetaData = LDAPUtils.getEffectiveClassMetaData(mmd, mmgr); hasColumn = mmd.getColumnMetaData() != null && mmd.getColumnMetaData().length > 0; if (mmd.getMappedBy() != null) { otherMmd = otherClassMetaData.getMetaDataForMember(mmd.getMappedBy()); } else if (mmd.getElementMetaData() != null && !hasColumn) { // always null otherMmd = null; } // else ??? if (mmd.getMappedBy() != null) { emptyValue = LDAPUtils.getEmptyValue(otherMmd); } else { emptyValue = LDAPUtils.getEmptyValue(mmd); } }