@Override public boolean useBackedSCOWrapperForMember(AbstractMemberMetaData mmd, ExecutionContext ec) { if ((mmd.hasCollection() || mmd.hasMap()) && mmd.hasExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME)) { // The only case where we don't use backed wrappers is for a Collection/Map that is using a converter for the whole field (so storing as a single column) return false; } return true; }
if (relType == RelationType.MANY_TO_MANY_BI && ownerFmd.hasCollection() && ownerFmd.getMappedBy() != null)
/** * Method to return the type of the XML element to use for the specified field/property. * Null implies no value defined * @param mmd Metadata for the field/property * @param clr ClassLoader resolver * @return The type */ public static Class getElementTypeForMember(AbstractMemberMetaData mmd, ClassLoaderResolver clr) { try { if (mmd.hasExtension("type")) { return clr.classForName(mmd.getValueForExtension("type")); } else if (mmd.hasCollection()) { // Collection but no "type" known so impose element type return clr.classForName(mmd.getCollection().getElementType()); } } catch (ClassNotResolvedException e) { throw new RuntimeException(e.getMessage()); } return null; }
if (ownerMemberMetaData.hasCollection())
if (relType == RelationType.MANY_TO_MANY_BI && ownerFmd.hasCollection() && ownerFmd.getMappedBy() != null)
/** * 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); }
@Override public Object fetch() { RelationType relType = mmd.getRelationType(clr); if (relType == RelationType.ONE_TO_ONE_UNI || relType == RelationType.ONE_TO_ONE_BI) { Set<String> objectClasses = LDAPUtils.getObjectClassesForClass(effectiveClassMetaData); if (objectClasses.isEmpty()) { // embedded into the current entry return fetchEmbedded(); } // embedded as child-entry return fetchFromChild(); } else if (relType == RelationType.ONE_TO_MANY_UNI || relType == RelationType.ONE_TO_MANY_BI) { if (mmd.hasCollection()) { Class instanceType = mmd.getType(); instanceType = org.datanucleus.store.types.SCOUtils.getContainerInstanceType(instanceType, mmd.getOrderMetaData() != null); Collection<Object> coll = fetchFromChildren(instanceType); return SCOUtils.wrapSCOField(op, fieldNumber, coll, true); } } // TODO Localise this throw new NucleusException("Cant obtain value for field " + mmd.getFullFieldName() + " since type=" + mmd.getTypeName() + " is not supported for this datastore"); }
public Type<E> getElementType() { if (mmd.hasCollection()) { Class elementCls = owner.model.getClassLoaderResolver().classForName(mmd.getCollection().getElementType()); return owner.model.getType(elementCls); } else if (mmd.hasArray()) { Class elementCls = owner.model.getClassLoaderResolver().classForName(mmd.getArray().getElementType()); return owner.model.getType(elementCls); } return null; } }
if (ammd.hasCollection() || ammd.hasMap() || ammd.hasArray())
if (mmd.hasCollection()) if (mmd.hasCollection())
else if (mmd != null && mmd.hasCollection() && SCOUtils.collectionHasSerialisedElements(mmd))
/** * 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); } }
if (mmd.hasCollection()) if (mmd.hasCollection())
else if (relationType == RelationType.MANY_TO_ONE_BI && relatedMmds[0].hasCollection())