Search in sources :

Example 6 with DescriptorException

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());
        }
    }
}
Also used : IntegrityChecker(org.eclipse.persistence.exceptions.IntegrityChecker) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException)

Example 7 with DescriptorException

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;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) Attributes(org.xml.sax.Attributes) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) ClassExtractor(org.eclipse.persistence.descriptors.ClassExtractor) CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) UnmarshalRecord(org.eclipse.persistence.oxm.record.UnmarshalRecord) QNameTransformer(org.eclipse.persistence.internal.xr.QNameTransformer) DataRecord(org.eclipse.persistence.sessions.DataRecord) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) Session(org.eclipse.persistence.sessions.Session)

Example 8 with DescriptorException

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);
}
Also used : DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) PersistenceObject(org.eclipse.persistence.internal.descriptors.PersistenceObject) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) PersistenceEntityCopyPolicy(org.eclipse.persistence.descriptors.copying.PersistenceEntityCopyPolicy) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) PersistenceObjectAttributeAccessor(org.eclipse.persistence.internal.descriptors.PersistenceObjectAttributeAccessor) PersistenceObjectInstantiationPolicy(org.eclipse.persistence.internal.descriptors.PersistenceObjectInstantiationPolicy)

Example 9 with DescriptorException

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);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) Project(org.eclipse.persistence.sessions.Project) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLContext(org.eclipse.persistence.oxm.XMLContext) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) Vector(java.util.Vector) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) ValidationException(org.eclipse.persistence.exceptions.ValidationException)

Example 10 with DescriptorException

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);
}
Also used : Project(org.eclipse.persistence.sessions.Project) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLContext(org.eclipse.persistence.oxm.XMLContext) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) EISDirectMapping(org.eclipse.persistence.eis.mappings.EISDirectMapping) Vector(java.util.Vector) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) ValidationException(org.eclipse.persistence.exceptions.ValidationException)

Aggregations

DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)21 IntegrityException (org.eclipse.persistence.exceptions.IntegrityException)7 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)6 InputStream (java.io.InputStream)4 ValidationException (org.eclipse.persistence.exceptions.ValidationException)4 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)4 JAXBException (jakarta.xml.bind.JAXBException)3 HashMap (java.util.HashMap)3 Vector (java.util.Vector)3 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)3 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)3 XMLTransformationMapping (org.eclipse.persistence.oxm.mappings.XMLTransformationMapping)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)2 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)2 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)2 XMLContext (org.eclipse.persistence.oxm.XMLContext)2