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