Search in sources :

Example 1 with SimpleXMLFormatProject

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

the class BaseDBWSBuilderHelper method buildOROXProjects.

/**
 * Builds OR/OX projects, descriptors {@literal &} mappings, based on a given list
 * of types, as well as table(s) and secondary SQL.
 */
public void buildOROXProjects(NamingConventionTransformer nct, List<CompositeDatabaseType> types) {
    // save for later
    this.nct = nct;
    String projectName = dbwsBuilder.getProjectName();
    Project orProject = new Project();
    orProject.setName(projectName + UNDERSCORE + DBWS_OR_LABEL);
    Project oxProject = null;
    if (dbTables.isEmpty() && !dbwsBuilder.hasBuildSqlOperations()) {
        dbwsBuilder.logMessage(FINEST, "No tables specified");
        oxProject = new SimpleXMLFormatProject();
    } else {
        oxProject = new Project();
    }
    oxProject.setName(projectName + UNDERSCORE + DBWS_OX_LABEL);
    for (TableType dbTable : dbTables) {
        String tableName = dbTable.getTableName();
        RelationalDescriptor desc = buildORDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.requireCRUDOperations, nct);
        orProject.addDescriptor(desc);
        XMLDescriptor xdesc = buildOXDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.getTargetNamespace(), nct);
        oxProject.addDescriptor(xdesc);
        for (FieldType dbColumn : dbTable.getColumns()) {
            String columnName = dbColumn.getFieldName();
            ElementStyle style = nct.styleForElement(columnName);
            if (style == NONE) {
                continue;
            }
            dbwsBuilder.logMessage(FINE, "Building mappings for " + tableName + DOT + columnName);
            DirectToFieldMapping orFieldMapping = buildORFieldMappingFromColumn(dbColumn, desc, dbwsBuilder.getDatabasePlatform(), nct);
            desc.addMapping(orFieldMapping);
            XMLDirectMapping oxFieldMapping = buildOXFieldMappingFromColumn(dbColumn, dbwsBuilder.getDatabasePlatform(), nct);
            if (oxFieldMapping instanceof XMLBinaryDataMapping) {
                xdesc.getNamespaceResolver().put(XML_MIME_PREFIX, XML_MIME_URL);
            }
            xdesc.addMapping(oxFieldMapping);
            // check for switch from Byte[] to byte[]
            if (oxFieldMapping.getAttributeClassificationName() == APBYTE.getName()) {
                orFieldMapping.setAttributeClassificationName(APBYTE.getName());
            }
        }
        setUpFindQueries(nct, tableName, desc);
    }
    finishUpProjects(orProject, oxProject, types);
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ElementStyle(org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType)

Example 2 with SimpleXMLFormatProject

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

the class XRServiceFactory method buildSessions.

/**
 * <p>INTERNAL:
 */
