Search in sources :

Example 1 with ElementStyle

use of org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method addToOROXProjectsForBuildSql.

protected void addToOROXProjectsForBuildSql(ModelWithBuildSql modelWithBuildSql, Project orProject, Project oxProject, NamingConventionTransformer nct) {
    List<DbColumn> columns = buildDbColumns(dbwsBuilder.getConnection(), modelWithBuildSql.getBuildSql());
    String schemaAlias = modelWithBuildSql.getReturnType();
    String tableName = schemaAlias;
    NamingConventionTransformer customNct = setUpCustomTransformer(tableName, nct);
    RelationalDescriptor desc = buildORDescriptor(tableName, dbwsBuilder.getProjectName(), null, customNct);
    createdORDescriptors.put(desc.getJavaClassName(), desc);
    desc.descriptorIsAggregate();
    orProject.addDescriptor(desc);
    XMLDescriptor xdesc = buildOXDescriptor(desc.getAlias(), schemaAlias, desc.getJavaClassName(), dbwsBuilder.getTargetNamespace());
    oxProject.addDescriptor(xdesc);
    List<String> columnsAlreadyProcessed = new ArrayList<String>();
    for (DbColumn dbColumn : columns) {
        String columnName = dbColumn.getFieldName();
        if (!columnsAlreadyProcessed.contains(columnName)) {
            columnsAlreadyProcessed.add(columnName);
            ElementStyle style = nct.styleForElement(columnName);
            if (style == NONE) {
                continue;
            }
            dbwsBuilder.logMessage(FINE, "Building mappings for " + 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);
        } else {
            dbwsBuilder.logMessage(SEVERE, "Duplicate ResultSet columns not supported '" + columnName + "'");
            throw new RuntimeException("Duplicate ResultSet columns not supported");
        }
    }
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) DbColumn(org.eclipse.persistence.tools.dbws.jdbc.DbColumn) ArrayList(java.util.ArrayList) ElementStyle(org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Example 2 with ElementStyle

use of org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle 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 3 with ElementStyle

use of org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method setUpXMLDirectMapping.

protected XMLDirectMapping setUpXMLDirectMapping(String columnName, QName qName, NamingConventionTransformer nct, Class<?> attributeClass, int jdbcType, boolean isPk) {
    XMLDirectMapping xdm = null;
    // figure out if binary attachments are required
    boolean binaryAttach = false;
    String attachmentType = null;
    if (BASE_64_BINARY_QNAME.equals(qName)) {
        // use primitive byte[] array, not object Byte[] array
        attributeClass = APBYTE;
        for (OperationModel om : dbwsBuilder.operations) {
            if (om.isTableOperation()) {
                TableOperationModel tom = (TableOperationModel) om;
                if (tom.getBinaryAttachment()) {
                    binaryAttach = true;
                    if (MTOM_STR.equalsIgnoreCase(tom.getAttachmentType())) {
                        attachmentType = MTOM_STR;
                    } else {
                        attachmentType = SWAREF_STR;
                    }
                    // only need one operation to require attachments
                    break;
                }
                if (tom.additionalOperations != null && tom.additionalOperations.size() > 0) {
                    for (OperationModel om2 : tom.additionalOperations) {
                        if (om2.isProcedureOperation()) {
                            ProcedureOperationModel pom = (ProcedureOperationModel) om2;
                            if (pom.getBinaryAttachment()) {
                                binaryAttach = true;
                                if (MTOM_STR.equalsIgnoreCase(tom.getAttachmentType())) {
                                    attachmentType = MTOM_STR;
                                } else {
                                    attachmentType = SWAREF_STR;
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
        XMLBinaryDataMapping xbdm = new XMLBinaryDataMapping();
        if (binaryAttach) {
            if (attachmentType.equals(SWAREF_STR)) {
                xbdm.setSwaRef(true);
                qName = XMLConstants.SWA_REF_QNAME;
            }
        } else {
            xbdm.setShouldInlineBinaryData(true);
        }
        xbdm.setMimeType(DEFAULT_ATTACHMENT_MIMETYPE);
        xdm = xbdm;
    } else {
        xdm = new XMLDirectMapping();
    }
    String fieldName = nct.generateElementAlias(columnName);
    xdm.setAttributeName(fieldName);
    xdm.setAttributeClassificationName(attributeClass.getName());
    String xPath = EMPTY_STRING;
    ElementStyle style = nct.styleForElement(columnName);
    if (style == ATTRIBUTE) {
        xPath += AT_SIGN + fieldName;
    } else if (style == ELEMENT) {
        xPath += fieldName;
    }
    if (style == ELEMENT && attributeClass != APBYTE) {
        xPath += SLASH_TEXT;
    }
    xdm.setXPath(xPath);
    XMLField xmlField = (XMLField) xdm.getField();
    xmlField.setSchemaType(qName);
    if (isPk) {
        xmlField.setRequired(true);
    } else {
        AbstractNullPolicy nullPolicy = xdm.getNullPolicy();
        nullPolicy.setNullRepresentedByEmptyNode(false);
        nullPolicy.setMarshalNullRepresentation(XSI_NIL);
        nullPolicy.setNullRepresentedByXsiNil(true);
        xdm.setNullPolicy(nullPolicy);
    }
    return xdm;
}
Also used : XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) XMLField(org.eclipse.persistence.oxm.XMLField) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ElementStyle(org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle)

Aggregations

XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)3 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)3 ElementStyle (org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle)3 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)2 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)2 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)2 ArrayList (java.util.ArrayList)1 DBWSModelProject (org.eclipse.persistence.dbws.DBWSModelProject)1 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)1 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)1 SimpleXMLFormatProject (org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject)1 XMLField (org.eclipse.persistence.oxm.XMLField)1 AbstractNullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy)1 Project (org.eclipse.persistence.sessions.Project)1 DbColumn (org.eclipse.persistence.tools.dbws.jdbc.DbColumn)1 FieldType (org.eclipse.persistence.tools.oracleddl.metadata.FieldType)1 ObjectTableType (org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType)1 TableType (org.eclipse.persistence.tools.oracleddl.metadata.TableType)1