use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class DirectCollectionMapping method extractKeyFromTargetRow.
/**
* INTERNAL:
* Extract the source primary key value from the reference direct row.
* Used for batch reading, most following same order and fields as in the mapping.
*/
@Override
protected Object extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) {
int size = this.referenceKeyFields.size();
Object[] key = new Object[size];
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
for (int index = 0; index < size; index++) {
DatabaseField relationField = this.referenceKeyFields.get(index);
DatabaseField sourceField = this.sourceKeyFields.get(index);
Object value = row.get(relationField);
// Must ensure the classification gets a cache hit.
try {
value = conversionManager.convertObject(value, sourceField.getType());
} catch (ConversionException e) {
throw ConversionException.couldNotBeConverted(this, getDescriptor(), e);
}
key[index] = value;
}
return new CacheId(key);
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class DirectCollectionMapping method extractBatchKeyFromRow.
/**
* INTERNAL:
* Extract the primary key value from the source row.
* Used for batch reading, most following same order and fields as in the mapping.
*/
@Override
protected Object extractBatchKeyFromRow(AbstractRecord row, AbstractSession session) {
int size = this.sourceKeyFields.size();
Object[] key = new Object[size];
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
for (int index = 0; index < size; index++) {
DatabaseField field = this.sourceKeyFields.get(index);
Object value = row.get(field);
// Must ensure the classification to get a cache hit.
try {
value = conversionManager.convertObject(value, field.getType());
} catch (ConversionException exception) {
throw ConversionException.couldNotBeConverted(this, this.descriptor, exception);
}
key[index] = value;
}
return new CacheId(key);
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class OneToManyMapping method extractBatchKeyFromRow.
/**
* Extract the key field values from the specified row.
* Used for batch reading. Keep the fields in the same order
* as in the targetForeignKeysToSourceKeys map.
*/
@Override
protected Object extractBatchKeyFromRow(AbstractRecord row, AbstractSession session) {
int size = this.sourceKeyFields.size();
Object[] key = new Object[size];
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
for (int index = 0; index < size; index++) {
DatabaseField sourceField = this.sourceKeyFields.get(index);
Object value = row.get(sourceField);
// Must ensure the classification to get a cache hit.
try {
value = conversionManager.convertObject(value, sourceField.getType());
} catch (ConversionException exception) {
throw ConversionException.couldNotBeConverted(this, this.descriptor, exception);
}
key[index] = value;
}
return new CacheId(key);
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class OneToManyMapping method extractKeyFromTargetRow.
/**
* INTERNAL:
* Extract the source primary key value from the target row.
* Used for batch reading, most following same order and fields as in the mapping.
*/
@Override
protected Object extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) {
int size = this.sourceKeyFields.size();
Object[] key = new Object[size];
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
for (int index = 0; index < size; index++) {
DatabaseField targetField = this.targetForeignKeyFields.get(index);
DatabaseField sourceField = this.sourceKeyFields.get(index);
Object value = row.get(targetField);
// Must ensure the classification gets a cache hit.
try {
value = conversionManager.convertObject(value, sourceField.getType());
} catch (ConversionException e) {
throw ConversionException.couldNotBeConverted(this, getDescriptor(), e);
}
key[index] = value;
}
return new CacheId(key);
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class AnnotationsProcessor method getAnnotations.
/**
* Returns an array of Annotations for a given TypeMappingInfo. This array
* will either be populated from the TypeMappingInfo's array of annotations,
* or based on an xml-element if present. The xml-element will take
* precedence over the annotation array; if there is an xml-element the
* Array of Annotations will be ignored.
*/
private java.lang.annotation.Annotation[] getAnnotations(TypeMappingInfo tmInfo) {
if (tmInfo.getXmlElement() != null) {
ClassLoader loader = helper.getClassLoader();
// create a single ConversionManager for that will be shared by the
// proxy objects
ConversionManager cMgr = new ConversionManager();
cMgr.setLoader(loader);
// unmarshal the node into an XmlElement
org.eclipse.persistence.jaxb.xmlmodel.XmlElement xElt = CompilerHelper.getXmlElement(tmInfo.getXmlElement(), loader);
List<Annotation> annotations = new ArrayList<>();
// where applicable, a given dynamic proxy will contain a Map of
// method name/return value entries
Map<String, Object> components = null;
// handle @XmlElement: set 'type' method
if (!(xElt.getType().equals("jakarta.xml.bind.annotation.XmlElement.DEFAULT"))) {
components = new HashMap<>();
components.put(TYPE_METHOD_NAME, xElt.getType());
annotations.add(AnnotationProxy.getProxy(components, XmlElement.class, loader, cMgr));
}
// handle @XmlList
if (xElt.isXmlList()) {
annotations.add(AnnotationProxy.getProxy(components, XmlList.class, loader, cMgr));
}
// handle @XmlAttachmentRef
if (xElt.isXmlAttachmentRef()) {
annotations.add(AnnotationProxy.getProxy(components, XmlAttachmentRef.class, loader, cMgr));
}
// handle @XmlMimeType: set 'value' method
if (xElt.getXmlMimeType() != null) {
components = new HashMap<>();
components.put(VALUE_METHOD_NAME, xElt.getXmlMimeType());
annotations.add(AnnotationProxy.getProxy(components, XmlMimeType.class, loader, cMgr));
}
// handle @XmlJavaTypeAdapter: set 'type' and 'value' methods
if (xElt.getXmlJavaTypeAdapter() != null) {
components = new HashMap<>();
components.put(TYPE_METHOD_NAME, xElt.getXmlJavaTypeAdapter().getType());
components.put(VALUE_METHOD_NAME, xElt.getXmlJavaTypeAdapter().getValue());
annotations.add(AnnotationProxy.getProxy(components, XmlJavaTypeAdapter.class, loader, cMgr));
}
// return the newly created array of dynamic proxy objects
return annotations.toArray(new Annotation[annotations.size()]);
}
// array of Annotation objects
return tmInfo.getAnnotations();
}
Aggregations