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");
}
}
}
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);
}
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;
}
Aggregations