use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class ExternalizedMetadataTestCases method createXmlContext.
/**
* Convenience method that returns a newly created XMLContext based on an array of classes.
*/
protected XMLContext createXmlContext(Class<?>[] classes) {
try {
ClassLoader classLoader = new JaxbClassLoader(Thread.currentThread().getContextClassLoader());
Generator generator = new Generator(new JavaModelInputImpl(classes, new JavaModelImpl(classLoader)));
CoreProject proj = generator.generateProject();
ConversionManager manager = new ConversionManager();
manager.setLoader(classLoader);
for (Iterator<ClassDescriptor> descriptorIt = proj.getOrderedDescriptors().iterator(); descriptorIt.hasNext(); ) {
ClassDescriptor descriptor = descriptorIt.next();
if (descriptor.getJavaClass() == null) {
descriptor.setJavaClass(manager.convertClassNameToClass(descriptor.getJavaClassName()));
}
}
return new XMLContext((Project) proj, classLoader);
} catch (Exception e) {
e.printStackTrace();
fail("XmlContext creation failed");
}
return null;
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class SQLAsCollectionTestSuite method buildSessions.
@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();
((DatabaseLogin) login).setUsesStreamsForBinding(true);
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;
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(parentClassLoader, properties);
oxProject = jCtx.getXMLContext().getSession(0).getProject();
} catch (JAXBException e) {
e.printStackTrace();
}
((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);
prepareDescriptors(oxProject, orProject, xrdecl);
ProjectHelper.fixOROXAccessors(orProject, oxProject);
xrService.setORSession(databaseSession);
xrService.setXMLContext(new XMLContext(oxProject));
xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class SecondarySQLTestSuite method buildSessions.
@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();
((DatabaseLogin) login).setUsesStreamsForBinding(true);
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;
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(parentClassLoader, properties);
oxProject = jCtx.getXMLContext().getSession(0).getProject();
} catch (JAXBException e) {
e.printStackTrace();
}
((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);
prepareDescriptors(oxProject, orProject, xrdecl);
ProjectHelper.fixOROXAccessors(orProject, oxProject);
xrService.setORSession(databaseSession);
xrService.setXMLContext(new XMLContext(oxProject));
xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
use of org.eclipse.persistence.internal.helper.ConversionManager 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);
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class HistoryPolicy method additionalHistoryExpression.
/**
* INTERNAL:
* Add any temporal querying conditions to this object expression.
* @param tableIndex not null indicates that only expression for a single table should be returned.
*/
public Expression additionalHistoryExpression(Expression context, Expression base, Integer tableIndex) {
//
AsOfClause clause = base.getAsOfClause();
Object value = clause.getValue();
Expression join = null;
Expression subJoin = null;
Expression start = null;
Expression end = null;
if (value == null) {
return null;
// for now nothing as assume mirroring historical tables.
} else {
if (value instanceof Expression) {
// Print AS OF TIMESTAMP (SYSDATE - 1000*60*10) not AS OF ('SYSDATE - 1000*60*10').
if ((value instanceof ConstantExpression) && (((ConstantExpression) value).getValue() instanceof String)) {
value = (((ConstantExpression) value).getValue());
}
} else {
ConversionManager converter = ConversionManager.getDefaultManager();
value = converter.convertObject(value, ClassConstants.TIMESTAMP);
}
if (getMapping() != null) {
if (tableIndex != null && tableIndex > 0) {
return null;
}
TableExpression tableExp = null;
DatabaseTable historicalTable = getHistoricalTables().get(0);
tableExp = (TableExpression) ((ObjectExpression) base).existingDerivedTable(historicalTable);
start = tableExp.getField(getStart());
end = tableExp.getField(getEnd());
join = start.lessThanEqual(value).and(end.isNull().or(end.greaterThan(value)));
// We also need to do step two here in advance.
tableExp.setTable(historicalTable);
return join;
}
int iFirst, iLast;
if (tableIndex == null) {
// loop through all history tables
iFirst = 0;
iLast = getHistoricalTables().size() - 1;
} else {
// only return expression for the specified table
iFirst = tableIndex;
iLast = iFirst;
}
for (int i = iFirst; i <= iLast; i++) {
start = base.getField(getStart(i));
end = base.getField(getEnd(i));
subJoin = start.lessThanEqual(value).and(end.isNull().or(end.greaterThan(value)));
join = ((join == null) ? subJoin : join.and(subJoin));
}
return join;
}
}
Aggregations