Search in sources :

Example 6 with DatabasePlatform

use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.

the class OrderListTestModel method addModels.

/*
     * Loops through all possible model configurations and adds those for which shouldAddModel returns true.
     */
void addModels() {
    DatabasePlatform platform = getSession().getPlatform();
    changeTracking = ChangeTracking.ATTRIBUTE;
    orderCorrectionType = OrderCorrectionType.READ_WRITE;
    joinFetchOrBatchRead = JoinFetchOrBatchRead.NONE;
    useVarcharOrder = false;
    useSecondaryTable = false;
    isPrivatelyOwned = false;
    useIndirection = true;
    useListOrderField = true;
    shouldOverrideContainerPolicy = false;
    useVarcharOrder = true;
    addTestModel(platform);
    useVarcharOrder = false;
    useSecondaryTable = true;
    addTestModel(platform);
    useSecondaryTable = false;
    useIndirection = false;
    changeTracking = ChangeTracking.DEFERRED;
    addTestModel(platform);
    changeTracking = ChangeTracking.ATTRIBUTE;
    useIndirection = true;
    shouldOverrideContainerPolicy = true;
    addTestModel(platform);
    shouldOverrideContainerPolicy = false;
    for (int i = 0; i < ChangeTracking.values().length; i++) {
        changeTracking = ChangeTracking.values()[i];
        addTestModel(platform);
    }
    isPrivatelyOwned = true;
    for (int i = 0; i < ChangeTracking.values().length; i++) {
        changeTracking = ChangeTracking.values()[i];
        addTestModel(platform);
    }
    changeTracking = ChangeTracking.ATTRIBUTE;
    isPrivatelyOwned = false;
    for (int j = 0; j < OrderCorrectionType.values().length; j++) {
        orderCorrectionType = OrderCorrectionType.values()[j];
        addTestModel(platform);
    }
    orderCorrectionType = OrderCorrectionType.READ_WRITE;
    for (int k = 0; k < JoinFetchOrBatchRead.values().length; k++) {
        joinFetchOrBatchRead = JoinFetchOrBatchRead.values()[k];
        addTestModel(platform);
    }
    joinFetchOrBatchRead = JoinFetchOrBatchRead.NONE;
    useSecondaryTable = true;
    for (int k = 0; k < JoinFetchOrBatchRead.values().length; k++) {
        joinFetchOrBatchRead = JoinFetchOrBatchRead.values()[k];
        addTestModel(platform);
    }
    joinFetchOrBatchRead = JoinFetchOrBatchRead.NONE;
    useSecondaryTable = false;
/**
 * Un-comment to run 2^6 * 3 * 6 * 15 tests... (a lot...)
 *        do {
 *            do {
 *                do {
 *                    do {
 *                        do {
 *                            for(int i=0; i < ChangeTracking.values().length; i++) {
 *                                changeTracking = ChangeTracking.values()[i];
 *                                for(int j=0; j < OrderCorrectionType.values().length; j++) {
 *                                    orderCorrectionType = OrderCorrectionType.values()[j];
 *                                    do{
 *                                        for(int k=0; k < JoinFetchOrBatchRead.values().length; k++) {
 *                                            joinFetchOrBatchRead = JoinFetchOrBatchRead.values()[k];
 *                                            addTestModel(platform);
 *                                        }
 *                                        shouldOverrideContainerPolicy = !shouldOverrideContainerPolicy;
 *                                    } while(shouldOverrideContainerPolicy);
 *                                }
 *                            }
 *                            useVarcharOrder = !useVarcharOrder;
 *                        } while(useVarcharOrder);
 *                        useSecondaryTable = !useSecondaryTable;
 *                    } while(useSecondaryTable);
 *                    isPrivatelyOwned = !isPrivatelyOwned;
 *                } while(isPrivatelyOwned);
 *                useIndirection = !useIndirection;
 *            } while(useIndirection);
 *            useListOrderField = !useListOrderField;
 *        } while(useListOrderField);
 */
}
Also used : DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)

Example 7 with DatabasePlatform

use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.

the class ParameterBatchWritingFlushQueryTest method setup.

@Override
public void setup() {
    super.setup();
    DatabasePlatform platform = getSession().getPlatform();
    usesBindAllParameters = platform.shouldBindAllParameters();
    platform.setShouldBindAllParameters(true);
    platform.setUsesJDBCBatchWriting(true);
}
Also used : DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)

Example 8 with DatabasePlatform

use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.

the class ParameterBatchWritingFlushQueryTest method reset.

