Search in sources :

Example 36 with DatabaseSessionImpl

use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.

the class SOAPResponseWriter method initialize.

@SuppressWarnings("unchecked")
public void initialize() {
    SOAPResponseClassLoader loader = new SOAPResponseClassLoader(Thread.currentThread().getContextClassLoader());
    NamespaceResolver nr = new NamespaceResolver();
    nr.put(SERVICE_NAMESPACE_PREFIX, dbwsAdapter.getExtendedSchema().getTargetNamespace());
    for (Operation op : dbwsAdapter.getOperationsList()) {
        String className = op.getName() + "_Response";
        Class<?> opClass = loader.buildClass(className);
        XMLDescriptor descriptor = new XMLDescriptor();
        descriptor.setDefaultRootElement(SERVICE_NAMESPACE_PREFIX + ":" + op.getName() + "Response");
        descriptor.setNamespaceResolver(nr);
        descriptor.setJavaClass(opClass);
        if (op instanceof QueryOperation) {
            QueryOperation queryOperation = (QueryOperation) op;
            if (queryOperation.isSimpleXMLFormat()) {
                XMLAnyObjectMapping mapping = new XMLAnyObjectMapping();
                mapping.setUseXMLRoot(true);
                mapping.setAttributeName("result");
                mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                descriptor.addMapping(mapping);
                mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
            } else if (queryOperation.isAttachment()) {
                Attachment attachment = queryOperation.getResult().getAttachment();
                XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
                mapping.setAttributeName("result");
                mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                mapping.setSwaRef(true);
                mapping.setShouldInlineBinaryData(false);
                mapping.setMimeType(attachment.getMimeType());
                descriptor.addMapping(mapping);
            } else {
                QName type = queryOperation.getResult().getType();
                String localElement = type.getLocalPart();
                // look for top-level complex types
                Set<Map.Entry<String, ComplexType>> entrySet = dbwsAdapter.getSchema().getTopLevelComplexTypes().entrySet();
                for (Map.Entry<String, ComplexType> me : entrySet) {
                    if (me.getValue().getName().equals(type.getLocalPart())) {
                        localElement = me.getKey();
                        break;
                    }
                }
                XMLDescriptor typeDescriptor = dbwsAdapter.getDescriptorsByQName().get(type);
                if (typeDescriptor != null) {
                    if (queryOperation.isCollection()) {
                        XMLCompositeCollectionMapping mapping = new XMLCompositeCollectionMapping();
                        mapping.setAttributeName("result");
                        mapping.setReferenceClass(typeDescriptor.getJavaClass());
                        mapping.useCollectionClass(ArrayList.class);
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/" + localElement);
                        descriptor.getNamespaceResolver().setDefaultNamespaceURI(typeDescriptor.getNamespaceResolver().getDefaultNamespaceURI());
                        descriptor.addMapping(mapping);
                        mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
                    } else {
                        XMLCompositeObjectMapping mapping = new XMLCompositeObjectMapping();
                        mapping.setAttributeName("result");
                        mapping.setReferenceClass(typeDescriptor.getJavaClass());
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/" + localElement);
                        descriptor.getNamespaceResolver().setDefaultNamespaceURI(typeDescriptor.getNamespaceResolver().getDefaultNamespaceURI());
                        descriptor.addMapping(mapping);
                        mapping.initialize((AbstractSession) dbwsAdapter.getOXSession());
                    }
                } else {
                    if (type.equals(new QName(W3C_XML_SCHEMA_NS_URI, "any"))) {
                        XMLAnyObjectMapping mapping = new XMLAnyObjectMapping();
                        mapping.setAttributeName("result");
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                        descriptor.addMapping(mapping);
                    } else if (type.equals(new QName(W3C_XML_SCHEMA_NS_URI, BASE_64_BINARY))) {
                        XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
                        mapping.setAttributeName("result");
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
                        mapping.setShouldInlineBinaryData(true);
                        ((XMLField) mapping.getField()).setSchemaType(type);
                        descriptor.addMapping(mapping);
                    } else {
                        XMLDirectMapping mapping = new XMLDirectMapping();
                        mapping.setAttributeName("result");
                        mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result/text()");
                        descriptor.addMapping(mapping);
                    }
                }
            }
        }
        dbwsAdapter.getOXSession().getProject().addDescriptor(descriptor);
        ((DatabaseSessionImpl) dbwsAdapter.getOXSession()).initializeDescriptorIfSessionAlive(descriptor);
        dbwsAdapter.getXMLContext().storeXMLDescriptorByQName(descriptor);
        resultDescriptors.put(op.getName(), descriptor);
    }
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) Set(java.util.Set) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Attachment(org.eclipse.persistence.internal.xr.Attachment) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) Operation(org.eclipse.persistence.internal.xr.Operation) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) HashMap(java.util.HashMap) Map(java.util.Map) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 37 with DatabaseSessionImpl

use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.

