use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class ProjectHelper method fixOROXAccessors.
/**
* INTERNAL: Fix the given EclipseLink OR and OX projects so that the
* descriptors for all generated sub-classes of XRDynamicEntity have the correct
* AttributeAccessors.
*/
public static void fixOROXAccessors(Project orProject, Project oxProject) {
for (Iterator<ClassDescriptor> i = orProject.getDescriptors().values().iterator(); i.hasNext(); ) {
ClassDescriptor desc = i.next();
if (!XRDynamicEntity.class.isAssignableFrom(desc.getJavaClass())) {
continue;
}
Class<?> clz = desc.getJavaClass();
ClassDescriptor xdesc = null;
if (oxProject != null) {
xdesc = oxProject.getDescriptorForAlias(desc.getAlias());
}
XRDynamicPropertiesManager xrDPM = null;
if (!clz.getName().endsWith(COLLECTION_WRAPPER_SUFFIX)) {
try {
XRDynamicEntity newInstance = (XRDynamicEntity) clz.getConstructor().newInstance();
xrDPM = newInstance.fetchPropertiesManager();
} catch (Exception e) {
e.printStackTrace();
}
}
Set<String> propertiesNameSet = new HashSet<>();
for (Iterator<DatabaseMapping> j = desc.getMappings().iterator(); j.hasNext(); ) {
DatabaseMapping dm = j.next();
String attributeName = dm.getAttributeName();
DatabaseMapping xdm = null;
if (xdesc != null) {
xdm = xdesc.getMappingForAttributeName(attributeName);
}
dm.setAttributeAccessor(new XRDynamicEntityAccessor(dm));
if (xdm != null) {
if (dm.isForeignReferenceMapping()) {
ForeignReferenceMapping frm = (ForeignReferenceMapping) dm;
if (frm.usesIndirection() && frm.getIndirectionPolicy().getClass().isAssignableFrom(BasicIndirectionPolicy.class)) {
xdm.setAttributeAccessor(new XRDynamicEntityVHAccessor(dm));
} else {
// no indirection or indirection that is transparent enough (!) to work
xdm.setAttributeAccessor(new XRDynamicEntityAccessor(dm));
}
} else {
xdm.setAttributeAccessor(new XRDynamicEntityAccessor(dm));
}
}
propertiesNameSet.add(attributeName);
}
if (xrDPM != null) {
xrDPM.setPropertyNames(propertiesNameSet);
}
}
// turn-off dynamic class generation
ClassLoader cl = null;
Login login = orProject.getDatasourceLogin();
if (login != null) {
Platform platform = login.getDatasourcePlatform();
if (platform != null) {
ConversionManager conversionManager = platform.getConversionManager();
if (conversionManager != null) {
cl = conversionManager.getLoader();
}
}
}
if (cl instanceof XRDynamicClassLoader) {
XRDynamicClassLoader xrdecl = (XRDynamicClassLoader) cl;
xrdecl.dontGenerateSubclasses();
}
if (oxProject != null) {
cl = null;
login = oxProject.getDatasourceLogin();
if (login != null) {
Platform platform = login.getDatasourcePlatform();
if (platform != null) {
ConversionManager conversionManager = platform.getConversionManager();
if (conversionManager != null) {
cl = conversionManager.getLoader();
}
}
}
if (cl instanceof XRDynamicClassLoader) {
XRDynamicClassLoader xrdecl = (XRDynamicClassLoader) cl;
xrdecl.dontGenerateSubclasses();
}
}
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class JCEEncryptionTest method convertToEncryptionObject.
/**
* Convert a String into a Securable object
* Class name must be fully qualified, eg. org.eclipse.persistence.internal.security.JCEEncryptor
*/
private Securable convertToEncryptionObject(String encryptionClassName) {
try {
ConversionManager cm = ConversionManager.getDefaultManager();
Class<?> securableClass = cm.convertObject(encryptionClassName, Class.class);
return (Securable) securableClass.getConstructor().newInstance();
} catch (Throwable e) {
return null;
}
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class ClassLoaderTest method setup.
@Override
public void setup() {
m_failure = false;
m_mgr = new ConversionManager();
m_mgr.setShouldUseClassLoaderFromCurrentThread(false);
m_mgr.setLoader(null);
ConversionManager.setDefaultLoader(ConversionManager.class.getClassLoader());
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class UnidirectionalOneToManyMapping method extractSourceKeyFromRow.
/**
* 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.
*/
protected Vector extractSourceKeyFromRow(AbstractRecord row, AbstractSession session) {
int size = sourceKeyFields.size();
Vector key = new Vector(size);
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
for (int index = 0; index < size; index++) {
DatabaseField targetField = targetForeignKeyFields.get(index);
DatabaseField sourceField = 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.addElement(value);
}
return key;
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class AggregateCollectionMapping 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 gets 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);
}
Aggregations