Search in sources :

Example 1 with XRServiceModel

use of org.eclipse.persistence.internal.xr.XRServiceModel in project eclipselink by eclipse-ee4j.

the class DBWSTestSuite method setUp.

/**
 * This method should be used when sessions xml is to be generated and written out
 * to DBWS_SESSION_STREAM.
 *
 * @param stageDir sessions xml will be generated and written out if non-null
 */
public static void setUp(String stageDir, boolean useLogger) throws WSDLException {
    comparer.setIgnoreOrder(true);
    if (builder == null) {
        builder = new DBWSBuilder();
    }
    DBWS_SERVICE_STREAM = new ByteArrayOutputStream();
    DBWS_SCHEMA_STREAM = new ByteArrayOutputStream();
    DBWS_SESSION_STREAM = new ByteArrayOutputStream();
    DBWS_OR_STREAM = new ByteArrayOutputStream();
    DBWS_OX_STREAM = new ByteArrayOutputStream();
    DBWS_WSDL_STREAM = new ByteArrayOutputStream();
    final String username = System.getProperty(DATABASE_USERNAME_KEY, DEFAULT_DATABASE_USERNAME);
    final String password = System.getProperty(DATABASE_PASSWORD_KEY, DEFAULT_DATABASE_PASSWORD);
    final String url = System.getProperty(DATABASE_URL_KEY, DEFAULT_DATABASE_URL);
    String builderString = DBWS_BUILDER_XML_USERNAME + username + DBWS_BUILDER_XML_PASSWORD + password + DBWS_BUILDER_XML_URL + url + DBWS_BUILDER_XML_DRIVER + DATABASE_DRIVER + DBWS_BUILDER_XML_PLATFORM + DATABASE_PLATFORM + DBWS_BUILDER_XML_MAIN;
    XMLContext context = new XMLContext(new DBWSBuilderModelProject());
    XMLUnmarshaller unmarshaller = context.createUnmarshaller();
    DBWSBuilderModel builderModel = (DBWSBuilderModel) unmarshaller.unmarshal(new StringReader(builderString));
    builder.quiet = true;
    builder.setPlatformClassname(DATABASE_PLATFORM);
    builder.properties = builderModel.properties;
    builder.operations = builderModel.operations;
    XRPackager xrPackager = new JSR109WebServicePackager(null, "WebServiceTestPackager", noArchive) {

        @Override
        public void start() {
        // do nothing - don't have to verify existence of 'stageDir' when
        // all the streams are in-memory
        }
    };
    xrPackager.setDBWSBuilder(builder);
    builder.setPackager(xrPackager);
    builder.setPackager(xrPackager);
    dbwsLogger = null;
    if (useLogger) {
        dbwsLogger = new DBWSLogger("DBWSTestLogger", null);
    }
    if (stageDir == null) {
        builder.getProperties().put(SESSIONS_FILENAME_KEY, NO_SESSIONS_FILENAME);
        builder.build(DBWS_SCHEMA_STREAM, __nullStream, DBWS_SERVICE_STREAM, DBWS_OR_STREAM, DBWS_OX_STREAM, __nullStream, __nullStream, __nullStream, __nullStream, __nullStream, __nullStream, __nullStream, dbwsLogger);
    } else {
        xrPackager.setStageDir(new File(stageDir));
        builder.build(DBWS_SCHEMA_STREAM, DBWS_SESSION_STREAM, DBWS_SERVICE_STREAM, DBWS_OR_STREAM, DBWS_OX_STREAM, __nullStream, __nullStream, DBWS_WSDL_STREAM, __nullStream, __nullStream, __nullStream, __nullStream, dbwsLogger);
    }
    XRServiceFactory factory = new XRServiceFactory() {

        @Override
        public XRServiceAdapter buildService(XRServiceModel xrServiceModel) {
            parentClassLoader = this.getClass().getClassLoader();
            xrSchemaStream = new ByteArrayInputStream(DBWS_SCHEMA_STREAM.toByteArray());
            return super.buildService(xrServiceModel);
        }

        @Override
        public void buildSessions() {
            XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
            DatasourceLogin login = new DatabaseLogin();
            login.setUserName(username);
            login.setPassword(password);
            ((DatabaseLogin) login).setConnectionString(url);
            ((DatabaseLogin) login).setDriverClassName(DATABASE_PLATFORM);
            Platform platform = builder.getDatabasePlatform();
            ConversionManager conversionManager = platform.getConversionManager();
            if (conversionManager != null) {
                conversionManager.setLoader(xrdecl);
            }
            login.setDatasourcePlatform(platform);
            ((DatabaseLogin) login).bindAllParameters();
            Project orProject = null;
            if (DBWS_OR_STREAM.size() != 0) {
                MetadataProcessor processor = new MetadataProcessor(new XRPersistenceUnitInfo(xrdecl), new DatabaseSessionImpl(login), xrdecl, false, true, false, false, false, null, null);
                processor.setMetadataSource(new JPAMetadataSource(xrdecl, new StringReader(DBWS_OR_STREAM.toString())));
                PersistenceUnitProcessor.processORMetadata(processor, true, PersistenceUnitProcessor.Mode.ALL);
                processor.addNamedQueries();
                orProject = processor.getProject().getProject();
            } else {
                orProject = new Project();
            }
            orProject.setName(builder.getProjectName().concat(OR_PRJ_SUFFIX));
            orProject.setDatasourceLogin(login);
            DatabaseSession databaseSession = orProject.createDatabaseSession();
            if ("off".equalsIgnoreCase(builder.getLogLevel())) {
                databaseSession.dontLogMessages();
            } else {
                databaseSession.setLogLevel(AbstractSessionLog.translateStringToLoggingLevel(builder.getLogLevel()));
            }
            xrService.setORSession(databaseSession);
            orProject.convertClassNamesToClasses(xrdecl);
            Project oxProject = null;
            if (DBWS_OX_STREAM.size() != 0) {
                Map<String, OXMMetadataSource> metadataMap = new HashMap<String, OXMMetadataSource>();
                StreamSource xml = new StreamSource(new StringReader(DBWS_OX_STREAM.toString()));
                try {
                    JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
                    Unmarshaller unmarshaller = jc.createUnmarshaller();
                    JAXBElement<XmlBindingsModel> jaxbElt = unmarshaller.unmarshal(xml, XmlBindingsModel.class);
                    XmlBindingsModel model = jaxbElt.getValue();
                    for (XmlBindings xmlBindings : model.getBindingsList()) {
                        metadataMap.put(xmlBindings.getPackageName(), new OXMMetadataSource(xmlBindings));
                    }
                } catch (JAXBException jaxbex) {
                    jaxbex.printStackTrace();
                }
                Map<String, Map<String, OXMMetadataSource>> properties = new HashMap<String, Map<String, OXMMetadataSource>>();
                properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataMap);
                try {
                    org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext jCtx = org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(xrdecl, properties);
                    oxProject = jCtx.getXMLContext().getSession(0).getProject();
                } catch (JAXBException e) {
                    e.printStackTrace();
                }
            } else {
                oxProject = new Project();
            }
            oxProject.setName(builder.getProjectName().concat(OX_PRJ_SUFFIX));
            login = (DatasourceLogin) oxProject.getDatasourceLogin();
            if (login != null) {
                platform = login.getDatasourcePlatform();
                if (platform != null) {
                    conversionManager = platform.getConversionManager();
                    if (conversionManager != null) {
                        conversionManager.setLoader(xrdecl);
                    }
                }
            }
            prepareDescriptors(oxProject, orProject, xrdecl);
            ProjectHelper.fixOROXAccessors(orProject, oxProject);
            xrService.setORSession(orProject.createDatabaseSession());
            xrService.getORSession().dontLogMessages();
            xrService.setXMLContext(new XMLContext(oxProject));
            xrService.setOXSession(xrService.getXMLContext().getSession(0));
        }
    };
    context = new XMLContext(new DBWSModelProject());
    unmarshaller = context.createUnmarshaller();
    DBWSModel model = (DBWSModel) unmarshaller.unmarshal(new StringReader(DBWS_SERVICE_STREAM.toString()));
    xrService = factory.buildService(model);
}
Also used : XRPackager(org.eclipse.persistence.tools.dbws.XRPackager) XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) HashMap(java.util.HashMap) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) JAXBContext(jakarta.xml.bind.JAXBContext) DBWSBuilder(org.eclipse.persistence.tools.dbws.DBWSBuilder) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) JSR109WebServicePackager(org.eclipse.persistence.tools.dbws.JSR109WebServicePackager) StringReader(java.io.StringReader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) XmlBindingsModel(org.eclipse.persistence.internal.xr.XmlBindingsModel) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) Unmarshaller(jakarta.xml.bind.Unmarshaller) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) DBWSModel(org.eclipse.persistence.dbws.DBWSModel) XMLContext(org.eclipse.persistence.oxm.XMLContext) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(jakarta.xml.bind.JAXBException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) DBWSBuilderModelProject(org.eclipse.persistence.tools.dbws.DBWSBuilderModelProject) Project(org.eclipse.persistence.sessions.Project) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) XRServiceFactory(org.eclipse.persistence.internal.xr.XRServiceFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) DBWSBuilderModel(org.eclipse.persistence.tools.dbws.DBWSBuilderModel) XRServiceModel(org.eclipse.persistence.internal.xr.XRServiceModel) DBWSBuilderModelProject(org.eclipse.persistence.tools.dbws.DBWSBuilderModelProject) File(java.io.File) MetadataProcessor(org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with XRServiceModel

use of org.eclipse.persistence.internal.xr.XRServiceModel in project eclipselink by eclipse-ee4j.

the class DBWSModelProject method buildServiceDescriptor.

protected XMLDescriptor buildServiceDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(DBWSModel.class);
    descriptor.setDefaultRootElement("dbws");
    XMLDirectMapping name = new XMLDirectMapping();
    name.setAttributeName("name");
    name.setXPath("name/text()");
    descriptor.addMapping(name);
    XMLDirectMapping sessionFile = new XMLDirectMapping();
    sessionFile.setAttributeName("sessionsFile");
    sessionFile.setXPath("sessions-file/text()");
    descriptor.addMapping(sessionFile);
    XMLChoiceCollectionMapping operationsMapping = new XMLChoiceCollectionMapping();
    operationsMapping.setAttributeName("operations");
    operationsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            return ((XRServiceModel) object).getOperationsList();
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            Vector v = (Vector) value;
            XRServiceModel dbwsModel = (XRServiceModel) object;
            Map<String, Operation> operations = dbwsModel.getOperations();
            for (Iterator i = v.iterator(); i.hasNext(); ) {
                Object obj = i.next();
                if (obj instanceof Operation) {
                    Operation op = (Operation) obj;
                    operations.put(op.getName(), op);
                }
            }
        }
    });
    operationsMapping.addChoiceElement("insert", InsertOperation.class);
    operationsMapping.addChoiceElement("query", QueryOperation.class);
    operationsMapping.addChoiceElement("update", UpdateOperation.class);
    operationsMapping.addChoiceElement("delete", DeleteOperation.class);
    operationsMapping.addChoiceElement("batch-sql-query", BatchQueryOperation.class);
    descriptor.addMapping(operationsMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XRServiceModel(org.eclipse.persistence.internal.xr.XRServiceModel) Iterator(java.util.Iterator) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) BatchQueryOperation(org.eclipse.persistence.internal.xr.BatchQueryOperation) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) UpdateOperation(org.eclipse.persistence.internal.xr.UpdateOperation) InsertOperation(org.eclipse.persistence.internal.xr.InsertOperation) DeleteOperation(org.eclipse.persistence.internal.xr.DeleteOperation) Operation(org.eclipse.persistence.internal.xr.Operation) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) Vector(java.util.Vector) Map(java.util.Map)

