Search in sources :

Example 16 with ConversionManager

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);
}
Also used : Oracle10Platform(org.eclipse.persistence.platform.database.oracle.Oracle10Platform) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Oracle10Platform(org.eclipse.persistence.platform.database.oracle.Oracle10Platform) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) Project(org.eclipse.persistence.sessions.Project) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) StringReader(java.io.StringReader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) NonSynchronizedVector(org.eclipse.persistence.internal.helper.NonSynchronizedVector) Test(org.junit.Test)

Example 17 with ConversionManager

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();
        }
    }
}
Also used : DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) DBWSModel(org.eclipse.persistence.dbws.DBWSModel) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform) XMLContext(org.eclipse.persistence.oxm.XMLContext) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) EclipseLinkObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject) Project(org.eclipse.persistence.sessions.Project) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) XRServiceFactory(org.eclipse.persistence.internal.xr.XRServiceFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) XRServiceModel(org.eclipse.persistence.internal.xr.XRServiceModel) StringReader(java.io.StringReader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) EclipseLinkObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform) BeforeClass(org.junit.BeforeClass)

Example 18 with ConversionManager

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;
}
Also used : DefaultSessionLog(org.eclipse.persistence.logging.DefaultSessionLog) SessionLog(org.eclipse.persistence.logging.SessionLog) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedActionException(java.security.PrivilegedActionException) SessionLoaderException(org.eclipse.persistence.exceptions.SessionLoaderException)

Example 19 with ConversionManager

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);
}
Also used : CacheId(org.eclipse.persistence.internal.identitymaps.CacheId) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager)

Example 20 with ConversionManager

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);
}
Also used : CacheId(org.eclipse.persistence.internal.identitymaps.CacheId) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager)

Aggregations

ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)32 Project (org.eclipse.persistence.sessions.Project)12 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)11 XMLContext (org.eclipse.persistence.oxm.XMLContext)11 JAXBException (jakarta.xml.bind.JAXBException)10 StringReader (java.io.StringReader)10 XRDynamicClassLoader (org.eclipse.persistence.internal.xr.XRDynamicClassLoader)10 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)10 JAXBContext (jakarta.xml.bind.JAXBContext)9 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)9 XMLPlatform (org.eclipse.persistence.platform.xml.XMLPlatform)9 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)9 DatasourceLogin (org.eclipse.persistence.sessions.DatasourceLogin)9 Unmarshaller (jakarta.xml.bind.Unmarshaller)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 StreamSource (javax.xml.transform.stream.StreamSource)8 CacheId (org.eclipse.persistence.internal.identitymaps.CacheId)8 MetadataProcessor (org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor)8 DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)8