@SuppressWarnings("rawtypes")
public void buildSessions() {
    XRDynamicClassLoader projectLoader = new XRDynamicClassLoader(parentClassLoader);
    SessionManager sessionManager = SessionManager.getManager();
    boolean found = false;
    String sessionsFile = xrService.sessionsFile == null ? DBWS_SESSIONS_XML : xrService.sessionsFile;
    for (String prefix : META_INF_PATHS) {
        String searchPath = prefix + sessionsFile;
        XRSessionConfigLoader loader = new XRSessionConfigLoader(searchPath);
        loader.setShouldLogin(false);
        try {
            found = loader.load(sessionManager, projectLoader);
        } catch (RuntimeException e) {
        /* ignore */
        }
        if (found) {
            break;
        }
    }
    if (!found) {
        throw DBWSException.couldNotLocateFile(DBWS_SESSIONS_XML);
    }
    // make sure the OR/OX sessions were loaded successfully
    Map sessions = sessionManager.getSessions();
    String orSessionKey = xrService.name + DASH_STR + DBWS_OR_SESSION_NAME_SUFFIX;
    if (!sessions.containsKey(orSessionKey)) {
        throw DBWSException.couldNotLocateORSessionForService(xrService.name);
    }
    String oxSessionKey = xrService.name + DASH_STR + DBWS_OX_SESSION_NAME_SUFFIX;
    if (!sessions.containsKey(oxSessionKey)) {
        throw DBWSException.couldNotLocateOXSessionForService(xrService.name);
    }
    xrService.orSession = (Session) sessions.get(orSessionKey);
    xrService.oxSession = (Session) sessions.get(oxSessionKey);
    // load OX project via xml-bindings
    Project oxProject;
    if ((oxProject = loadOXMetadata(projectLoader, xrService.oxSession)) == null) {
        // at this point we may have a legacy deployment XML project, or none set
        oxProject = xrService.oxSession.getProject();
        // check to see if it's a default Project
        if (oxProject.getName().length() == 0) {
            // default to SimpleXMLFormat
            oxProject = new SimpleXMLFormatProject();
        }
    }
    ((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
    ((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);
    // load OR project via entity-mappings
    Project orProject;
    if ((orProject = loadORMetadata(projectLoader, (ServerSession) xrService.orSession)) == null) {
        // at this point we may have a legacy deployment XML project, or none set
        orProject = xrService.orSession.getProject();
        updateFindQueryNames(orProject);
    }
    prepareDescriptors(oxProject, orProject, projectLoader);
    ProjectHelper.fixOROXAccessors(orProject, oxProject);
    xrService.xmlContext = new XMLContext(oxProject);
    xrService.oxSession = xrService.xmlContext.getSession(0);
}
Also used : SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) XMLContext(org.eclipse.persistence.oxm.XMLContext) SessionManager(org.eclipse.persistence.sessions.factories.SessionManager) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with SimpleXMLFormatProject

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

the class SQLOperationModel method buildOperation.

@Override
public void buildOperation(DBWSBuilder builder) {
    super.buildOperation(builder);
    QueryOperation qo = new QueryOperation();
    qo.setName(name);
    SQLQueryHandler sqlqh = new SQLQueryHandler();
    Result result;
    if (isCollection) {
        result = new CollectionResult();
    } else {
        result = new Result();
    }
    SimpleXMLFormat sxf = null;
    if (isSimpleXMLFormat() || getReturnType() == null) {
        sxf = new SimpleXMLFormat();
        if (simpleXMLFormatTag != null && simpleXMLFormatTag.length() > 0) {
            sxf.setSimpleXMLFormatTag(simpleXMLFormatTag);
        }
        result.setType(SXF_QNAME);
    }
    if (xmlTag != null && xmlTag.length() > 0) {
        if (sxf == null) {
            sxf = new SimpleXMLFormat();
            result.setType(SXF_QNAME);
        }
        sxf.setXMLTag(xmlTag);
    }
    if (sxf != null) {
        result.setSimpleXMLFormat(sxf);
        // check to see if the O-X project needs descriptor for SimpleXMLFormat
        if (builder.oxProject.getDescriptorForAlias(DEFAULT_SIMPLE_XML_FORMAT_TAG) == null) {
            SimpleXMLFormatProject sxfProject = new SimpleXMLFormatProject();
            builder.oxProject.addDescriptor(sxfProject.buildXRRowSetModelDescriptor());
        }
    }
    if (binaryAttachment) {
        Attachment attachment = new Attachment();
        attachment.setMimeType(DEFAULT_ATTACHMENT_MIMETYPE);
        result.setAttachment(attachment);
    }
    if (returnType != null && returnType.length() > 0) {
        result.setType(qNameFromString("{" + builder.getTargetNamespace() + "}" + returnType, builder.schema));
    } else {
        result.setType(SXF_QNAME);
        result.setSimpleXMLFormat(sxf == null ? new SimpleXMLFormat() : sxf);
    }
    qo.setResult(result);
    sqlqh.setSqlString(convertJDBCParameterBindingMarkers(sql, bindings));
    if (!bindings.isEmpty()) {
        for (BindingModel param : bindings) {
            Parameter p = new Parameter();
            p.setName(param.name);
            p.setType(qNameFromString(param.type, builder.schema));
            qo.getParameters().add(p);
        }
    }
    qo.setQueryHandler(sqlqh);
    builder.xrServiceModel.getOperations().put(qo.getName(), qo);
    // check to see if the schema requires sxfType to be added
    if (requiresSimpleXMLFormat(builder.xrServiceModel) && builder.schema.getTopLevelElements().get("simple-xml-format") == null) {
        addSimpleXMLFormat(builder.schema);
    }
}
Also used : CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) SQLQueryHandler(org.eclipse.persistence.internal.xr.SQLQueryHandler) Parameter(org.eclipse.persistence.internal.xr.Parameter) Attachment(org.eclipse.persistence.internal.xr.Attachment) Util.addSimpleXMLFormat(org.eclipse.persistence.tools.dbws.Util.addSimpleXMLFormat) SimpleXMLFormat(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormat) Util.requiresSimpleXMLFormat(org.eclipse.persistence.tools.dbws.Util.requiresSimpleXMLFormat) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) Result(org.eclipse.persistence.internal.xr.Result) CollectionResult(org.eclipse.persistence.internal.xr.CollectionResult)