Example 3 with XRServiceModel

use of org.eclipse.persistence.internal.xr.XRServiceModel in project eclipselink by eclipse-ee4j.

the class ProviderHelper method init.

@SuppressWarnings("unchecked")
public void init(ClassLoader parentClassLoader, ServletContext sc, boolean mtomEnabled) {
    this.parentClassLoader = parentClassLoader;
    this.mtomEnabled = mtomEnabled;
    InputStream xrServiceStream = initXRServiceStream(parentClassLoader, sc);
    DBWSModelProject xrServiceModelProject = new DBWSModelProject();
    XMLContext xmlContext = new XMLContext(xrServiceModelProject);
    XMLUnmarshaller unmarshaller = xmlContext.createUnmarshaller();
    XRServiceModel xrServiceModel;
    try {
        xrServiceModel = (XRServiceModel) unmarshaller.unmarshal(xrServiceStream);
    } catch (XMLMarshalException e) {
        // something went wrong parsing the eclipselink-dbws.xml - can't recover from that
        throw new WebServiceException(DBWSException.couldNotParseDBWSFile());
    } finally {
        try {
            xrServiceStream.close();
        } catch (IOException e) {
        // ignore
        }
    }
    xrSchemaStream = initXRSchemaStream(parentClassLoader, sc);
    try {
        // inherit xrService processing from XRServiceFactory
        buildService(xrServiceModel);
    } catch (Exception e) {
        // something went wrong building the service
        throw new WebServiceException(e);
    }
    // the xrService built by 'buildService' above is overridden to produce an
    // instance of DBWSAdapter (a sub-class of XRService)
    DBWSAdapter dbwsAdapter = (DBWSAdapter) xrService;
    // get inline schema from WSDL - has additional types for the operations
    try (InputStream wsdlInputStream = initWSDLInputStream(parentClassLoader, sc)) {
        StringWriter sw = new StringWriter();
        StreamSource wsdlStreamSource = new StreamSource(wsdlInputStream);
        Transformer t = TransformerFactory.newInstance().newTransformer(new StreamSource(new StringReader(MATCH_SCHEMA)));
        StreamResult streamResult = new StreamResult(sw);
        t.transform(wsdlStreamSource, streamResult);
        SchemaModelProject schemaProject = new SchemaModelProject();
        XMLContext xmlContext2 = new XMLContext(schemaProject);
        unmarshaller = xmlContext2.createUnmarshaller();
        Schema extendedSchema = (Schema) unmarshaller.unmarshal(new StringReader(sw.toString()));
        dbwsAdapter.setExtendedSchema(extendedSchema);
    } catch (IOException | TransformerException e) {
        // that's Ok, WSDL may not contain inline schema
        xmlContext.getSession().getSessionLog().log(SessionLog.FINE, SessionLog.DBWS, "dbws_no_wsdl_inline_schema", e.getLocalizedMessage());
    }
    // an Invocation needs a mapping for its parameters - use XMLAnyCollectionMapping +
    // custom AttributeAccessor
    // NB - this code is NOt in it own initNNN method, cannot be overridden
    String tns = dbwsAdapter.getExtendedSchema().getTargetNamespace();
    Project oxProject = dbwsAdapter.getOXSession().getProject();
    XMLDescriptor invocationDescriptor = new XMLDescriptor();
    invocationDescriptor.setJavaClass(Invocation.class);
    NamespaceResolver nr = new NamespaceResolver();
    invocationDescriptor.setNamespaceResolver(nr);
    nr.put(SERVICE_NAMESPACE_PREFIX, tns);
    nr.setDefaultNamespaceURI(tns);
    XMLAnyCollectionMapping parametersMapping = new XMLAnyCollectionMapping();
    parametersMapping.setAttributeName("parameters");
    parametersMapping.setAttributeAccessor(new AttributeAccessor() {

        Project oxProject;

        DBWSAdapter dbwsAdapter;

        @Override
        public Object getAttributeValueFromObject(Object object) {
            return ((Invocation) object).getParameters();
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            Invocation invocation = (Invocation) object;
            Vector<Object> values = (Vector<Object>) value;
            for (Iterator<Object> i = values.iterator(); i.hasNext(); ) {
                /* scan through values:
                   *  if XML conforms to something mapped, it an object; else it is a DOM Element
                   *  (probably a scalar). Walk through operations for the types, converting
                   *   as required. The 'key' is the local name of the element - for mapped objects,
                   *   have to get the element name from the schema context for the object
                   */
                Object o = i.next();
                if (o instanceof Element) {
                    Element e = (Element) o;
                    String key = e.getLocalName();
                    if ("theInstance".equals(key)) {
                        NodeList nl = e.getChildNodes();
                        for (int j = 0; j < nl.getLength(); j++) {
                            Node n = nl.item(j);
                            if (n.getNodeType() == Node.ELEMENT_NODE) {
                                try {
                                    Object theInstance = dbwsAdapter.getXMLContext().createUnmarshaller().unmarshal(n);
                                    if (theInstance instanceof XMLRoot) {
                                        theInstance = ((XMLRoot) theInstance).getObject();
                                    }
                                    invocation.setParameter(key, theInstance);
                                    break;
                                } catch (XMLMarshalException xmlMarshallException) {
                                    throw new WebServiceException(xmlMarshallException);
                                }
                            }
                        }
                    } else {
                        ClassDescriptor desc = null;
                        for (ClassDescriptor xdesc : oxProject.getOrderedDescriptors()) {
                            XMLSchemaReference schemaReference = xdesc instanceof XMLDescriptor ? ((XMLDescriptor) xdesc).getSchemaReference() : null;
                            if (schemaReference != null && schemaReference.getSchemaContext().equalsIgnoreCase(key)) {
                                desc = xdesc;
                                break;
                            }
                        }
                        if (desc != null) {
                            try {
                                Object theObject = dbwsAdapter.getXMLContext().createUnmarshaller().unmarshal(e, desc.getJavaClass());
                                if (theObject instanceof XMLRoot) {
                                    theObject = ((XMLRoot) theObject).getObject();
                                }
                                invocation.setParameter(key, theObject);
                            } catch (XMLMarshalException xmlMarshallException) {
                                throw new WebServiceException(xmlMarshallException);
                            }
                        } else {
                            String serviceName = e.getParentNode().getLocalName();
                            boolean found = false;
                            for (Operation op : dbwsAdapter.getOperationsList()) {
                                if (op.getName().equals(serviceName)) {
                                    for (Parameter p : op.getParameters()) {
                                        if (p.getName().equals(key)) {
                                            desc = dbwsAdapter.getDescriptorsByQName().get(p.getType());
                                            if (desc != null) {
                                                found = true;
                                            }
                                            break;
                                        }
                                    }
                                }
                                if (found) {
                                    break;
                                }
                            }
                            if (found) {
                                Object theObject = dbwsAdapter.getXMLContext().createUnmarshaller().unmarshal(e, desc.getJavaClass());
                                if (theObject instanceof XMLRoot) {
                                    theObject = ((XMLRoot) theObject).getObject();
                                }
                                invocation.setParameter(key, theObject);
                            } else {
                                // cant use e.getTextContent() - some DOM impls dont support it :-(
                                // String val = e.getTextContent();
                                StringBuilder sb = new StringBuilder();
                                NodeList childNodes = e.getChildNodes();
                                for (int idx = 0; idx < childNodes.getLength(); idx++) {
                                    if (childNodes.item(idx).getNodeType() == Node.TEXT_NODE) {
                                        sb.append(childNodes.item(idx).getNodeValue());
                                    }
                                }
                                invocation.setParameter(key, sb.toString());
                            }
                        }
                    }
                } else {
                    XMLDescriptor descriptor = (XMLDescriptor) oxProject.getDescriptor(o.getClass());
                    String key = descriptor.getDefaultRootElement();
                    int idx = key.indexOf(':');
                    if (idx != -1) {
                        key = key.substring(idx + 1);
                    }
                    invocation.setParameter(key, o);
                }
            }
        }

        public AttributeAccessor setProjectAndAdapter(Project oxProject, DBWSAdapter dbwsAdapter) {
            this.oxProject = oxProject;
            this.dbwsAdapter = dbwsAdapter;
            return this;
        }
    }.setProjectAndAdapter(oxProject, dbwsAdapter));
    parametersMapping.setKeepAsElementPolicy(KEEP_UNKNOWN_AS_ELEMENT);
    invocationDescriptor.addMapping(parametersMapping);
    oxProject.addDescriptor(invocationDescriptor);
    ((DatabaseSessionImpl) dbwsAdapter.getOXSession()).initializeDescriptorIfSessionAlive(invocationDescriptor);
    dbwsAdapter.getXMLContext().storeXMLDescriptorByQName(invocationDescriptor);
    // create SOAP message response handler of appropriate version
    responseWriter = new SOAPResponseWriter(dbwsAdapter);
    responseWriter.initialize();
}
Also used : Transformer(javax.xml.transform.Transformer) Invocation(org.eclipse.persistence.internal.xr.Invocation) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) SOAPElement(jakarta.xml.soap.SOAPElement) Element(org.w3c.dom.Element) SOAPBodyElement(jakarta.xml.soap.SOAPBodyElement) Node(org.w3c.dom.Node) Operation(org.eclipse.persistence.internal.xr.Operation) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) Vector(java.util.Vector) TransformerException(javax.xml.transform.TransformerException) WebServiceException(jakarta.xml.ws.WebServiceException) StreamResult(javax.xml.transform.stream.StreamResult) XMLContext(org.eclipse.persistence.oxm.XMLContext) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) InputStream(java.io.InputStream) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) StreamSource(javax.xml.transform.stream.StreamSource) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) SOAPException(jakarta.xml.soap.SOAPException) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) WebServiceException(jakarta.xml.ws.WebServiceException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) DBWSException(org.eclipse.persistence.exceptions.DBWSException) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) XMLSchemaReference(org.eclipse.persistence.oxm.schema.XMLSchemaReference) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) XRServiceModel(org.eclipse.persistence.internal.xr.XRServiceModel) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) Parameter(org.eclipse.persistence.internal.xr.Parameter) ValueObject(org.eclipse.persistence.internal.xr.ValueObject) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor)

