use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class JUnitTestCase method supportsStoredFunctions.
public static boolean supportsStoredFunctions(String puName) {
DatabasePlatform platform = getDatabaseSession(puName).getPlatform();
// TODO: DB2 should be in this list.
if (platform.isOracle() || platform.isMySQL()) {
return true;
}
warning("This database does not support stored function creation.");
return false;
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform 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;
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class BatchCommitTransactionExceptionTest method test.
@Override
public void test() {
Session session = getSession();
DatabasePlatform plat = session.getPlatform();
// test to fail on MYSQL. Tracking bug 335724
if (plat.isOracle() || plat.isSQLServer() || plat.isSybase() || plat.isSQLAnywhere() || plat.isMySQL() || plat.isSymfoware()) {
DatabaseLogin login = session.getLogin();
login.useBatchWriting();
try {
((DatabaseSession) session).beginTransaction();
session.executeNonSelectingCall(new org.eclipse.persistence.queries.SQLCall("Insert into BOB Value"));
((DatabaseSession) session).commitTransaction();
} catch (org.eclipse.persistence.exceptions.EclipseLinkException e) {
this.caughtException = e;
((DatabaseSession) session).rollbackTransaction();
}
} else {
throw new TestWarningException("Test not run on this database platform");
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class SessionsFactory method processStructConverterConfig.
/**
* INTERNAL:
*/
@SuppressWarnings({ "unchecked" })
protected void processStructConverterConfig(StructConverterConfig converterClassConfig, DatabaseLogin login) {
if (converterClassConfig != null) {
Platform platform = login.getDatasourcePlatform();
if (platform instanceof DatabasePlatform) {
Iterator<String> i = converterClassConfig.getStructConverterClasses().iterator();
while (i.hasNext()) {
String converterClassName = i.next();
try {
Class<StructConverter> converterClass = (Class<StructConverter>) m_classLoader.loadClass(converterClassName);
StructConverter converter = null;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
try {
converter = AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(converterClass));
} catch (PrivilegedActionException ex) {
throw (Exception) ex.getCause();
}
} else {
converter = PrivilegedAccessHelper.newInstanceFromClass(converterClass);
}
((DatabasePlatform) platform).addStructConverter(converter);
} catch (Exception exception) {
throw SessionLoaderException.failedToLoadTag("struct-converter", converterClassName, exception);
}
}
}
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class OwnershipSystem method createTables.
@Override
public void createTables(DatabaseSession session) {
// Drop old constraints.
DatabasePlatform platform = (DatabasePlatform) session.getDatasourcePlatform();
boolean supportsAlterTableConstraints = platform.supportsForeignKeyConstraints() || (platform.supportsUniqueColumns() && !platform.requiresUniqueConstraintCreationOnTableCreate());
if (supportsAlterTableConstraints)
try {
if (platform.isMySQL()) {
session.executeNonSelectingSQL("Alter TABLE OBJECT_A DROP FOREIGN KEY OWNER_A_ONE_TO_ONE_");
session.executeNonSelectingSQL("Alter TABLE OBJECT_C DROP FOREIGN KEY OWNER_C_ONE_TO_ONE_");
} else {
session.executeNonSelectingSQL("Alter TABLE OBJECT_A DROP CONSTRAINT OWNER_A_ONE_TO_ONE_");
session.executeNonSelectingSQL("Alter TABLE OBJECT_C DROP CONSTRAINT OWNER_C_ONE_TO_ONE_");
}
} catch (Exception ignore) {
}
SchemaManager schemaManager = new SchemaManager(session);
if (supportsAlterTableConstraints) {
schemaManager.dropConstraints(ObjectA.tableDefinition());
schemaManager.dropConstraints(ObjectB.tableDefinition());
schemaManager.dropConstraints(ObjectC.tableDefinition());
schemaManager.dropConstraints(ObjectD.tableDefinition());
schemaManager.dropConstraints(ObjectE.tableDefinition());
}
schemaManager.replaceObject(ObjectA.tableDefinition());
schemaManager.replaceObject(ObjectB.tableDefinition());
schemaManager.replaceObject(ObjectC.tableDefinition());
schemaManager.replaceObject(ObjectD.tableDefinition());
schemaManager.replaceObject(ObjectE.tableDefinition());
if (supportsAlterTableConstraints) {
schemaManager.createConstraints(ObjectA.tableDefinition());
schemaManager.createConstraints(ObjectB.tableDefinition());
schemaManager.createConstraints(ObjectC.tableDefinition());
schemaManager.createConstraints(ObjectD.tableDefinition());
schemaManager.createConstraints(ObjectE.tableDefinition());
}
schemaManager.createSequences();
}
Aggregations