use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class AggregateCollectionMapping 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.targetForeignKeyFields.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 OrderedListContainerPolicy method addAll.
protected boolean addAll(List elements, Object container, AbstractSession session, List<AbstractRecord> dbRows, ReadQuery query, CacheKey parentCacheKey) {
int size = dbRows.size();
if (this.elementDescriptor != null && this.elementDescriptor.getObjectBuilder().hasWrapperPolicy()) {
ObjectBuilder objectBuilder = this.elementDescriptor.getObjectBuilder();
List wrappedElements = new ArrayList(size);
for (int i = 0; i < size; i++) {
wrappedElements.add(objectBuilder.wrapObject(elements.get(i), session));
}
elements = wrappedElements;
}
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
// populate container with a dummy so the container.set(i, obj) could be used later.
for (int i = 0; i < size; i++) {
((List) container).add(NOT_SET);
}
// insert the elements into container
boolean failed = false;
for (int i = 0; i < size; i++) {
AbstractRecord row = dbRows.get(i);
Object orderValue = row.get(this.listOrderField);
// order value is null
if (orderValue == null) {
failed = true;
break;
}
int intOrderValue = conversionManager.convertObject(orderValue, Integer.class);
try {
// one or more elements have the same order value
if (NOT_SET != ((List) container).set(intOrderValue, elements.get(i))) {
failed = true;
break;
}
} catch (IndexOutOfBoundsException indexException) {
// order value negative or greater/equal to size
failed = true;
break;
}
}
if (failed) {
((List) container).clear();
// extract order list - it will be set into exception or used by order correction.
List<Integer> orderList = new ArrayList(size);
for (int i = 0; i < size; i++) {
AbstractRecord row = dbRows.get(i);
Object orderValue = row.get(this.listOrderField);
if (orderValue == null) {
orderList.add(null);
} else {
orderList.add(conversionManager.convertObject(orderValue, Integer.class));
}
}
if (this.orderCorrectionType == OrderCorrectionType.READ || this.orderCorrectionType == OrderCorrectionType.READ_WRITE) {
// pair each element with its order index
List<IndexedObject> indexedElements = new ArrayList(size);
for (int i = 0; i < size; i++) {
indexedElements.add(new IndexedObject(orderList.get(i), elements.get(i)));
}
// put elements in order and add to container
((List) container).addAll(correctOrderList(indexedElements));
if (this.orderCorrectionType == OrderCorrectionType.READ_WRITE) {
// mark IndirectList to have broken order
((IndirectList) container).setIsListOrderBrokenInDb(true);
}
} else {
// this.orderCorrectionType == OrderCorrectionType.EXCEPTION
throw QueryException.listOrderFieldWrongValue(query, this.listOrderField, orderList);
}
}
return size > 0;
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class SecurableObjectHolder method initSecurableObject.
/**
* Convert a String into a Securable object
* Class name must be fully qualified, eg. org.eclipse.persistence.internal.security.JCEEncryptor
* Default is the JCEEncryptor
*/
private void initSecurableObject() {
boolean initPassThroughEncryptor = false;
if (m_securableClassName == null) {
// Since we are defaulting, hence, assuming they can initialize the JCE
// libraries, if the init fails, this flag tells us to assume no encryption.
// However, if the JCE init does work, the JCEEncryptor will need to
// determine that a password was not encrypted by it, therefore, assume
// clear text. See JCEEncryptor.
initPassThroughEncryptor = true;
m_securableClassName = JCE_ENCRYPTION_CLASS_NAME;
}
try {
ConversionManager cm = ConversionManager.getDefaultManager();
Class<?> securableClass = cm.convertObject(m_securableClassName, Class.class);
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
try {
m_securableObject = (Securable) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(securableClass));
} catch (PrivilegedActionException exception) {
throw exception.getException();
}
} else {
m_securableObject = (Securable) PrivilegedAccessHelper.newInstanceFromClass(securableClass);
}
} catch (Throwable e) {
if (initPassThroughEncryptor) {
// default failed, so perform no encryption.
m_securableObject = new PassThroughEncryptor();
} else {
throw ValidationException.invalidEncryptionClass(m_securableClassName, e);
}
}
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class XMLProjectReader method read.
/**
* PUBLIC:
* Read the EclipseLink project deployment XML from the file or resource name.
* If a resource name is used the class loader will be used to resolve the resource.
* Note the class loader must be able to resolve the domain classes.
* Note the file must be the deployment XML, not the Mapping Workbench project file.
*/
public static Project read(String fileOrResourceName, ClassLoader classLoader) {
if (fileOrResourceName.toLowerCase().indexOf(".mwp") != -1) {
throw ValidationException.invalidFileName(fileOrResourceName);
}
InputStream fileStream = null;
if (classLoader == null) {
fileStream = (new ConversionManager()).getLoader().getResourceAsStream(fileOrResourceName);
} else {
fileStream = classLoader.getResourceAsStream(fileOrResourceName);
}
if (fileStream == null) {
File file = new File(fileOrResourceName);
if (!file.exists()) {
throw ValidationException.projectXMLNotFound(fileOrResourceName, null);
}
try {
fileStream = new FileInputStream(fileOrResourceName);
} catch (FileNotFoundException exception) {
throw ValidationException.projectXMLNotFound(fileOrResourceName, exception);
}
}
InputStreamReader reader = null;
try {
// Bug2631348 Only UTF-8 is supported
reader = new InputStreamReader(fileStream, StandardCharsets.UTF_8);
Project project = read(reader, classLoader);
return project;
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException exception) {
throw ValidationException.fileError(exception);
}
}
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class DynamicClassLoader method lookup.
/**
* Lookup the DynamicConversionManager for the given session. If the
* existing ConversionManager is not an instance of DynamicConversionManager
* then create a new one and replace the existing one.
*/
public static DynamicClassLoader lookup(Session session) {
ConversionManager cm = null;
if (session == null) {
cm = ConversionManager.getDefaultManager();
} else {
cm = session.getPlatform().getConversionManager();
}
if (cm.getLoader() instanceof DynamicClassLoader) {
return (DynamicClassLoader) cm.getLoader();
}
DynamicClassLoader dcl = new DynamicClassLoader(cm.getLoader());
cm.setLoader(dcl);
if (session == null) {
ConversionManager.setDefaultLoader(dcl);
}
return dcl;
}
Aggregations