1 package org.openslx.imagemaster.db;
3 import java.sql.Connection;
4 import java.sql.SQLException;
5 import java.util.ArrayList;
8 import org.apache.logging.log4j.LogManager;
9 import org.apache.logging.log4j.Logger;
33 if ( !sql.startsWith(
"SELECT" ) && !sql.startsWith(
"DESCRIBE" ) && !sql.startsWith(
"SHOW" ) ) {
34 hasPendingQueries =
true;
37 openStatements.add( statement );
41 public void commit() throws SQLException
43 rawConnection.commit();
44 hasPendingQueries =
false;
49 rawConnection.rollback();
50 hasPendingQueries =
false;
55 return System.currentTimeMillis() <
deadline;
61 if ( hasPendingQueries ) {
62 LOGGER.warn(
"Mysql connection had uncommited queries on .close()",
63 new RuntimeException(
"Stack trace" ) );
65 LOGGER.info( s.getQuery() );
67 hasPendingQueries =
false;
70 rawConnection.rollback();
71 }
catch ( SQLException e ) {
72 LOGGER.warn(
"Rolling back uncommited queries failed!", e );
74 if ( !openStatements.isEmpty() ) {
78 openStatements.clear();
81 rawConnection.rollback();
82 rawConnection.setAutoCommit(
true );
83 }
catch ( SQLException e ) {
84 LOGGER.warn(
"Rolling back uncommited queries failed!", e );
92 rawConnection.close();
93 }
catch ( SQLException e ) {
100 rawConnection.setAutoCommit( b );
MysqlConnection(Connection rawConnection)
final Connection rawConnection
boolean hasPendingQueries
static final Logger LOGGER
static void returnConnection(MysqlConnection connection)
Called by a MysqlConnection when its close()-method is called, so the connection will be added to the...
Class for creating PreparedStatements with named parameters.
MysqlStatement prepareStatement(String sql)
void setAutoCommit(boolean b)
static final int CONNECTION_TIMEOUT_MS
List< MysqlStatement > openStatements