Search in sources :

Example 1 with MySQLPlatform

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

the class SimpleSPTestSuite method noargsTest.

@Test
public void noargsTest() {
    Invocation invocation = new Invocation("NoArgsTest");
    Operation op = xrService.getOperation(invocation.getName());
    Object result = op.invoke(xrService, invocation);
    assertNotNull("result is null", result);
    Document doc = xmlPlatform.createDocument();
    XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
    marshaller.marshal(result, doc);
    Document controlDoc = xmlParser.parse(new StringReader(xrService.getORSession().getProject().getDatasourceLogin().getPlatform() instanceof MySQLPlatform ? VALUE_0_XML : VALUE_1_XML));
    assertTrue("control document not same as instance document", comparer.isNodeEqual(controlDoc, doc));
}
Also used : Invocation(org.eclipse.persistence.internal.xr.Invocation) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) StringReader(java.io.StringReader) Operation(org.eclipse.persistence.internal.xr.Operation) Document(org.w3c.dom.Document) MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform) Test(org.junit.Test)

Example 2 with MySQLPlatform

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

the class SimpleSPTestSuite method varcharTest.

@Test
public void varcharTest() {
    Invocation invocation = new Invocation("VarcharTest");
    invocation.setParameter("X", "this is a test");
    Operation op = xrService.getOperation(invocation.getName());
    Object result = op.invoke(xrService, invocation);
    assertNotNull("result is null", result);
    Document doc = xmlPlatform.createDocument();
    XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
    marshaller.marshal(result, doc);
    Document controlDoc = xmlParser.parse(new StringReader(xrService.getORSession().getProject().getDatasourceLogin().getPlatform() instanceof MySQLPlatform ? VALUE_0_XML : VALUE_1_XML));
    assertTrue("control document not same as instance document", comparer.isNodeEqual(controlDoc, doc));
}
Also used : Invocation(org.eclipse.persistence.internal.xr.Invocation) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) StringReader(java.io.StringReader) Operation(org.eclipse.persistence.internal.xr.Operation) Document(org.w3c.dom.Document) MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform) Test(org.junit.Test)

Example 3 with MySQLPlatform

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

the class JDBCHelper method loadProcedures.

