use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class ConstructorTest method verify.
@Override
protected void verify() {
if (caughtException == null) {
throwError("The proper exception was not thrown:" + org.eclipse.persistence.internal.helper.Helper.cr() + "caught exception was null! " + org.eclipse.persistence.internal.helper.Helper.cr() + org.eclipse.persistence.internal.helper.Helper.cr() + "[EXPECTING] " + expectedException + " or " + secondExpectedException);
}
if (caughtException instanceof IntegrityException) {
boolean illegalAccessConstructorInit = false;
boolean noSuchMethodConstructorInit = false;
boolean noSuchMethodInstantiationInit = false;
IntegrityChecker ic = new IntegrityChecker();
ic = ((IntegrityException) caughtException).getIntegrityChecker();
java.util.Vector exceptionList = ic.getCaughtExceptions();
for (int i = 0; i < exceptionList.size(); i++) {
if (exceptionList.elementAt(i) instanceof DescriptorException) {
if (((DescriptorException) (exceptionList.elementAt(i))).getErrorCode() == DescriptorException.ILLEGAL_ACCESS_WHILE_CONSTRUCTOR_INSTANTIATION) {
illegalAccessConstructorInit = true;
}
if (((DescriptorException) (exceptionList.elementAt(i))).getErrorCode() == DescriptorException.NO_SUCH_METHOD_WHILE_CONSTRUCTOR_INSTANTIATION) {
noSuchMethodConstructorInit = true;
}
if (((DescriptorException) (exceptionList.elementAt(i))).getErrorCode() == DescriptorException.NO_SUCH_METHOD_WHILE_INITIALIZING_INSTANTIATION_POLICY) {
noSuchMethodInstantiationInit = true;
}
}
}
String cr = org.eclipse.persistence.internal.helper.Helper.cr();
if (!illegalAccessConstructorInit && !noSuchMethodConstructorInit && !noSuchMethodInstantiationInit) {
throw new org.eclipse.persistence.testing.framework.TestErrorException("The proper exception was not thrown:" + cr + "[CAUGHT] " + caughtException + cr + cr + "[EXPECTING] " + expectedException.getMessage() + cr + " or " + secondExpectedException.getMessage() + cr + " or " + thirdExpectedException.getMessage());
}
}
}
use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class DBWSModelProject method buildResultDescriptor.
// result
//
// type|attachment
protected XMLDescriptor buildResultDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Result.class);
descriptor.setDefaultRootElement("result");
XMLTransformationMapping type = new XMLTransformationMapping();
type.setAttributeName("type");
QNameTransformer qNameTransformer = new QNameTransformer("type/text()");
type.addFieldTransformer("type/text()", qNameTransformer);
type.setAttributeTransformer(qNameTransformer);
descriptor.addMapping(type);
XMLCompositeObjectMapping attachment = new XMLCompositeObjectMapping();
attachment.setAttributeName("attachment");
attachment.setXPath("attachment");
attachment.setReferenceClass(Attachment.class);
descriptor.addMapping(attachment);
XMLCompositeObjectMapping sxf = new XMLCompositeObjectMapping();
sxf.setAttributeName("simpleXMLFormat");
sxf.setXPath("simple-xml-format");
sxf.setReferenceClass(SimpleXMLFormat.class);
descriptor.addMapping(sxf);
XMLDirectMapping isCollection = new XMLDirectMapping();
isCollection.setAttributeAccessor(new AttributeAccessor() {
@Override
public String getAttributeName() {
return "isCollection";
}
@Override
public Object getAttributeValueFromObject(Object object) throws DescriptorException {
if (object instanceof CollectionResult) {
return Boolean.TRUE;
}
return null;
}
@Override
public void setAttributeValueInObject(Object object, Object value) throws DescriptorException {
}
});
isCollection.setXPath("@isCollection");
descriptor.addMapping(isCollection);
XMLField isColl = new XMLField("@isCollection");
isColl.setSchemaType(BOOLEAN_QNAME);
descriptor.getInheritancePolicy().setClassIndicatorField(isColl);
descriptor.getInheritancePolicy().setClassExtractor(new ClassExtractor() {
@Override
@SuppressWarnings({ "unchecked" })
public <T> Class<T> extractClassFromRow(DataRecord dataRecord, Session session) {
Class<?> clz = Result.class;
UnmarshalRecord uRecord = (UnmarshalRecord) dataRecord;
Attributes attrs = uRecord.getAttributes();
if (attrs != null) {
for (int i = 0, l = attrs.getLength(); i < l; i++) {
String attributeName = attrs.getQName(i);
if (attributeName.equals("isCollection")) {
String value = attrs.getValue(i);
if (value.equalsIgnoreCase("true")) {
clz = CollectionResult.class;
break;
}
}
}
}
return (Class<T>) clz;
}
});
XMLDirectMapping jdbcTypeMapping = new XMLDirectMapping();
jdbcTypeMapping.setAttributeName("jdbcType");
jdbcTypeMapping.setXPath("@jdbcType");
descriptor.addMapping(jdbcTypeMapping);
return descriptor;
}
use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class ClassDescriptor method preInitialize.
/**
* INTERNAL:
* Allow the descriptor to initialize any dependencies on this session.
*/
public void preInitialize(AbstractSession session) throws DescriptorException {
// Avoid repetitive initialization (this does not solve loops)
if (isInitialized(PREINITIALIZED)) {
return;
}
setInitializationStage(PREINITIALIZED);
assignDefaultValues(session);
if (this.isCascadeOnDeleteSetOnDatabaseOnSecondaryTables && !session.getPlatform().supportsDeleteOnCascade()) {
this.isCascadeOnDeleteSetOnDatabaseOnSecondaryTables = false;
}
// Set the fetchgroup manager is the class implements the tracking interface.
if (FetchGroupTracker.class.isAssignableFrom(getJavaClass())) {
if (getFetchGroupManager() == null && !isAggregateDescriptor()) {
// aggregate descriptors will set fetchgroupmanager during mapping init.
setFetchGroupManager(new FetchGroupManager());
}
}
// If weaved avoid reflection, use clone copy and empty new.
if (Arrays.asList(getJavaClass().getInterfaces()).contains(PersistenceObject.class)) {
// Cloning is only auto set for field access, as method access
// may not have simple fields, same with empty new and reflection get/set.
boolean isMethodAccess = false;
for (Iterator<DatabaseMapping> iterator = getMappings().iterator(); iterator.hasNext(); ) {
DatabaseMapping mapping = iterator.next();
if (mapping.isUsingMethodAccess()) {
// Ok for lazy 1-1s
if (!mapping.isOneToOneMapping() || !((ForeignReferenceMapping) mapping).usesIndirection()) {
isMethodAccess = true;
}
} else if (!mapping.isWriteOnly()) {
// Avoid reflection.
mapping.setAttributeAccessor(new PersistenceObjectAttributeAccessor(mapping.getAttributeName()));
}
}
if (!isMethodAccess) {
if (this.copyPolicy == null) {
setCopyPolicy(new PersistenceEntityCopyPolicy());
}
if (!isAbstract()) {
try {
if (this.instantiationPolicy == null) {
setInstantiationPolicy(new PersistenceObjectInstantiationPolicy((PersistenceObject) getJavaClass().getConstructor().newInstance()));
}
} catch (Exception ignore) {
}
}
}
}
// 4924665 Check for spaces in table names, and add the appropriate quote character
Iterator<DatabaseTable> tables = this.getTables().iterator();
while (tables.hasNext()) {
DatabaseTable next = tables.next();
if (next.getName().indexOf(' ') != -1) {
// EL Bug 382420 - set use delimiters to true if table name contains a space
next.setUseDelimiters(true);
}
}
// Allow mapping pre init, must be done before validate.
for (DatabaseMapping mapping : getMappings()) {
try {
mapping.preInitialize(session);
} catch (DescriptorException exception) {
session.getIntegrityChecker().handleError(exception);
}
}
validateBeforeInitialization(session);
preInitializeInheritancePolicy(session);
// Make sure that parent is already preinitialized
if (hasInheritance()) {
// The default table will be set in this call once the duplicate
// tables have been removed.
getInheritancePolicy().preInitialize(session);
} else {
// This must be done now, after validate, before init anything else.
setInternalDefaultTable();
}
// duplicate anything else we have done to support tenant id fields.
if (hasMultitenantPolicy()) {
getMultitenantPolicy().preInitialize(session);
}
verifyTableQualifiers(session.getDatasourcePlatform());
initializeProperties(session);
if (!isAggregateDescriptor()) {
// Adjust before you initialize ...
adjustMultipleTableInsertOrder();
initializeMultipleTablePrimaryKeyFields();
}
if (hasInterfacePolicy()) {
preInterfaceInitialization(session);
}
getQueryManager().preInitialize(session);
}
use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class XMLMarshallerCreateTestCases method testInvalidMappingTypeRelational.
public void testInvalidMappingTypeRelational() {
Project project = new Project();
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Car.class);
descriptor.setDefaultRootElement("test");
DirectToFieldMapping mapping = new DirectToFieldMapping();
mapping.setAttributeName("license");
mapping.setFieldName("license");
descriptor.addMapping(mapping);
project.addDescriptor(descriptor);
try {
XMLContext context = new XMLContext(project);
} catch (DescriptorException exception) {
assertTrue("An invalid mapping type exception should have been caught but wasn't.", exception.getErrorCode() == DescriptorException.INVALID_MAPPING_TYPE);
return;
} catch (IntegrityException exception) {
Vector exceptions = exception.getIntegrityChecker().getCaughtExceptions();
assertTrue("Too many exceptions were found...should have been 1.", exceptions.size() == 1);
Exception e = (Exception) exceptions.elementAt(0);
assertTrue("A DescriptorException should have been caught but wasn't.", e.getClass() == DescriptorException.class);
assertTrue("An invalid mapping type exception should have been caught but wasn't.", ((DescriptorException) e).getErrorCode() == DescriptorException.INVALID_MAPPING_TYPE);
return;
}
assertTrue("An invalid mapping type exception should have been caught but wasn't.", false);
}
use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.
the class XMLMarshallerCreateTestCases method testInvalidMappingTypeEIS.
public void testInvalidMappingTypeEIS() {
Project project = new Project();
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Car.class);
descriptor.setDefaultRootElement("test");
EISDirectMapping mapping = new EISDirectMapping();
mapping.setAttributeName("license");
mapping.setXPath("license");
descriptor.addMapping(mapping);
project.addDescriptor(descriptor);
try {
XMLContext context = new XMLContext(project);
} catch (DescriptorException exception) {
assertTrue("An invalid mapping type exception should have been caught but wasn't.", exception.getErrorCode() == DescriptorException.INVALID_MAPPING_TYPE);
return;
} catch (IntegrityException exception) {
Vector exceptions = exception.getIntegrityChecker().getCaughtExceptions();
assertTrue("Too many exceptions were found...should have been 1.", exceptions.size() == 1);
Exception e = (Exception) exceptions.elementAt(0);
assertTrue("A DescriptorException should have been caught but wasn't.", e.getClass() == DescriptorException.class);
assertTrue("An invalid mapping type exception should have been caught but wasn't.", ((DescriptorException) e).getErrorCode() == DescriptorException.INVALID_MAPPING_TYPE);
return;
}
assertTrue("An invalid mapping type exception should have been caught but wasn't.", false);
}
Aggregations