Search in sources :

Example 6 with MySQLPlatform

use of org.eclipse.persistence.platform.database.MySQLPlatform 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 7 with MySQLPlatform

use of org.eclipse.persistence.platform.database.MySQLPlatform in project eclipselink by eclipse-ee4j.

the class RelationshipsTestSuite 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(RELATIONSHIPS_SCHEMA.getBytes());
            return super.buildService(xrServiceModel);
        }

        @Override
        public void buildSessions() {
            XMLContext context = new XMLContext(new EclipseLinkObjectPersistenceRuntimeXMLProject());
            XMLUnmarshaller unmarshaller = context.createUnmarshaller();
            Project orProject = (Project) unmarshaller.unmarshal(new StringReader(RELATIONSHIPS_OR_PROJECT));
            DatabaseLogin login = new DatabaseLogin();
            login.setUserName(username);
            login.setPassword(password);
            login.setConnectionString(url);
            login.setDriverClassName(driver);
            Platform platform = new MySQLPlatform();
            login.setDatasourcePlatform(platform);
            login.bindAllParameters();
            orProject.setDatasourceLogin(login);
            Project oxProject = (Project) unmarshaller.unmarshal(new StringReader(RELATIONSHIPS_OX_PROJECT));
            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(RELATIONSHIPS_DBWS));
    xrService = factory.buildService(model);
    if (ddlCreate) {
        try {
            AllTests.runDdl(CREATE_DDL, ddlDebug);
        } catch (Exception e) {
        // e.printStackTrace();
        }
    }
}
Also used : DBWSModel(org.eclipse.persistence.dbws.DBWSModel) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform) XMLContext(org.eclipse.persistence.oxm.XMLContext) 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) 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 8 with MySQLPlatform

use of org.eclipse.persistence.platform.database.MySQLPlatform in project eclipselink by eclipse-ee4j.

the class TestPropertiesUtils method testInvalidConfiguration.

@Test
public void testInvalidConfiguration() {
    MySQLPlatform db = new MySQLPlatform();
    try {
        PropertiesUtils.set(db, "eclipselink.target-database", "ShouldForceFieldNamesToUpperCase");
        Assert.fail();
    } catch (ConversionException ce) {
    // expected
    }
    try {
        PropertiesUtils.set(db, "eclipselink.target-database", "==");
        Assert.fail();
    } catch (ConversionException ce) {
    // expected
    }
    try {
        PropertiesUtils.set(db, "eclipselink.target-database", "");
    } catch (ConversionException ce) {
        Assert.fail();
    }
    try {
        PropertiesUtils.set(db, "eclipselink.target-database", ",,ShouldForceFieldNamesToUpperCase=true");
        Assert.fail();
    } catch (ConversionException ce) {
    // expected
    }
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform) Test(org.junit.Test)

Aggregations

MySQLPlatform (org.eclipse.persistence.platform.database.MySQLPlatform)8 Test (org.junit.Test)5 StringReader (java.io.StringReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DBWSModel (org.eclipse.persistence.dbws.DBWSModel)2 DBWSModelProject (org.eclipse.persistence.dbws.DBWSModelProject)2 ConversionException (org.eclipse.persistence.exceptions.ConversionException)2 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)2 EclipseLinkObjectPersistenceRuntimeXMLProject (org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject)2 Invocation (org.eclipse.persistence.internal.xr.Invocation)2 Operation (org.eclipse.persistence.internal.xr.Operation)2 XRServiceFactory (org.eclipse.persistence.internal.xr.XRServiceFactory)2 XRServiceModel (org.eclipse.persistence.internal.xr.XRServiceModel)2 XMLContext (org.eclipse.persistence.oxm.XMLContext)2 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)2 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)2 XMLPlatform (org.eclipse.persistence.platform.xml.XMLPlatform)2 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)2 Project (org.eclipse.persistence.sessions.Project)2 BeforeClass (org.junit.BeforeClass)2