Skip to content

Commit

Permalink
MID-5103 fixed statement closing for manual doWork calls, caused too …
Browse files Browse the repository at this point in the history
…many open coursors error with oracle
  • Loading branch information
1azyman committed Jan 25, 2019
1 parent bc740d7 commit 73933c9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Expand Up @@ -93,7 +93,7 @@ public Session beginTransaction(boolean readOnly) {

if (getConfiguration().getTransactionIsolation() == TransactionIsolation.SNAPSHOT) {
LOGGER.trace("Setting transaction isolation level SNAPSHOT.");
session.doWork(connection -> connection.createStatement().execute("SET TRANSACTION ISOLATION LEVEL SNAPSHOT"));
session.doWork(connection -> RUtil.executeStatement(connection,"SET TRANSACTION ISOLATION LEVEL SNAPSHOT"));
}

if (readOnly) {
Expand All @@ -102,7 +102,7 @@ public Session beginTransaction(boolean readOnly) {
session.setHibernateFlushMode(FlushMode.MANUAL);

LOGGER.trace("Marking transaction as read only.");
session.doWork(connection -> connection.createStatement().execute("SET TRANSACTION READ ONLY"));
session.doWork(connection -> RUtil.executeStatement(connection, "SET TRANSACTION READ ONLY"));
}
return session;
}
Expand Down
Expand Up @@ -19,11 +19,11 @@
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ReferenceDelta;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration;
import com.evolveum.midpoint.repo.sql.data.common.ROrgClosure;
import com.evolveum.midpoint.repo.sql.data.common.other.RObjectType;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
Expand Down Expand Up @@ -953,7 +953,7 @@ private String computeDeltaTable(List<Edge> edges, Context context, Session sess
"PRIMARY KEY (descendant_oid, ancestor_oid))";
// NativeQuery createTableQuery = session.createNativeQuery(createTableSql);
// createTableQuery.executeUpdate(); <--- this does not work because the temporary table gets deleted when the command terminates (preparedStatement issue - maybe something like this: https://support.microsoft.com/en-us/kb/280134 ?)
session.doWork(connection -> connection.createStatement().execute(createTableSql));
session.doWork(connection -> RUtil.executeStatement(connection, createTableSql));
LOGGER.trace("Empty delta table created in {} ms", System.currentTimeMillis() - start);

NativeQuery insertQuery = session.createNativeQuery("insert into " + deltaTempTableName + " " + selectClause);
Expand Down
Expand Up @@ -65,6 +65,9 @@
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
Expand Down Expand Up @@ -564,4 +567,16 @@ public static String fixDBSchemaObjectNameLength(String input) {

return result;
}

public static void executeStatement(Connection connection, String sql) throws SQLException {
Statement stmt = null;
try {
stmt = connection.createStatement();
stmt.execute(sql);
} finally {
if (stmt != null && !stmt.isClosed()) {
stmt.close();
}
}
}
}

0 comments on commit 73933c9

Please sign in to comment.