use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class ConstructingDescriptorExceptionTests method test.
@Override
public void test() throws NoSuchMethodException {
try {
Class<ConstructingDescriptorExceptionTests> javaClass = ConstructingDescriptorExceptionTests.class;
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClass(javaClass);
TestErrorException dummyException = new TestErrorException("no ERROR");
DirectToFieldMapping mapping = new DirectToFieldMapping();
ForeignReferenceMapping mappingFR = new OneToOneMapping();
IndirectListContainerPolicy policy = new IndirectListContainerPolicy();
Object object = new Object();
DatabaseRecord row = new DatabaseRecord();
Class<?>[] parmClasses = {};
Method method = javaClass.getDeclaredMethod("test", parmClasses);
DescriptorException descriptorException;
descriptorException = DescriptorException.javaClassNotSpecified(descriptor);
if (descriptorException.getErrorCode() != 39)
testResults.add("DescriptorException.javaClassNotSpecified");
// else testResults.add("Passed");
descriptorException = DescriptorException.writeLockFieldInChildDescriptor(descriptor);
if (descriptorException.getErrorCode() != 109)
testResults.add("DescriptorException.writeLockFieldInChildDescriptor");
// else testResults.add("Passed");
descriptorException = DescriptorException.childDoesNotDefineAbstractQueryKeyOfParent(descriptor, descriptor, "dummy");
if (descriptorException.getErrorCode() != 120)
testResults.add("DescriptorException.childDoesNotDefineAbstractQueryKeyOfParent");
// else testResults.add("Passed");
descriptorException = DescriptorException.missingIndirectContainerConstructor(javaClass);
if (descriptorException.getErrorCode() != 145)
testResults.add("DescriptorException.missingIndirectContainerConstructor");
// else testResults.add("Passed");
descriptorException = DescriptorException.couldNotInstantiateIndirectContainerClass(javaClass, dummyException);
if (descriptorException.getErrorCode() != 146)
testResults.add("DescriptorException.couldNotInstantiateIndirectContainerClass");
// else testResults.add("Passed");
descriptorException = DescriptorException.invalidContainerPolicy(policy, javaClass);
if (descriptorException.getErrorCode() != 147)
testResults.add("DescriptorException.invalidContainerPolicy");
// else testResults.add("Passed");
descriptorException = DescriptorException.invalidUseOfNoIndirection(mapping);
if (descriptorException.getErrorCode() != 149)
testResults.add("DescriptorException.invalidUseOfNoIndirection");
// else testResults.add("Passed");
descriptorException = DescriptorException.proxyIndirectionNotAvailable(mapping);
if (descriptorException.getErrorCode() != 159)
testResults.add("DescriptorException.proxyIndirectionNotAvailable");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccesstWhileGettingValueThruInstanceVaraibleAccessor("attributeName", "objectName", dummyException);
if (descriptorException.getErrorCode() != 13)
testResults.add("DescriptorException.illegalAccesstWhileGettingValueThruInstanceVaraibleAccessor");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileCloning(object, "methodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 14)
testResults.add("DescriptorException.illegalAccessWhileCloning");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileEventExecution("eventMethodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 16)
testResults.add("DescriptorException.illegalAccessWhileEventExecution");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileGettingValueThruMethodAccessor("methodName", "objectName", dummyException);
if (descriptorException.getErrorCode() != 17)
testResults.add("DescriptorException.illegalAccessWhileGettingValueThruMethodAccessor");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileInstantiatingMethodBasedProxy(dummyException);
if (descriptorException.getErrorCode() != 18)
testResults.add("DescriptorException.illegalAccessWhileInstantiatingMethodBasedProxy");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileInvokingAttributeMethod(mapping, dummyException);
if (descriptorException.getErrorCode() != 19)
testResults.add("DescriptorException.illegalAccessWhileInvokingAttributeMethod");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileInvokingFieldToMethod("methodName", mapping, dummyException);
if (descriptorException.getErrorCode() != 20)
testResults.add("DescriptorException.illegalAccessWhileInvokingFieldToMethod");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileInvokingRowExtractionMethod(row, method, descriptor, dummyException);
if (descriptorException.getErrorCode() != 21)
testResults.add("DescriptorException.illegalAccessWhileInvokingRowExtractionMethod");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileMethodInstantiation("methodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 22)
testResults.add("DescriptorException.illegalAccessWhileMethodInstantiation");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileObsoleteEventExecute("eventMethodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 23)
testResults.add("DescriptorException.illegalAccessWhileObsoleteEventExecute");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileSettingValueThruInstanceVariableAccessor("attributeName", "objectName", object, dummyException);
if (descriptorException.getErrorCode() != 24)
testResults.add("DescriptorException.illegalAccessWhileSettingValueThruInstanceVariableAccessor");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileSettingValueThruMethodAccessor("setMethodName", object, dummyException);
if (descriptorException.getErrorCode() != 25)
testResults.add("DescriptorException.illegalAccessWhileSettingValueThruMethodAccessor");
// else testResults.add("Passed");
descriptorException = DescriptorException.missingClassForIndicatorFieldValue(object, descriptor);
if (descriptorException.getErrorCode() != 43)
testResults.add("DescriptorException.missingClassForIndicatorFieldValue");
// else testResults.add("Passed");
descriptorException = DescriptorException.missingClassIndicatorField(row, descriptor);
if (descriptorException.getErrorCode() != 44)
testResults.add("DescriptorException.missingClassIndicatorField");
// else testResults.add("Passed");
descriptorException = DescriptorException.notDeserializable(mapping, dummyException);
if (descriptorException.getErrorCode() != 66)
testResults.add("DescriptorException.notDeserializable");
// else testResults.add("Passed");
descriptorException = DescriptorException.notSerializable(mapping, dummyException);
if (descriptorException.getErrorCode() != 67)
testResults.add("DescriptorException.notSerializable");
// else testResults.add("Passed");
descriptorException = DescriptorException.nullPointerWhileSettingValueThruInstanceVariableAccessor("attributeName", object, dummyException);
if (descriptorException.getErrorCode() != 71)
testResults.add("DescriptorException.nullPointerWhileSettingValueThruInstanceVariableAccessor");
// else testResults.add("Passed");
descriptorException = DescriptorException.nullPointerWhileSettingValueThruMethodAccessor("setMethodName", object, dummyException);
if (descriptorException.getErrorCode() != 72)
testResults.add("DescriptorException.nullPointerWhileSettingValueThruMethodAccessor");
// else testResults.add("Passed");
descriptorException = DescriptorException.securityOnFindMethod("methodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 82)
testResults.add("DescriptorException.securityOnFindMethod");
// else testResults.add("Passed");
descriptorException = DescriptorException.securityOnFindObsoleteMethod("methodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 83)
testResults.add("DescriptorException.securityOnFindObsoleteMethod");
// else testResults.add("Passed");
descriptorException = DescriptorException.securityOnInitializingAttributeMethod("attributeMethodName", mapping, dummyException);
if (descriptorException.getErrorCode() != 84)
testResults.add("DescriptorException.securityOnInitializingAttributeMethod");
// else testResults.add("Passed");
descriptorException = DescriptorException.securityWhileConvertingToMethod("methodName", mapping, dummyException);
if (descriptorException.getErrorCode() != 85)
testResults.add("DescriptorException.securityWhileConvertingToMethod");
// else testResults.add("Passed");
descriptorException = DescriptorException.securityWhileInitializingAttributesInInstanceVariableAccessor("attributeName", "javaClassName", dummyException);
if (descriptorException.getErrorCode() != 86)
testResults.add("DescriptorException.securityWhileInitializingAttributesInInstanceVariableAccessor");
// else testResults.add("Passed");
descriptorException = DescriptorException.securityWhileInitializingAttributesInMethodAccessor("setMethodName", "getMethodName", "javaClassName");
if (descriptorException.getErrorCode() != 87)
testResults.add("DescriptorException.securityWhileInitializingAttributesInMethodAccessor");
// else testResults.add("Passed");
descriptorException = DescriptorException.securityWhileInitializingClassExtractionMethod("methodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 88)
testResults.add("DescriptorException.securityWhileInitializingClassExtractionMethod");
// else testResults.add("Passed");
descriptorException = DescriptorException.securityWhileInitializingCopyPolicy("methodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 89)
testResults.add("DescriptorException.securityWhileInitializingCopyPolicy");
// else testResults.add("Passed");
descriptorException = DescriptorException.securityWhileInitializingInstantiationPolicy("methodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 90)
testResults.add("DescriptorException.securityWhileInitializingInstantiationPolicy");
// else testResults.add("Passed");
descriptorException = DescriptorException.sizeMismatchOfForeignKeys(mappingFR);
if (descriptorException.getErrorCode() != 92)
testResults.add("DescriptorException.sizeMismatchOfForeignKeys");
// else testResults.add("Passed");
descriptorException = DescriptorException.targetForeignKeysSizeMismatch(mappingFR);
if (descriptorException.getErrorCode() != 96)
testResults.add("DescriptorException.targetForeignKeysSizeMismatch");
// else testResults.add("Passed");
descriptorException = DescriptorException.multipleTableInsertOrderMismatch(descriptor);
if (descriptorException.getErrorCode() != 143)
testResults.add("DescriptorException.multipleTableInsertOrderMismatch");
// else testResults.add("Passed");
descriptorException = DescriptorException.variableOneToOneMappingIsNotDefinedProperly(mapping, descriptor, "targetKeyName");
if (descriptorException.getErrorCode() != 166)
testResults.add("DescriptorException.variableOneToOneMappingIsNotDefinedProperly");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileConstructorInstantiationOfFactory(descriptor, dummyException);
if (descriptorException.getErrorCode() != 170)
testResults.add("DescriptorException.illegalAccessWhileConstructorInstantiationOfFactory");
// else testResults.add("Passed");
descriptorException = DescriptorException.noSuchMethodWhileConstructorInstantiationOfFactory(descriptor, dummyException);
if (descriptorException.getErrorCode() != 172)
testResults.add("DescriptorException.noSuchMethodWhileConstructorInstantiationOfFactory");
// else testResults.add("Passed");
descriptorException = DescriptorException.nullPointerWhileConstructorInstantiationOfFactory(descriptor, dummyException);
if (descriptorException.getErrorCode() != 173)
testResults.add("DescriptorException.nullPointerWhileConstructorInstantiationOfFactory");
// else testResults.add("Passed");
descriptorException = DescriptorException.illegalAccessWhileMethodInstantiationOfFactory("methodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 174)
testResults.add("DescriptorException.illegalAccessWhileMethodInstantiationOfFactory");
// else testResults.add("Passed");
descriptorException = DescriptorException.targetInvocationWhileMethodInstantiationOfFactory("methodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 175)
testResults.add("DescriptorException.targetInvocationWhileMethodInstantiationOfFactory");
// else testResults.add("Passed");
descriptorException = DescriptorException.nullPointerWhileMethodInstantiationOfFactory("methodName", descriptor, dummyException);
if (descriptorException.getErrorCode() != 176)
testResults.add("DescriptorException.nullPointerWhileMethodInstantiationOfFactory");
// else testResults.add("Passed");
descriptorException = DescriptorException.mappingForAttributeIsMissing("attributeName", descriptor);
if (descriptorException.getErrorCode() != 177)
testResults.add("DescriptorException.mappingForAttributeIsMissing");
// else testResults.add("Passed");
descriptorException = DescriptorException.attributeMappingIsMissingForEntityBean("attributeName", "beanName");
if (descriptorException.getErrorCode() != 178)
testResults.add("DescriptorException.attributeMappingIsMissingForEntityBean");
// else testResults.add("Passed");
} catch (EclipseLinkException exception) {
caughtException = exception;
}
}
use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class MergeDeadIndirectionTest method test.
/**
* Simulate detching and object and attempting to merge it.
*/
@Override
public void test() {
getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
UnitOfWork uow = getSession().acquireUnitOfWork();
PhoneNumber detachedPhone = (PhoneNumber) uow.readObject(PhoneNumber.class);
((DatabaseValueHolder) detachedPhone.owner).setSession(null);
uow.release();
getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
uow = getSession().acquireUnitOfWork();
DescriptorException caughtException = null;
try {
uow.deepMergeClone(detachedPhone);
} catch (DescriptorException exception) {
caughtException = exception;
}
if ((caughtException == null) || (caughtException.getErrorCode() != DescriptorException.ATTEMPT_TO_REGISTER_DEAD_INDIRECTION)) {
throwError("Incorrect exception thrown. " + caughtException);
}
uow.release();
}
use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class XMLDescriptor method preInitialize.
/**
* INTERNAL:
* Allow the descriptor to initialize any dependencies on this session.
*/
@Override
public void preInitialize(AbstractSession session) throws DescriptorException {
// Avoid repetitive initialization (this does not solve loops)
if (isInitialized(PREINITIALIZED)) {
return;
}
setInitializationStage(PREINITIALIZED);
// Allow mapping pre init, must be done before validate.
for (Enumeration<DatabaseMapping> mappingsEnum = getMappings().elements(); mappingsEnum.hasMoreElements(); ) {
try {
DatabaseMapping mapping = mappingsEnum.nextElement();
mapping.preInitialize(session);
} catch (DescriptorException exception) {
session.getIntegrityChecker().handleError(exception);
}
}
getCachePolicy().useNoIdentityMap();
getQueryManager().getDoesExistQuery().setExistencePolicy(DoesExistQuery.CheckDatabase);
validateBeforeInitialization(session);
preInitializeInheritancePolicy(session);
verifyTableQualifiers(session.getDatasourcePlatform());
initializeProperties(session);
if (hasInterfacePolicy()) {
preInterfaceInitialization(session);
}
getCachePolicy().assignDefaultValues(session);
}
use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class AbstractTransformationMapping method initializeFieldToTransformers.
/**
* INTERNAL:
* Convert the field names and their corresponding method names to
* DatabaseFields and Methods.
*/
protected void initializeFieldToTransformers(AbstractSession session) throws DescriptorException {
for (Object[] pair : this.fieldToTransformers) {
pair[0] = getDescriptor().buildField(((DatabaseField) pair[0]));
((FieldTransformer) pair[1]).initialize(this);
}
for (FieldTransformation transformation : getFieldTransformations()) {
DatabaseField field = getDescriptor().buildField(transformation.getField());
String transformerClassName = "MethodBasedFieldTransformer";
FieldTransformer transformer = null;
try {
transformer = transformation.buildTransformer();
} catch (ConversionException ex) {
if (transformation instanceof TransformerBasedFieldTransformation) {
transformerClassName = ((TransformerBasedFieldTransformation) transformation).getTransformerClassName();
}
throw DescriptorException.fieldTransformerClassNotFound(transformerClassName, this, ex);
} catch (Exception ex) {
if (transformation instanceof TransformerBasedFieldTransformation) {
transformerClassName = ((TransformerBasedFieldTransformation) transformation).getTransformerClassName();
}
throw DescriptorException.fieldTransformerClassInvalid(transformerClassName, this, ex);
}
transformer.initialize(this);
// Attempt to ensure a type is set on the field.
if (field.getType() == null) {
if (transformer instanceof MethodBasedFieldTransformer) {
field.setType(((MethodBasedFieldTransformer) transformer).getFieldType());
} else if (field.getColumnDefinition() != null) {
// Search for the type for this field definition.
if (session.getDatasourcePlatform() instanceof DatabasePlatform) {
Iterator<Map.Entry<Class<?>, FieldTypeDefinition>> iterator = session.getPlatform().getFieldTypes().entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Class<?>, FieldTypeDefinition> entry = iterator.next();
if (entry.getValue().getName().equals(field.getColumnDefinition())) {
field.setType(entry.getKey());
break;
}
}
}
}
}
Object[] fieldToTransformer = new Object[2];
fieldToTransformer[0] = field;
fieldToTransformer[1] = transformer;
this.fieldToTransformers.add(fieldToTransformer);
}
}
use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class DBWSBuilderModelProject method buildBatchSQLOperationModelDescriptor.
/**
* Build an XMLDescriptor for the BatchSQLOperationModel.
*/
protected ClassDescriptor buildBatchSQLOperationModelDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(BatchSQLOperationModel.class);
descriptor.setDefaultRootElement("batch-sql");
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setXPath("@name");
descriptor.addMapping(nameMapping);
XMLDirectMapping returnTypeMapping = new XMLDirectMapping();
returnTypeMapping.setAttributeName("returnType");
returnTypeMapping.setXPath("@returnType");
descriptor.addMapping(returnTypeMapping);
XMLDirectMapping statementsMapping = new XMLDirectMapping();
statementsMapping.setAttributeName("batchSql");
XMLField f1 = new XMLField("batch-statement/text()");
f1.setIsCDATA(true);
statementsMapping.setField(f1);
// need to setup a custom accessor to convert to/from a List and an '\n' separated string
statementsMapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public void setAttributeValueInObject(Object object, Object value) throws DescriptorException {
String rawBatchStatements = (String) value;
String[] batchStatements = rawBatchStatements.split("\n");
List<String> listOfStatements = Arrays.asList(batchStatements);
((BatchSQLOperationModel) object).setBatchSql(listOfStatements);
}
@Override
public Object getAttributeValueFromObject(Object object) throws DescriptorException {
return ((BatchSQLOperationModel) object).getBatchSql();
}
});
descriptor.addMapping(statementsMapping);
return descriptor;
}
Aggregations