Example 4 with XRServiceModel

use of org.eclipse.persistence.internal.xr.XRServiceModel in project eclipselink by eclipse-ee4j.

the class KeyMappingsTestSuite method setUp.

@BeforeClass
public static void setUp() {
    final String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
    if ("true".equalsIgnoreCase(ddlCreateProp)) {
        ddlCreate = true;
    }
    final String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
    if ("true".equalsIgnoreCase(ddlDropProp)) {
        ddlDrop = true;
    }
    final String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
    if ("true".equalsIgnoreCase(ddlDebugProp)) {
        ddlDebug = true;
    }
    final String username = System.getProperty(DATABASE_USERNAME_KEY);
    if (username == null) {
        fail("error retrieving database username");
    }
    final String password = System.getProperty(DATABASE_PASSWORD_KEY);
    if (password == null) {
        fail("error retrieving database password");
    }
    final String url = System.getProperty(DATABASE_URL_KEY);
    if (url == null) {
        fail("error retrieving database url");
    }
    final String driver = System.getProperty(DATABASE_DRIVER_KEY);
    if (driver == null) {
        fail("error retrieving database driver");
    }
    XRServiceFactory factory = new XRServiceFactory() {

        @Override
        public XRServiceAdapter buildService(XRServiceModel xrServiceModel) {
            parentClassLoader = this.getClass().getClassLoader();
            xrSchemaStream = new ByteArrayInputStream(KEYMAPPINGS_SCHEMA.getBytes());
            return super.buildService(xrServiceModel);
        }

        @Override
        public void buildSessions() {
            XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
            XMLContext context = new XMLContext(new EclipseLinkObjectPersistenceRuntimeXMLProject(), xrdecl);
            XMLUnmarshaller unmarshaller = context.createUnmarshaller();
            Project orProject = (Project) unmarshaller.unmarshal(new StringReader(KEYMAPPINGS_OR_PROJECT));
            DatasourceLogin login = new DatabaseLogin();
            login.setUserName(username);
            login.setPassword(password);
            ((DatabaseLogin) login).setConnectionString(url);
            ((DatabaseLogin) login).setDriverClassName(driver);
            Platform platform = new MySQLPlatform();
            ConversionManager conversionManager = platform.getConversionManager();
            if (conversionManager != null) {
                conversionManager.setLoader(xrdecl);
            }
            login.setDatasourcePlatform(platform);
            ((DatabaseLogin) login).bindAllParameters();
            orProject.setDatasourceLogin(login);
            Project oxProject = (Project) unmarshaller.unmarshal(new StringReader(KEYMAPPINGS_OX_PROJECT));
            login = (DatasourceLogin) oxProject.getDatasourceLogin();
            if (login != null) {
                platform = login.getDatasourcePlatform();
                if (platform != null) {
                    conversionManager = platform.getConversionManager();
                    if (conversionManager != null) {
                        conversionManager.setLoader(xrdecl);
                    }
                }
            }
            ProjectHelper.fixOROXAccessors(orProject, oxProject);
            xrService.setORSession(orProject.createDatabaseSession());
            xrService.getORSession().dontLogMessages();
            xrService.setXMLContext(new XMLContext(oxProject));
            xrService.setOXSession(xrService.getXMLContext().getSession(0));
        }
    };
    XMLContext context = new XMLContext(new DBWSModelProject());
    XMLUnmarshaller unmarshaller = context.createUnmarshaller();
    DBWSModel model = (DBWSModel) unmarshaller.unmarshal(new StringReader(KEYMAPPINGS_DBWS));
    xrService = factory.buildService(model);
    if (ddlCreate) {
        try {
            AllTests.runDdl(CREATE_DDL, ddlDebug);
        } catch (Exception e) {
        // e.printStackTrace();
        }
    }
}
Also used : DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) DBWSModel(org.eclipse.persistence.dbws.DBWSModel) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform) XMLContext(org.eclipse.persistence.oxm.XMLContext) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) EclipseLinkObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject) Project(org.eclipse.persistence.sessions.Project) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) XRServiceFactory(org.eclipse.persistence.internal.xr.XRServiceFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) XRServiceModel(org.eclipse.persistence.internal.xr.XRServiceModel) StringReader(java.io.StringReader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) EclipseLinkObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform) BeforeClass(org.junit.BeforeClass)