@Override
public void reset() {
    if (usesBindAllParameters != null) {
        DatabasePlatform platform = getSession().getPlatform();
        platform.setShouldBindAllParameters(usesBindAllParameters);
    }
    super.reset();
}
Also used : DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)

Example 9 with DatabasePlatform

use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.

the class SQLSelectStatement method appendFromClauseForOuterJoin.

/**
 * ADVANCED:
 * Appends the SQL standard outer join clause, and some variation per platform.
 * Most platforms use this syntax, support is also offered for Oracle to join in the where clause (although it should use the FROM clause as the WHERE clause is obsolete).
 * This is also used for inner joins when configured in the platform.
 */
public void appendFromClauseForOuterJoin(ExpressionSQLPrinter printer, List<DatabaseTable> outerJoinedAliases, Collection aliasesOfTablesToBeLocked, boolean shouldPrintUpdateClauseForAllTables) throws IOException {
    Writer writer = printer.getWriter();
    AbstractSession session = printer.getSession();
    DatabasePlatform platform = session.getPlatform();
    // Print outer joins
    boolean firstTable = true;
    // Checks if the JDBC closing escape syntax is needed.
    boolean requiresEscape = false;
    boolean usesHistory = (getBuilder() != null) && getBuilder().hasAsOfClause();
    int nSize = getOuterJoinExpressionsHolders().size();
    for (OuterJoinExpressionHolder holder : getOuterJoinExpressionsHolders()) {
        holder.process(usesHistory);
    }
    if (nSize > 1) {
        sortOuterJoinExpressionHolders(getOuterJoinExpressionsHolders());
    }
    for (OuterJoinExpressionHolder holder : outerJoinExpressionHolders) {
        ObjectExpression outerExpression = holder.joinExpression;
        boolean isOuterJoin = (outerExpression == null) || outerExpression.shouldUseOuterJoin();
        DatabaseTable targetTable = holder.targetTable;
        DatabaseTable sourceTable = holder.sourceTable;
        DatabaseTable sourceAlias = holder.sourceAlias;
        DatabaseTable targetAlias = holder.targetAlias;
        if (!outerJoinedAliases.contains(targetAlias)) {
            if (!outerJoinedAliases.contains(sourceAlias)) {
                if (requiresEscape && session.getPlatform().shouldUseJDBCOuterJoinSyntax()) {
                    writer.write("}");
                }
                if (!firstTable) {
                    writer.write(",");
                }
                if (platform.shouldUseJDBCOuterJoinSyntax()) {
                    writer.write(platform.getJDBCOuterJoinString());
                }
                requiresEscape = true;
                firstTable = false;
                sourceTable.printSQL(printer);
                outerJoinedAliases.add(sourceAlias);
                writer.write(" ");
                if (sourceAlias.isDecorated()) {
                    ((DecoratedDatabaseTable) sourceAlias).getAsOfClause().printSQL(printer);
                    writer.write(" ");
                }
                sourceAlias.printSQL(printer);
                printForUpdateClauseOnJoin(sourceAlias, printer, shouldPrintUpdateClauseForAllTables, aliasesOfTablesToBeLocked, platform);
            }
            if (outerExpression == null) {
                holder.printAdditionalJoins(printer, outerJoinedAliases, aliasesOfTablesToBeLocked, shouldPrintUpdateClauseForAllTables);
            } else {
                DatabaseTable relationTable = outerExpression.getRelationTable();
                boolean hasAdditionalJoinExpressions = holder.hasAdditionalJoinExpressions();
                boolean isMapKeyObject = holder.hasMapKeyHolder();
                Expression additionalOnExpression = outerExpression.getOnClause();
                if (relationTable == null) {
                    if (outerExpression.isDirectCollection()) {
                        // Append the join clause,
                        // If this is a direct collection, join to direct table.
                        Expression onExpression = holder.outerJoinedMappingCriteria;
                        DatabaseTable newAlias = onExpression.aliasForTable(targetTable);
                        if (isOuterJoin) {
                            writer.write(" LEFT OUTER JOIN ");
                        } else {
                            writer.write(" JOIN ");
                        }
                        targetTable.printSQL(printer);
                        writer.write(" ");
                        if (newAlias.isDecorated()) {
                            ((DecoratedDatabaseTable) newAlias).getAsOfClause().printSQL(printer);
                            writer.write(" ");
                        }
                        outerJoinedAliases.add(newAlias);
                        newAlias.printSQL(printer);
                        printForUpdateClauseOnJoin(newAlias, printer, shouldPrintUpdateClauseForAllTables, aliasesOfTablesToBeLocked, platform);
                        printOnClause(onExpression.and(additionalOnExpression), printer, platform);
                    } else {
                        // the rest of the tables are joined with the additional join criteria.
                        if (isOuterJoin) {
                            writer.write(" LEFT OUTER JOIN ");
                        } else {
                            writer.write(" JOIN ");
                        }
                        if (hasAdditionalJoinExpressions && platform.supportsNestingOuterJoins()) {
                            writer.write("(");
                        }
                        targetTable.printSQL(printer);
                        writer.write(" ");
                        if (targetAlias.isDecorated()) {
                            ((DecoratedDatabaseTable) targetAlias).getAsOfClause().printSQL(printer);
                            writer.write(" ");
                        }
                        outerJoinedAliases.add(targetAlias);
                        targetAlias.printSQL(printer);
                        printForUpdateClauseOnJoin(targetAlias, printer, shouldPrintUpdateClauseForAllTables, aliasesOfTablesToBeLocked, platform);
                        if (hasAdditionalJoinExpressions && platform.supportsNestingOuterJoins()) {
                            holder.printAdditionalJoins(printer, outerJoinedAliases, aliasesOfTablesToBeLocked, shouldPrintUpdateClauseForAllTables);
                            writer.write(")");
                        }
                        Expression sourceToTargetJoin = holder.outerJoinedMappingCriteria;
                        if (additionalOnExpression != null) {
                            if (sourceToTargetJoin == null) {
                                sourceToTargetJoin = additionalOnExpression;
                            } else {
                                sourceToTargetJoin = sourceToTargetJoin.and(additionalOnExpression);
                            }
                        }
                        printOnClause(sourceToTargetJoin, printer, platform);
                        if (hasAdditionalJoinExpressions && !platform.supportsNestingOuterJoins()) {
                            holder.printAdditionalJoins(printer, outerJoinedAliases, aliasesOfTablesToBeLocked, shouldPrintUpdateClauseForAllTables);
                        }
                    }
                } else {
                    // Bug#4240751 Treat ManyToManyMapping separately for out join
                    // Must outer join each of the targets tables.
                    // The first table is joined with the mapping join criteria,
                    // the rest of the tables are joined with the additional join criteria.
                    // For example: EMPLOYEE t1 LEFT OUTER JOIN (PROJ_EMP t3 LEFT OUTER JOIN PROJECT t0 ON (t0.PROJ_ID = t3.PROJ_ID)) ON (t3.EMP_ID = t1.EMP_ID)
                    // Now OneToOneMapping also may have relation table.
                    DatabaseTable relationAlias = holder.outerJoinedMappingCriteria.aliasForTable(relationTable);
                    DatabaseTable mapKeyAlias = null;
                    DatabaseTable mapKeyTable = null;
                    List<DatabaseTable> tablesInOrder = new ArrayList<>();
                    // glassfish issue 2440: store aliases instead of tables
                    // in the tablesInOrder. This allows to distinguish source
                    // and target table in case of an self referencing relationship.
                    tablesInOrder.add(sourceAlias);
                    tablesInOrder.add(relationAlias);
                    tablesInOrder.add(targetAlias);
                    if (isMapKeyObject) {
                        // Need to also join the map key key.
                        mapKeyAlias = holder.mapKeyHolder.targetAlias;
                        mapKeyTable = holder.mapKeyHolder.targetTable;
                        tablesInOrder.add(mapKeyAlias);
                    }
                    TreeMap indexToExpressionMap = new TreeMap();
                    mapTableIndexToExpression(holder.outerJoinedMappingCriteria, indexToExpressionMap, tablesInOrder);
                    Expression sourceToRelationJoin = (Expression) indexToExpressionMap.get(1);
                    Expression relationToTargetJoin = (Expression) indexToExpressionMap.get(2);
                    Expression relationToKeyJoin = null;
                    if (isMapKeyObject) {
                        relationToKeyJoin = (Expression) indexToExpressionMap.get(3);
                    }
                    if (outerExpression.shouldUseOuterJoin()) {
                        writer.write(" LEFT OUTER JOIN ");
                    } else {
                        writer.write(" JOIN ");
                    }
                    if (platform.supportsNestingOuterJoins()) {
                        writer.write("(");
                    }
                    relationTable.printSQL(printer);
                    writer.write(" ");
                    if (relationAlias.isDecorated()) {
                        ((DecoratedDatabaseTable) relationAlias).getAsOfClause().printSQL(printer);
                        writer.write(" ");
                    }
                    outerJoinedAliases.add(relationAlias);
                    relationAlias.printSQL(printer);
                    printForUpdateClauseOnJoin(relationAlias, printer, shouldPrintUpdateClauseForAllTables, aliasesOfTablesToBeLocked, platform);
                    if (!platform.supportsNestingOuterJoins()) {
                        printOnClause(sourceToRelationJoin.and(additionalOnExpression), printer, platform);
                    }
                    if (isMapKeyObject) {
                        // Append join to map key.
                        if (isOuterJoin && !session.getPlatform().supportsANSIInnerJoinSyntax()) {
                            writer.write(" LEFT OUTER");
                        }
                        writer.write(" JOIN ");
                        mapKeyTable.printSQL(printer);
                        writer.write(" ");
                        if (mapKeyAlias.isDecorated()) {
                            ((DecoratedDatabaseTable) mapKeyAlias).getAsOfClause().printSQL(printer);
                            writer.write(" ");
                        }
                        outerJoinedAliases.add(mapKeyAlias);
                        mapKeyAlias.printSQL(printer);
                        printForUpdateClauseOnJoin(mapKeyAlias, printer, shouldPrintUpdateClauseForAllTables, aliasesOfTablesToBeLocked, platform);
                        printOnClause(relationToKeyJoin.and(additionalOnExpression), printer, platform);
                        if (holder.mapKeyHolder.hasAdditionalJoinExpressions()) {
                            holder.mapKeyHolder.printAdditionalJoins(printer, outerJoinedAliases, aliasesOfTablesToBeLocked, shouldPrintUpdateClauseForAllTables);
                        }
                    }
                    if (isOuterJoin && !session.getPlatform().supportsANSIInnerJoinSyntax()) {
                        // if the DB does not support 'JOIN', do a left outer
                        // join instead. This will give the same result because
                        // the left table is a join table and has therefore
                        // no rows that are not in the right table.
                        writer.write(" LEFT OUTER");
                    }
                    writer.write(" JOIN ");
                    targetTable.printSQL(printer);
                    writer.write(" ");
                    if (targetAlias.isDecorated()) {
                        ((DecoratedDatabaseTable) targetAlias).getAsOfClause().printSQL(printer);
                        writer.write(" ");
                    }
                    outerJoinedAliases.add(targetAlias);
                    targetAlias.printSQL(printer);
                    printForUpdateClauseOnJoin(targetAlias, printer, shouldPrintUpdateClauseForAllTables, aliasesOfTablesToBeLocked, platform);
                    printOnClause(relationToTargetJoin, printer, platform);
                    if (hasAdditionalJoinExpressions) {
                        holder.printAdditionalJoins(printer, outerJoinedAliases, aliasesOfTablesToBeLocked, shouldPrintUpdateClauseForAllTables);
                    }
                    if (platform.supportsNestingOuterJoins()) {
                        writer.write(")");
                        printOnClause(sourceToRelationJoin, printer, platform);
                    }
                }
            }
        }
    }
    if (requiresEscape && session.getPlatform().shouldUseJDBCOuterJoinSyntax()) {
        writer.write("}");
    }
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) ArrayList(java.util.ArrayList) DecoratedDatabaseTable(org.eclipse.persistence.internal.history.DecoratedDatabaseTable) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform) TreeMap(java.util.TreeMap) CharArrayWriter(java.io.CharArrayWriter) Writer(java.io.Writer) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 10 with DatabasePlatform

use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.

the class NativeBatchWritingTestModel method reset.

@Override
public void reset() {
    DatabasePlatform platform = getSession().getPlatform();
    if (platform.isOracle()) {
        platform.setUsesBatchWriting(false);
        platform.setUsesJDBCBatchWriting(true);
        platform.setShouldBindAllParameters(this.usesBinding);
        platform.setShouldCacheAllStatements(false);
        platform.setUsesNativeBatchWriting(false);
    }
}
Also used : DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)

Aggregations

DatabasePlatform (org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)52 EntityManager (jakarta.persistence.EntityManager)12 DatabaseCall (org.eclipse.persistence.internal.databaseaccess.DatabaseCall)11 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)9 EntityManagerFactoryImpl (org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl)9 Test (org.junit.Test)9 GenericEntity (org.eclipse.persistence.jpa.test.property.model.GenericEntity)8 PersistenceException (jakarta.persistence.PersistenceException)6 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)6 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)6 ResultSetMetaData (java.sql.ResultSetMetaData)5 DatabaseAccessor (org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor)5 FieldTypeDefinition (org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition)5 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)5 IOException (java.io.IOException)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Vector (java.util.Vector)4