/** * Accessor for the element type stored in this Collection/Set/List. * @return Name of element type. */ public String getElementType() { return mmd.getCollection().getElementType(); }
/** * @param metaData The meta data we'll consult. * * @return {@code true} if the pojo property is a collection of bytes. */ private boolean pojoPropertyIsByteCollection(AbstractMemberMetaData metaData) { String containerClassStr = metaData.getCollection().getElementType(); return containerClassStr.equals(Byte.class.getName()) || containerClassStr.equals(Byte.TYPE.getName()); }
public String getElementType() { return getInternal().getElementType(); }
public <E> ListAttribute<? super X, E> getList(String attr, Class<E> elementType) { AttributeImpl<X, ?> theAttr = (AttributeImpl<X, ?>) attributes.get(attr); if (theAttr == null) { throw new IllegalArgumentException("Attribute " + attr + " was not found in class"); } AbstractMemberMetaData mmd = theAttr.getMetadata(); if (!List.class.isAssignableFrom(mmd.getType())) { throw new IllegalArgumentException("Attribute " + attr + " isnt a List"); } Class elementCls = model.getClassLoaderResolver().classForName(mmd.getCollection().getElementType()); if (!elementType.isAssignableFrom(elementCls)) { throw new IllegalArgumentException("Attribute " + attr + " doesn't have a List with element of type " + elementType.getName()); } return (ListAttribute<? super X, E>)theAttr; }
public <E> SetAttribute<? super X, E> getSet(String attr, Class<E> elementType) { AttributeImpl<X, ?> theAttr = (AttributeImpl<X, ?>) attributes.get(attr); if (theAttr == null) { throw new IllegalArgumentException("Attribute " + attr + " was not found in class"); } AbstractMemberMetaData mmd = theAttr.getMetadata(); if (!Set.class.isAssignableFrom(mmd.getType())) { throw new IllegalArgumentException("Attribute " + attr + " isnt a Set"); } Class elementCls = model.getClassLoaderResolver().classForName(mmd.getCollection().getElementType()); if (!elementType.isAssignableFrom(elementCls)) { throw new IllegalArgumentException("Attribute " + attr + " doesn't have a Set with element of type " + elementType.getName()); } return (SetAttribute<? super X, E>)theAttr; }
public String getXMLForMetaData(CollectionMetaData collmd, String prefix, String indent) { StringBuilder str = new StringBuilder(); str.append(prefix).append("<collection element-type=\"").append(collmd.getElementType()).append("\""); if (collmd.isEmbeddedElement()) { str.append(" embedded-element=\"").append(collmd.isEmbeddedElement()).append("\""); } if (collmd.isDependentElement()) { str.append(" dependent-element=\"").append(collmd.isDependentElement()).append("\""); } if (collmd.isSerializedElement()) { str.append(" serialized-element=\"").append(collmd.isSerializedElement()).append("\""); } str.append(">\n"); // Add extensions processExtensions(collmd.getExtensions(), str, prefix, indent); str.append(prefix).append("</collection>\n"); return str.toString(); }
public <E> CollectionAttribute<? super X, E> getCollection(String attr, Class<E> elementType) { AttributeImpl<X, ?> theAttr = (AttributeImpl<X, ?>) attributes.get(attr); if (theAttr == null) { throw new IllegalArgumentException("Attribute " + attr + " was not found in class"); } AbstractMemberMetaData mmd = theAttr.getMetadata(); if (!Collection.class.isAssignableFrom(mmd.getType())) { throw new IllegalArgumentException("Attribute " + attr + " isnt a collection"); } Class elementCls = model.getClassLoaderResolver().classForName(mmd.getCollection().getElementType()); if (!elementType.isAssignableFrom(elementCls)) { throw new IllegalArgumentException("Attribute " + attr + " doesn't have a collection with element of type " + elementType.getName()); } return (CollectionAttribute<? super X, E>)theAttr; }
public Class<E> getBindableJavaType() { // What about for a Map ? return owner.model.getClassLoaderResolver().classForName(mmd.getCollection().getElementType()); }
public <E> ListAttribute<X, E> getDeclaredList(String attr, Class<E> elementType) { AttributeImpl<X, ?> theAttr = (AttributeImpl<X, ?>) attributes.get(attr); if (theAttr == null) { throw new IllegalArgumentException("Attribute " + attr + " was not found in class"); } AbstractMemberMetaData mmd = theAttr.getMetadata(); if (!List.class.isAssignableFrom(mmd.getType())) { throw new IllegalArgumentException("Attribute " + attr + " isnt a List"); } Class elementCls = model.getClassLoaderResolver().classForName(mmd.getCollection().getElementType()); if (!elementType.isAssignableFrom(elementCls)) { throw new IllegalArgumentException("Attribute " + attr + " doesn't have a List with element of type " + elementType.getName()); } Class thisCls = model.getClassLoaderResolver().classForName(cmd.getFullClassName()); if (mmd.getMemberRepresented().getDeclaringClass() != thisCls) { throw new IllegalArgumentException("Attribute " + attr + " isn't defined in " + cmd.getFullClassName()); } return (ListAttribute<X, E>)theAttr; }
public <E> CollectionAttribute<X, E> getDeclaredCollection(String attr, Class<E> elementType) { AttributeImpl<X, ?> theAttr = (AttributeImpl<X, ?>) attributes.get(attr); if (theAttr == null) { throw new IllegalArgumentException("Attribute " + attr + " was not found in class"); } AbstractMemberMetaData mmd = theAttr.getMetadata(); if (!Collection.class.isAssignableFrom(mmd.getType())) { throw new IllegalArgumentException("Attribute " + attr + " isnt a collection"); } Class elementCls = model.getClassLoaderResolver().classForName(mmd.getCollection().getElementType()); if (!elementType.isAssignableFrom(elementCls)) { throw new IllegalArgumentException("Attribute " + attr + " doesn't have a collection with element of type " + elementType.getName()); } Class thisCls = model.getClassLoaderResolver().classForName(cmd.getFullClassName()); if (mmd.getMemberRepresented().getDeclaringClass() != thisCls) { throw new IllegalArgumentException("Attribute " + attr + " isn't defined in " + cmd.getFullClassName()); } return (CollectionAttribute<X, E>) theAttr; }
/** * 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); } }
private Object convertPojoCollectionToDatastoreValue( ClassLoaderResolver clr, AbstractMemberMetaData ammd, Collection<?> value) { Object result = value; Class<?> elementType = clr.classForName(ammd.getCollection().getElementType()); if (Enum.class.isAssignableFrom(elementType)) { @SuppressWarnings("unchecked") Iterable<Enum> enums = (Iterable<Enum>) value; result = convertEnumsToStringList(enums); } else if (pojoPropertyIsByteCollection(ammd)) { result = convertByteCollectionToShortBlob((Collection<Byte>) value); } else { if (pojoToDatastoreTypeFunction.get(elementType) != null) { // this will transform non-lists into lists while also transforming // the elements of the collection result = Utils.transform(value, pojoToDatastoreTypeFunction.get(elementType)); } else if (!(value instanceof List)){ // elements don't need to be transformed but the container might result = Utils.transform(value, IDENTITY); } } return result; }
@Override public ElementMetadata setConverter(AttributeConverter<?, ?> conv) { String elemType = ((AbstractMemberMetaData)getInternal().getParent()).getCollection().getElementType(); Class elemCls = getInternal().getMetaDataManager().getNucleusContext().getClassLoaderResolver(null).classForName(elemType); Class attrType = JDOTypeConverterUtils.getAttributeTypeForAttributeConverter(conv.getClass(), elemCls); Class dbType = JDOTypeConverterUtils.getDatastoreTypeForAttributeConverter(conv.getClass(), attrType, null); // Register the TypeConverter under the name of the AttributeConverter class JDOTypeConverter typeConv = new JDOTypeConverter(conv); TypeManager typeMgr = getInternal().getMetaDataManager().getNucleusContext().getTypeManager(); typeMgr.registerConverter(conv.getClass().getName(), typeConv, attrType, dbType, false, null); getInternal().addExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME, conv.getClass().getName()); return this; }
@Override public void initialize(AbstractMemberMetaData mmd, Table table, ClassLoaderResolver clr) { CollectionMetaData collectionMetaData = mmd.getCollection(); String wrappedTypeName = collectionMetaData.getElementType(); wrappedTypeClass = clr.classForName(wrappedTypeName); WrappedMemberMetaData wmmd = new WrappedMemberMetaData(mmd, wrappedTypeClass, clr); // Get the actual mapping that handles the the wrapped type wrappedMapping = table.getStoreManager().getMappingManager().getMapping(table, wmmd, clr, FieldRole.ROLE_FIELD); super.initialize(mmd, table, clr); }
public SimpleCollectionMappingStrategy(ObjectProvider sm, AbstractMemberMetaData mmd, Attributes attributes) { super(sm, mmd, attributes); type = sm.getExecutionContext().getClassLoaderResolver().classForName(mmd.getCollection().getElementType()); // For now, each collection element is persisted as its own attribute value if (mmd.getJoinMetaData() == null) { // TODO Drop this hack. Using join as way of saying don't serialise mmd.setJoinMetaData(new JoinMetaData()); } }
/** * Return the type of the attribute. * If the type is simple then returns that java type, otherwise if a collection then returns the * element type. * @return The type of attribute */ public final Type<Y> getType() { ClassLoaderResolver clr = owner.getModel().getClassLoaderResolver(); if (Collection.class.isAssignableFrom(mmd.getType())) { String elementTypeName = mmd.getCollection().getElementType(); return owner.model.getType(clr.classForName(elementTypeName)); } else if (mmd.getType().isArray()) { return owner.model.managedType(mmd.getType().getComponentType()); } else { return owner.model.getType(mmd.getType()); } } }
/** * 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; }
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; } }
Class elementType = clr.classForName(mmd.getCollection().getElementType()); if (!api.isPersistable(elementType) && mmd.getJoinMetaData() == null)
@Override public Class getJavaType() { ClassLoaderResolver clr = storeMgr.getNucleusContext().getClassLoaderResolver(null); if (mmd != null) { if (roleForMember == FieldRole.ROLE_COLLECTION_ELEMENT) { return clr.classForName(mmd.getCollection().getElementType()); } else if (roleForMember == FieldRole.ROLE_ARRAY_ELEMENT) { return clr.classForName(mmd.getArray().getElementType()); } else if (roleForMember == FieldRole.ROLE_MAP_KEY) { return clr.classForName(mmd.getMap().getKeyType()); } else if (roleForMember == FieldRole.ROLE_MAP_VALUE) { return clr.classForName(mmd.getMap().getValueType()); } return mmd.getType(); } return clr.classForName(type); }