Example 4 with SimpleXMLFormatProject

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

the class BaseDBWSBuilderHelper method writeOROXProjects.

public void writeOROXProjects(OutputStream dbwsOrStream, OutputStream dbwsOxStream) {
    Project orProject = dbwsBuilder.getOrProject();
    Project oxProject = dbwsBuilder.getOxProject();
    boolean writeORProject = false;
    if (hasTables() || dbwsBuilder.hasBuildSqlOperations()) {
        writeORProject = true;
    }
    if (!writeORProject) {
        // check for any named queries - SimpleXMLFormatProject sometimes need them
        if (orProject.getQueries().size() > 0) {
            writeORProject = true;
        } else // check for ObjectRelationalDataTypeDescriptor's - Advanced JDBC object/varray types
        if (orProject.getDescriptors().size() > 0) {
            Collection<ClassDescriptor> descriptors = orProject.getDescriptors().values();
            for (ClassDescriptor desc : descriptors) {
                if (desc.isObjectRelationalDataTypeDescriptor()) {
                    writeORProject = true;
                    break;
                }
            }
        }
    }
    if ((writeORProject || !dbwsBuilder.xrServiceModel.getOperations().isEmpty()) && !isNullStream(dbwsOrStream)) {
        XMLContext context = new XMLContext(workbenchXMLProject);
        context.getSession(orProject).getEventManager().addListener(new MissingDescriptorListener());
        XMLEntityMappings mappings = XmlEntityMappingsGenerator.generateXmlEntityMappings(orProject, complextypes, crudOps);
        if (mappings != null) {
            XMLEntityMappingsWriter.write(mappings, dbwsOrStream);
        }
    }
    if (!isNullStream(dbwsOxStream)) {
        boolean writeOXProject = false;
        if (hasTables() || dbwsBuilder.hasBuildSqlOperations()) {
            writeOXProject = true;
        }
        if (!writeOXProject) {
            // check for any named queries - SimpleXMLFormatProject's sometimes need them
            if (orProject.getQueries().size() > 0) {
                writeOXProject = true;
            } else // check for ObjectRelationalDataTypeDescriptor's - Advanced JDBC object/varray types
            if (orProject.getDescriptors().size() > 0) {
                Collection<ClassDescriptor> descriptors = orProject.getDescriptors().values();
                for (ClassDescriptor desc : descriptors) {
                    if (desc.isObjectRelationalDataTypeDescriptor()) {
                        writeOXProject = true;
                        break;
                    }
                }
            }
        }
        if (writeOXProject) {
            List<XmlBindings> xmlBindingsList = XmlBindingsGenerator.generateXmlBindings(oxProject.getOrderedDescriptors());
            if (xmlBindingsList.size() > 0) {
                XmlBindingsModel model = new XmlBindingsModel();
                model.setBindingsList(xmlBindingsList);
                try {
                    JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
                    Marshaller marshaller = jc.createMarshaller();
                    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
                    marshaller.marshal(model, dbwsOxStream);
                } catch (JAXBException jaxbEx) {
                    throw new DBWSException(OXM_MARSHAL_EX_MSG, jaxbEx);
                }
            }
        }
    }
    dbwsBuilder.getPackager().closeOrStream(dbwsOrStream);
    dbwsBuilder.getPackager().closeOxStream(dbwsOxStream);
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) Marshaller(jakarta.xml.bind.Marshaller) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLEntityMappings(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings) JAXBException(jakarta.xml.bind.JAXBException) JAXBContext(jakarta.xml.bind.JAXBContext) MissingDescriptorListener(org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) DBWSException(org.eclipse.persistence.exceptions.DBWSException) Collection(java.util.Collection) PLSQLCollection(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCollection) XmlBindingsModel(org.eclipse.persistence.internal.xr.XmlBindingsModel)