protected List<ProcedureType> loadProcedures(String originalCatalogPattern, String originalSchemaPattern, String originalProcedurePattern) {
    List<ProcedureType> dbStoredProcedures = null;
    boolean catalogMatchDontCare = false;
    DatabasePlatform platform = dbwsBuilder.getDatabasePlatform();
    if (platform instanceof MySQLPlatform || platform instanceof DerbyPlatform || platform instanceof PostgreSQLPlatform) {
        // note that get info on other platforms that also require catalogMatchDontCare = true
        catalogMatchDontCare = true;
    }
    String catalogPattern = escapePunctuation(originalCatalogPattern);
    String schemaPattern = escapePunctuation(originalSchemaPattern);
    String procedurePattern = escapePunctuation(originalProcedurePattern);
    // Make sure procedure(s) is/are available
    ResultSet procsInfo = null;
    try {
        DatabaseMetaData databaseMetaData = getDatabaseMetaData(dbwsBuilder.getConnection());
        procsInfo = databaseMetaData.getProcedures(catalogPattern, schemaPattern, procedurePattern);
        // did we get a hit?
        if (procsInfo != null) {
            List<ProcedureType> tmpProcs = new ArrayList<ProcedureType>();
            while (procsInfo.next()) {
                String actualCatalogName = procsInfo.getString(PROCS_INFO_CATALOG);
                String actualSchemaName = procsInfo.getString(PROCS_INFO_SCHEMA);
                String actualProcedureName = procsInfo.getString(PROCS_INFO_NAME);
                short procedureType = procsInfo.getShort(PROCS_INFO_TYPE);
                ProcedureType dbStoredProcedure;
                if (procedureType == procedureReturnsResult) {
                    dbStoredProcedure = new FunctionType(actualProcedureName);
                } else {
                    dbStoredProcedure = new ProcedureType(actualProcedureName);
                }
                if (actualCatalogName != null && actualCatalogName.length() > 0) {
                    dbStoredProcedure.setCatalogName(actualCatalogName);
                }
                if (actualSchemaName != null && actualSchemaName.length() > 0) {
                    dbStoredProcedure.setSchema(actualSchemaName);
                }
                tmpProcs.add(dbStoredProcedure);
            }
            procsInfo.close();
            /* new a temp bucket to hold DbStoredArgs until they can be sorted out with respect
                 * to which DbStoredProcedure owns which args; this has to be done because Oracle can
                 * return multiple hits across multiple packages for the same procedureName.
                 */
            int numProcs = tmpProcs.size();
            if (numProcs > 0) {
                dbStoredProcedures = new ArrayList<ProcedureType>(numProcs);
                ResultSet procedureColumnsInfo = null;
                procedureColumnsInfo = databaseMetaData.getProcedureColumns(catalogPattern, schemaPattern, procedurePattern, "%");
                while (procedureColumnsInfo.next()) {
                    String actualCatalogName = procedureColumnsInfo.getString(PROC_COLS_INFO_CATALOG);
                    String actualSchemaName = procedureColumnsInfo.getString(PROC_COLS_INFO_SCHEMA);
                    String actualProcedureName = procedureColumnsInfo.getString(PROC_COLS_INFO_NAME);
                    String argName = procedureColumnsInfo.getString(PROC_COLS_INFO_COLNAME);
                    // some MySql drivers return empty string, some return null: set to emptyString regardless
                    if (argName == null) {
                        argName = "";
                    }
                    ArgumentType dbStoredArgument = new ArgumentType(argName);
                    short inOut = procedureColumnsInfo.getShort(PROC_COLS_INFO_TYPE);
                    if (inOut == procedureColumnInOut) {
                        dbStoredArgument.setDirection(INOUT);
                    } else if (inOut == procedureColumnOut) {
                        dbStoredArgument.setDirection(OUT);
                    } else if (inOut == procedureColumnReturn) {
                        dbStoredArgument.setDirection(RETURN);
                    } else {
                        // default to ArgumentTypeDirection.IN
                        dbStoredArgument.setDirection(IN);
                    }
                    int jdbcType = procedureColumnsInfo.getInt(PROC_COLS_INFO_DATA_TYPE);
                    int precision = procedureColumnsInfo.getInt(PROC_COLS_INFO_PRECISION);
                    int scale = procedureColumnsInfo.getInt(PROC_COLS_INFO_SCALE);
                    dbStoredArgument.setEnclosedType(buildTypeForJDBCType(jdbcType, precision, scale));
                    // find matching DbStoredProcedure
                    // this dbStoredArgument belongs to a 'regular' procedure
                    ProcedureType matchingProc = null;
                    for (int i = 0; i < tmpProcs.size(); ) {
                        ProcedureType tmpProc = tmpProcs.get(i);
                        if (matches(tmpProc, actualCatalogName, actualSchemaName, actualProcedureName, false, catalogMatchDontCare)) {
                            matchingProc = tmpProc;
                            dbStoredProcedures.add(matchingProc);
                            break;
                        }
                        i++;
                    }
                    if (matchingProc == null) {
                        // look in dbStoredProcedures - matching proc already moved over ?
                        for (ProcedureType dbStoredProcedure : dbStoredProcedures) {
                            if (matches(dbStoredProcedure, actualCatalogName, actualSchemaName, actualProcedureName, false, catalogMatchDontCare)) {
                                matchingProc = dbStoredProcedure;
                                break;
                            }
                        }
                    }
                    if (matchingProc != null) {
                        if (matchingProc.isFunctionType() && dbStoredArgument.getArgumentName().equalsIgnoreCase("")) {
                            ((FunctionType) matchingProc).setReturnArgument(dbStoredArgument);
                        } else {
                            matchingProc.getArguments().add(dbStoredArgument);
                        }
                        tmpProcs.remove(matchingProc);
                    }
                // else some argument that doesn't have a matching proc? ignore for now
                }
                procedureColumnsInfo.close();
                if (!tmpProcs.isEmpty()) {
                    // leftovers are the no-arg procedures
                    dbStoredProcedures.addAll(tmpProcs);
                }
            }
        }
    } catch (SQLException sqlException) {
        throw new IllegalStateException("failure retrieving Stored Procedure metadata", sqlException);
    }
    if (dbStoredProcedures != null && !dbStoredProcedures.isEmpty()) {
        Collections.sort(dbStoredProcedures, new Comparator<ProcedureType>() {

            @Override
            public int compare(ProcedureType o1, ProcedureType o2) {
                String name1 = o1.getProcedureName();
                String name2 = o2.getProcedureName();
                if (!name1.equals(name2)) {
                    return name1.compareTo(name2);
                } else {
                    return o1.getOverload() - o2.getOverload();
                }
            }
        });
    }
    return dbStoredProcedures;
}
Also used : PostgreSQLPlatform(org.eclipse.persistence.platform.database.PostgreSQLPlatform) ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) SQLException(java.sql.SQLException) FunctionType(org.eclipse.persistence.tools.oracleddl.metadata.FunctionType) ArrayList(java.util.ArrayList) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString) DatabaseMetaData(java.sql.DatabaseMetaData) ArgumentType(org.eclipse.persistence.tools.oracleddl.metadata.ArgumentType) DerbyPlatform(org.eclipse.persistence.platform.database.DerbyPlatform) ResultSet(java.sql.ResultSet) MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform)

Example 4 with MySQLPlatform

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

the class TestPropertiesUtils method testSetInToDatabasePlatform.

@Test
public void testSetInToDatabasePlatform() {
    MySQLPlatform db = new MySQLPlatform();
    Assert.assertFalse(db.shouldForceFieldNamesToUpperCase());
    Assert.assertTrue(db.shouldBindLiterals());
    PropertiesUtils.set(db, "eclipselink.target-database", "ShouldForceFieldNamesToUpperCase=true, shouldbindliterals = false");
    Assert.assertTrue(db.shouldForceFieldNamesToUpperCase());
    Assert.assertFalse(db.shouldBindLiterals());
}
Also used : MySQLPlatform(org.eclipse.persistence.platform.database.MySQLPlatform) Test(org.junit.Test)

Example 5 with MySQLPlatform

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

the class TestPropertiesUtils method testInvalidPropertyType.

@Test
public void testInvalidPropertyType() {
    // StringBindingSize is a property, but it is a number
    String config = "StringBindingSize=one";
    MySQLPlatform db = new MySQLPlatform();
    try {
        PropertiesUtils.set(db, "eclipselink.target-database", config);
        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