Example 5 with XRServiceModel

use of org.eclipse.persistence.internal.xr.XRServiceModel in project eclipselink by eclipse-ee4j.

the class RelationshipsTestSuite method setUp.

@BeforeClass
public static void setUp() {
    final String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
    if ("true".equalsIgnoreCase(ddlCreateProp)) {
        ddlCreate = true;
    }
    final String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
    if ("true".equalsIgnoreCase(ddlDropProp)) {
        ddlDrop = true;
    }
    final String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
    if ("true".equalsIgnoreCase(ddlDebugProp)) {
        ddlDebug = true;
    }
    final String username = System.getProperty(DATABASE_USERNAME_KEY);
    if (username == null) {
        fail("error retrieving database username");
    }
    final String password = System.getProperty(DATABASE_PASSWORD_KEY);
    if (password == null) {
        fail("error retrieving database password");
    }
    final String url = System.getProperty(DATABASE_URL_KEY);
    if (url == null) {
        fail("error retrieving database url");
    }
    final String driver = System.getProperty(DATABASE_DRIVER_KEY);
    if (driver == null) {
        fail("error retrieving database driver");
    }
    XRServiceFactory factory = new XRServiceFactory() {

        @Override
        public XRServiceAdapter buildService(XRServiceModel xrServiceModel) {
            parentClassLoader = this.getClass().getClassLoader();
            xrSchemaStream = new ByteArrayInputStream(RELATIONSHIPS_SCHEMA.getBytes());
            return super.buildService(xrServiceModel);
        }

        @Override
        public void buildSessions() {
            XMLContext context = new XMLContext(new EclipseLinkObjectPersistenceRuntimeXMLProject());
            XMLUnmarshaller unmarshaller = context.createUnmarshaller();
            Project orProject = (Project) unmarshaller.unmarshal(new StringReader(RELATIONSHIPS_OR_PROJECT));
            DatabaseLogin login = new DatabaseLogin();
            login.setUserName(username);
            login.setPassword(password);
            login.setConnectionString(url);
            login.setDriverClassName(driver);
            Platform platform = new MySQLPlatform();
            login.setDatasourcePlatform(platform);
            login.bindAllParameters();
            orProject.setDatasourceLogin(login);
            Project oxProject = (Project) unmarshaller.unmarshal(new StringReader(RELATIONSHIPS_OX_PROJECT));
            ProjectHelper.fixOROXAccessors(orProject, oxProject);
            xrService.setORSession(orProject.createDatabaseSession());
            xrService.getORSession().dontLogMessages();
            xrService.setXMLContext(new XMLContext(oxProject));
            xrService.setOXSession(xrService.getXMLContext().getSession(0));
        }
    };
    XMLContext context = new XMLContext(new DBWSModelProject());
    XMLUnmarshaller unmarshaller = context.createUnmarshaller();
    DBWSModel model = (DBWSModel) unmarshaller.unmarshal(new StringReader(RELATIONSHIPS_DBWS));
    xrService = factory.buildService(model);
    if (ddlCreate) {
        try {
            AllTests.runDdl(CREATE_DDL, ddlDebug);
        } catch (Exception e) {
        // e.printStackTrace();
        }
    }
}
Also used : DBWSModel(org.eclipse.persistence.dbws.DBWSModel) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform) XMLContext(org.eclipse.persistence.oxm.XMLContext) EclipseLinkObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject) Project(org.eclipse.persistence.sessions.Project) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) XRServiceFactory(org.eclipse.persistence.internal.xr.XRServiceFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) XRServiceModel(org.eclipse.persistence.internal.xr.XRServiceModel) StringReader(java.io.StringReader) EclipseLinkObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform) BeforeClass(org.junit.BeforeClass)

Aggregations

XRServiceModel (org.eclipse.persistence.internal.xr.XRServiceModel)5 StringReader (java.io.StringReader)4 DBWSModelProject (org.eclipse.persistence.dbws.DBWSModelProject)4 XMLContext (org.eclipse.persistence.oxm.XMLContext)4 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)4 Project (org.eclipse.persistence.sessions.Project)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DBWSModel (org.eclipse.persistence.dbws.DBWSModel)3 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)3 XRServiceFactory (org.eclipse.persistence.internal.xr.XRServiceFactory)3 XMLPlatform (org.eclipse.persistence.platform.xml.XMLPlatform)3 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)3 Map (java.util.Map)2 Vector (java.util.Vector)2 StreamSource (javax.xml.transform.stream.StreamSource)2 ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)2 DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)2 EclipseLinkObjectPersistenceRuntimeXMLProject (org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject)2 Operation (org.eclipse.persistence.internal.xr.Operation)2 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)2