use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class PLSQLcollectionTestSuite method fromProjectXML.
@Test
public void fromProjectXML() {
XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(PLSQLcollectionTestSuite.class.getClassLoader());
Project projectFromXML = XMLProjectReader.read(new StringReader(TEST_PROJECT_CONTROL_DOC), xrdecl);
DatabaseLogin login = new DatabaseLogin();
login.setUserName(username);
login.setPassword(password);
login.setConnectionString(url);
login.setDriverClassName("oracle.jdbc.OracleDriver");
Platform platform = new Oracle10Platform();
ConversionManager cm = platform.getConversionManager();
cm.setLoader(xrdecl);
login.setDatasourcePlatform(platform);
login.bindAllParameters();
projectFromXML.setDatasourceLogin(login);
ProjectHelper.fixOROXAccessors(projectFromXML, null);
xrdecl.dontGenerateSubclasses();
ClassDescriptor t1Descriptor = projectFromXML.getDescriptorForAlias("T1");
DatabaseQuery query = t1Descriptor.getQueryManager().getQuery(QUERY_NAME);
assertTrue(QUERY_NAME + " is wrong type of query: " + query.getClass().getSimpleName(), query.isDataModifyQuery());
session = projectFromXML.createDatabaseSession();
session.dontLogMessages();
t1Descriptor = session.getDescriptorForAlias("T1");
Class<?> t1Clz = t1Descriptor.getJavaClass();
((DatabaseSession) session).login();
String[] elements = { "first string", "second string", "third string" };
NonSynchronizedVector<Object> queryArgs = new NonSynchronizedVector<>();
queryArgs.add(elements);
queryArgs.add("barf");
boolean worked = false;
String msg = null;
try {
session.executeQuery(QUERY_NAME, t1Clz, queryArgs);
worked = true;
} catch (Exception e) {
msg = e.getMessage();
}
assertTrue("invocation somePackage.p1 failed: " + msg, worked);
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class KeyMappingsTestSuite method setUp.
@BeforeClass
public static void setUp() {
final String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
if ("true".equalsIgnoreCase(ddlCreateProp)) {
ddlCreate = true;
}
final String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
if ("true".equalsIgnoreCase(ddlDropProp)) {
ddlDrop = true;
}
final String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
if ("true".equalsIgnoreCase(ddlDebugProp)) {
ddlDebug = true;
}
final String username = System.getProperty(DATABASE_USERNAME_KEY);
if (username == null) {
fail("error retrieving database username");
}
final String password = System.getProperty(DATABASE_PASSWORD_KEY);
if (password == null) {
fail("error retrieving database password");
}
final String url = System.getProperty(DATABASE_URL_KEY);
if (url == null) {
fail("error retrieving database url");
}
final String driver = System.getProperty(DATABASE_DRIVER_KEY);
if (driver == null) {
fail("error retrieving database driver");
}
XRServiceFactory factory = new XRServiceFactory() {
@Override
public XRServiceAdapter buildService(XRServiceModel xrServiceModel) {
parentClassLoader = this.getClass().getClassLoader();
xrSchemaStream = new ByteArrayInputStream(KEYMAPPINGS_SCHEMA.getBytes());
return super.buildService(xrServiceModel);
}
@Override
public void buildSessions() {
XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
XMLContext context = new XMLContext(new EclipseLinkObjectPersistenceRuntimeXMLProject(), xrdecl);
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
Project orProject = (Project) unmarshaller.unmarshal(new StringReader(KEYMAPPINGS_OR_PROJECT));
DatasourceLogin login = new DatabaseLogin();
login.setUserName(username);
login.setPassword(password);
((DatabaseLogin) login).setConnectionString(url);
((DatabaseLogin) login).setDriverClassName(driver);
Platform platform = new MySQLPlatform();
ConversionManager conversionManager = platform.getConversionManager();
if (conversionManager != null) {
conversionManager.setLoader(xrdecl);
}
login.setDatasourcePlatform(platform);
((DatabaseLogin) login).bindAllParameters();
orProject.setDatasourceLogin(login);
Project oxProject = (Project) unmarshaller.unmarshal(new StringReader(KEYMAPPINGS_OX_PROJECT));
login = (DatasourceLogin) oxProject.getDatasourceLogin();
if (login != null) {
platform = login.getDatasourcePlatform();
if (platform != null) {
conversionManager = platform.getConversionManager();
if (conversionManager != null) {
conversionManager.setLoader(xrdecl);
}
}
}
ProjectHelper.fixOROXAccessors(orProject, oxProject);
xrService.setORSession(orProject.createDatabaseSession());
xrService.getORSession().dontLogMessages();
xrService.setXMLContext(new XMLContext(oxProject));
xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
};
XMLContext context = new XMLContext(new DBWSModelProject());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
DBWSModel model = (DBWSModel) unmarshaller.unmarshal(new StringReader(KEYMAPPINGS_DBWS));
xrService = factory.buildService(model);
if (ddlCreate) {
try {
AllTests.runDdl(CREATE_DDL, ddlDebug);
} catch (Exception e) {
// e.printStackTrace();
}
}
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class SessionsFactory method buildJavaLogConfig.
/**
* INTERNAL:
*/
@SuppressWarnings({ "unchecked" })
protected SessionLog buildJavaLogConfig(JavaLogConfig javaLogConfig, AbstractSession session) {
SessionLog javaLog = null;
try {
// use ConversionManager to avoid loading the JDK 1.4 class unless it is needed.
ConversionManager conversionManager = new ConversionManager();
conversionManager.setLoader(getClass().getClassLoader());
javaLog = ((Class<SessionLog>) conversionManager.convertObject("org.eclipse.persistence.logging.JavaLog", Class.class)).getConstructor().newInstance();
javaLog.setSession(session);
} catch (Exception exception) {
throw ValidationException.unableToLoadClass("org.eclipse.persistence.logging.JavaLog", exception);
}
// Process the common elements from LogConfig
processLogConfig(javaLogConfig, javaLog);
return javaLog;
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class RelationTableMechanism method extractBatchKeyFromRow.
/**
* INTERNAL:
* Extract the foreign key value from the source row.
*/
protected Object extractBatchKeyFromRow(AbstractRecord row, AbstractSession session) {
Object[] key;
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
List<DatabaseField> sourceKeyFields = this.sourceKeyFields;
int size = sourceKeyFields.size();
key = new Object[size];
for (int index = 0; index < size; index++) {
DatabaseField field = sourceKeyFields.get(index);
Object value = row.get(field);
// Must ensure the classification gets a cache hit.
key[index] = conversionManager.convertObject(value, field.getType());
}
return new CacheId(key);
}
use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.
the class RelationTableMechanism method extractKeyFromTargetRow.
/**
* INTERNAL:
* Extract the source primary key value from the relation row.
* Used for batch reading, most following same order and fields as in the mapping.
*/
protected Object extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) {
int size = getSourceRelationKeyFields().size();
Object[] key = new Object[size];
ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
for (int index = 0; index < size; index++) {
DatabaseField relationField = this.sourceRelationKeyFields.get(index);
DatabaseField sourceField = this.sourceKeyFields.get(index);
Object value = row.get(relationField);
// Must ensure the classification gets a cache hit.
value = conversionManager.convertObject(value, sourceField.getType());
key[index] = value;
}
return new CacheId(key);
}
Aggregations