Example 5 with SimpleXMLFormatProject

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

the class BaseDBWSBuilderHelper method handleSimpleXMLFormat.

/**
 * Apply SimpleXMLFormat if 'isSimpleXMLFormat' is true.  The SimpleXMLFormat is
 * configured based on the given ProcedureOperationModel's simpleXMLFormatTag
 * and xmlTag (if set) and set on the given Result.  A descriptor is also added
 * to the OXProject if none exists.
 */
protected void handleSimpleXMLFormat(boolean isSimpleXMLFormat, Result result, ProcedureOperationModel procedureOperationModel) {
    if (isSimpleXMLFormat || result.getType() == Util.SXF_QNAME) {
        SimpleXMLFormat sxf = new SimpleXMLFormat();
        String simpleXMLFormatTag = procedureOperationModel.getSimpleXMLFormatTag();
        if (simpleXMLFormatTag != null && simpleXMLFormatTag.length() > 0) {
            sxf.setSimpleXMLFormatTag(simpleXMLFormatTag);
        }
        String xmlTag = procedureOperationModel.getXmlTag();
        if (xmlTag != null && xmlTag.length() > 0) {
            sxf.setXMLTag(xmlTag);
        }
        result.setSimpleXMLFormat(sxf);
        // check to see if the O-X project needs descriptor for SimpleXMLFormat
        if (dbwsBuilder.getOxProject().getDescriptorForAlias(DEFAULT_SIMPLE_XML_FORMAT_TAG) == null) {
            SimpleXMLFormatProject sxfProject = new SimpleXMLFormatProject();
            dbwsBuilder.getOxProject().addDescriptor(sxfProject.buildXRRowSetModelDescriptor());
        }
    }
}
Also used : SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) SimpleXMLFormat(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormat) Util.addSimpleXMLFormat(org.eclipse.persistence.tools.dbws.Util.addSimpleXMLFormat) Util.requiresSimpleXMLFormat(org.eclipse.persistence.tools.dbws.Util.requiresSimpleXMLFormat)

Aggregations

SimpleXMLFormatProject (org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject)5 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)3 Project (org.eclipse.persistence.sessions.Project)3 DBWSModelProject (org.eclipse.persistence.dbws.DBWSModelProject)2 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)2 SimpleXMLFormat (org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormat)2 XMLContext (org.eclipse.persistence.oxm.XMLContext)2 Util.addSimpleXMLFormat (org.eclipse.persistence.tools.dbws.Util.addSimpleXMLFormat)2 Util.requiresSimpleXMLFormat (org.eclipse.persistence.tools.dbws.Util.requiresSimpleXMLFormat)2 JAXBContext (jakarta.xml.bind.JAXBContext)1 JAXBException (jakarta.xml.bind.JAXBException)1 Marshaller (jakarta.xml.bind.Marshaller)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)1 DBWSException (org.eclipse.persistence.exceptions.DBWSException)1 XMLEntityMappings (org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings)1 MissingDescriptorListener (org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener)1