the class EntityMappingsAdvancedJUnitTestCase method testEmployeeChangeTrackingPolicy.

/**
 * Verifies that the read-only metadata is correctly processed.
 */
/*    public void testReadOnlyClassSetting() {
        DatabaseSessionImpl session = getDatabaseSession();
        ClassDescriptor descriptor = session.getDescriptor(ReadOnlyClass.class);

        assertFalse("ReadOnlyClass descriptor was not found in the PU [" + m_persistenceUnit + "]", descriptor == null);
        assertTrue("ReadOnlyClass descriptor is not set to read only.", descriptor.shouldBeReadOnly());
    */
/**
 * Verifies that the change tracking metadata is correctly processed.
 * Employee has an AUTO setting, but has EAGER collections and transformation mapping
 * so should not be change tracked.
 */
public void testEmployeeChangeTrackingPolicy() {
    DatabaseSessionImpl session = getDatabaseSession();
    ClassDescriptor descriptor = session.getDescriptor(Employee.class);
    assertFalse("Employee descriptor was not found in the PU [" + m_persistenceUnit + "]", descriptor == null);
    assertFalse("Employee descriptor has incorrect object change policy", descriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy());
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)

Example 38 with DatabaseSessionImpl

use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.

the class EntityMappingsAdvancedJUnitTestCase method testAddressChangeTrackingPolicy.

/**
 * Verifies that the change tracking metadata is correctly processed.
 */
public void testAddressChangeTrackingPolicy() {
    DatabaseSessionImpl session = getDatabaseSession();
    ClassDescriptor descriptor = session.getDescriptor(Address.class);
    assertFalse("Address descriptor was not found in the PU [" + m_persistenceUnit + "]", descriptor == null);
    assertTrue("Address descriptor has incorrect object change policy", descriptor.getObjectChangePolicyInternal().isDeferredChangeDetectionPolicy());
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)

Example 39 with DatabaseSessionImpl

use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.

the class EntityMappingsAdvancedJUnitTestCase method testJoinFetchSetting.

/**
 * Verifies that the join-fetch setting was read correctly from XML.
 */
public void testJoinFetchSetting() {
    DatabaseSessionImpl session = getDatabaseSession();
    ClassDescriptor descriptor = session.getDescriptor(Employee.class);
    if (descriptor == null) {
        fail("Employee descriptor was not found in the PU [" + m_persistenceUnit + "]");
    } else if (((ForeignReferenceMapping) descriptor.getMappingForAttributeName("address")).getJoinFetch() != ForeignReferenceMapping.OUTER_JOIN) {
        fail("join-fetch setting from XML was not read correctly for Employee's address.");
    }
}
Also used : ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)

Example 40 with DatabaseSessionImpl

use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.

the class EntityMappingsAdvancedJUnitTestCase method testExistenceCheckingSetting.

/**
 * Verifies that existence-checking metadata is correctly processed.
 */
public void testExistenceCheckingSetting() {
    DatabaseSessionImpl session = getDatabaseSession();
    ClassDescriptor employeeDescriptor = session.getDescriptor(Employee.class);
    assertTrue("Employee existence checking was incorrect", employeeDescriptor.getQueryManager().getDoesExistQuery().getExistencePolicy() == DoesExistQuery.CheckDatabase);
    ClassDescriptor projectDescriptor = session.getDescriptor(Project.class);
    assertTrue("Project existence checking was incorrect", projectDescriptor.getQueryManager().getDoesExistQuery().getExistencePolicy() == DoesExistQuery.CheckCache);
    ClassDescriptor smallProjectDescriptor = session.getDescriptor(SmallProject.class);
    assertTrue("SmallProject existence checking was incorrect", smallProjectDescriptor.getQueryManager().getDoesExistQuery().getExistencePolicy() == DoesExistQuery.AssumeExistence);
    ClassDescriptor largeProjectDescriptor = session.getDescriptor(LargeProject.class);
    assertTrue("LargeProject existence checking was incorrect", largeProjectDescriptor.getQueryManager().getDoesExistQuery().getExistencePolicy() == DoesExistQuery.AssumeNonExistence);
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)

Aggregations

DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)64 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)18 EntityManager (jakarta.persistence.EntityManager)15 HashMap (java.util.HashMap)14 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)14 Map (java.util.Map)13 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)13 Project (org.eclipse.persistence.sessions.Project)12 StringReader (java.io.StringReader)9 StreamSource (javax.xml.transform.stream.StreamSource)9 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)9 MetadataProcessor (org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor)9 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)9 XMLContext (org.eclipse.persistence.oxm.XMLContext)9 DatasourceLogin (org.eclipse.persistence.sessions.DatasourceLogin)9 JAXBContext (jakarta.xml.bind.JAXBContext)8 JAXBException (jakarta.xml.bind.JAXBException)8 Unmarshaller (jakarta.xml.bind.Unmarshaller)8 ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)8 XRDynamicClassLoader (org.eclipse.persistence.internal.xr.XRDynamicClassLoader)8