Savepointの設定を遅延して行う

@param connection コネクション
@throws SQLException SQL例外
328765
private void initSavepoints(final Connection connection) {
		for (String savepointName : savepointNames) {
			try {
				savepointMap.put(savepointName, connection.setSavepoint(savepointName));
			} catch (SQLException e) {
				throw new UroborosqlSQLException(e);
			}
		}
	}
978207
public function rollbackSavepoint($savepoint)
    {
        if (! $this->getDatabasePlatform()->supportsSavepoints()) {
            throw ConnectionException::savepointsNotSupported();
        }

        $this->getWrappedConnection()->exec($this->platform->rollbackSavePoint($savepoint));
    }
188989
public static void registerSpatialTables(Connection connection) throws SQLException {
        Statement st = connection.createStatement();
        st.execute("drop view if exists geometry_columns");
        st.execute("create view geometry_columns as select TABLE_CATALOG f_table_catalog,TABLE_SCHEMA f_table_schema,TABLE_NAME f_table_name," +
                "COLUMN_NAME f_geometry_column,1 storage_type,_GeometryTypeFromConstraint(CHECK_CONSTRAINT || REMARKS, NUMERIC_PRECISION) geometry_type," +
                "_DimensionFromConstraint(TABLE_CATALOG,TABLE_SCHEMA, TABLE_NAME,COLUMN_NAME,CHECK_CONSTRAINT) coord_dimension," +
                "_ColumnSRID(TABLE_CATALOG,TABLE_SCHEMA, TABLE_NAME,COLUMN_NAME,CHECK_CONSTRAINT) srid," +
                " _GeometryTypeNameFromConstraint(CHECK_CONSTRAINT || REMARKS, NUMERIC_PRECISION) type" +
                " from INFORMATION_SCHEMA.COLUMNS WHERE TYPE_NAME = 'GEOMETRY'");
        ResultSet rs = connection.getMetaData().getTables("","PUBLIC","SPATIAL_REF_SYS",null);
        if(!rs.next()) {
        	InputStreamReader reader = new InputStreamReader(
					H2GISFunctions.class.getResourceAsStream("spatial_ref_sys.sql"));
			RunScript.execute(connection, reader);
				
			try {
				reader.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
        }
    }
485493
public void connectClient(Connection connection) {
    threadContext.checkThread();

    // Note we do not use method references here because the "state" variable changes over time.
    // We have to use lambdas to ensure the request handler points to the current state.
    connection.handler(RegisterRequest.class, (Function<RegisterRequest, CompletableFuture<RegisterResponse>>) request -> state.register(request));
    connection.handler(ConnectRequest.class, (Function<ConnectRequest, CompletableFuture<ConnectResponse>>) request -> state.connect(request, connection));
    connection.handler(KeepAliveRequest.class, (Function<KeepAliveRequest, CompletableFuture<KeepAliveResponse>>) request -> state.keepAlive(request));
    connection.handler(UnregisterRequest.class, (Function<UnregisterRequest, CompletableFuture<UnregisterResponse>>) request -> state.unregister(request));
    connection.handler(ResetRequest.class, (Consumer<ResetRequest>) request -> state.reset(request));
    connection.handler(CommandRequest.class, (Function<CommandRequest, CompletableFuture<CommandResponse>>) request -> state.command(request));
    connection.handler(QueryRequest.class, (Function<QueryRequest, CompletableFuture<QueryResponse>>) request -> state.query(request));

    connection.onClose(stateMachine.executor().context().sessions()::unregisterConnection);
  }
1326523
private void doExecute(Connection conn) throws SQLException
    {
        PreparedStatement stmt;
        int size;

        size = _methods.size();
        if ( size == 0 )
        {
            return;
        }
        stmt = conn.prepareStatement(_sql);
        try
        {
            m_platform.afterStatementCreate(stmt);
        }
        catch ( PlatformException e )
        {
            if ( e.getCause() instanceof SQLException )
            {
                throw (SQLException)e.getCause();
            }
            else
            {
                throw new SQLException(e.getMessage());
            }
        }
        try
        {
            m_platform.beforeBatch(stmt);
        }
        catch ( PlatformException e )
        {
            if ( e.getCause() instanceof SQLException )
            {
                throw (SQLException)e.getCause();
            }
            else
            {
                throw new SQLException(e.getMessage());
            }
        }
        try
        {
            for ( int i = 0; i < size; i++ )
            {
                Method method = (Method) _methods.get(i);
                try
                {
                    if ( method.equals(ADD_BATCH) )
                    {
                        /**
                         * we invoke on the platform and pass the stmt as an arg.
                         */
                        m_platform.addBatch(stmt);
                    }
                    else
                    {
                        method.invoke(stmt, (Object[]) _params.get(i));
                    }
                }
                catch (IllegalArgumentException ex)
                {
					StringBuffer buffer = generateExceptionMessage(i, stmt, ex);
					throw new SQLException(buffer.toString());
                }
                catch ( IllegalAccessException ex )
                {
					StringBuffer buffer = generateExceptionMessage(i, stmt, ex);
                    throw new SQLException(buffer.toString());
                }
                catch ( InvocationTargetException ex )
                {
                    Throwable th = ex.getTargetException();

                    if ( th == null )
                    {
                        th = ex;
                    }
                    if ( th instanceof SQLException )
                    {
                        throw ((SQLException) th);
                    }
                    else
                    {
                        throw new SQLException(th.toString());
                    }
                }
				catch (PlatformException e)
				{
					throw new SQLException(e.toString());
				}
            }
            try
            {
                /**
                 * this will call the platform specific call
                 */
                m_platform.executeBatch(stmt);
            }
            catch ( PlatformException e )
            {
                if ( e.getCause() instanceof SQLException )
                {
                    throw (SQLException)e.getCause();
                }
                else
                {
                    throw new SQLException(e.getMessage());
                }
            }

        }
        finally
        {
            stmt.close();
            _methods.clear();
            _params.clear();
        }
    }
379201
void rollback(final String savepointName) {
		if (connection != null) {
			try {
				connection.rollback(savepointMap.get(savepointName));
			} catch (SQLException e) {
				throw new UroborosqlSQLException(e);
			}
		}
	}
491700
protected void commitLocalConnection(Connection connection) {
    try {
      if (connection != null ) {
        connection.commit();
      }
    } catch (SQLException e) {
      if (logger.isTraceEnabled()) {
        logger.trace(e.getMessage());
      }
    }
  }
1146921
ThrowableInformation getException(Connection connection, long id)
      throws SQLException {

    PreparedStatement statement = null;

    try {
      statement = connection.prepareStatement(sqlException);
      statement.setLong(1, id);
      ResultSet rs = statement.executeQuery();

      Vector v = new Vector();

      while (rs.next()) {
        //int i = rs.getShort(1);
        v.add(rs.getString(1));
      }

      int len = v.size();
      String[] strRep = new String[len];
      for (int i = 0; i < len; i++) {
        strRep[i] = (String) v.get(i);
      }
      // we've filled strRep, we now attach it to the event
      return new ThrowableInformation(strRep);
    } finally {
      if (statement != null) {
        statement.close();
      }
    }
  }
135423
Connection getConnection() throws SQLException {
		if (connection == null) {
			connection = connectionSupplier.getConnection();
			initSavepoints(connection);
		}
		return connection;
	}
374555
public static void load(Connection connection) throws SQLException {
        Statement st = connection.createStatement();
        for (Function function : getBuiltInsFunctions()) {
            try {
                H2GISFunctions.registerFunction(st, function, "");
            } catch (SQLException ex) {
                // Catch to register other functions
                LOGGER.error(ex.getLocalizedMessage(), ex);
            }
        }
    }
1117152
public static void close(@Nullable Connection con) throws SQLException {
		if (con != null && !con.isClosed()) {
			if (!con.getAutoCommit()) {
				con.rollback();
				con.setAutoCommit(true);
			}
			con.close();
		}
	}
750538
public static void commitAndClose(Connection conn) throws SQLException {
        if (conn != null) {
            try {
                conn.commit();
            } finally {
                conn.close();
            }
        }
    }
405839
private void setSchemaOnConnection(Connection connection) throws SQLException {
		logger.finest("Entering " + CLASSNAME +".setSchemaOnConnection()");

		String dbProductName = connection.getMetaData().getDatabaseProductName();
		if (!"Oracle".equals(dbProductName) && !"Microsoft SQL Server".equals(dbProductName)) {
			PreparedStatement ps = null;
			if ("MySQL".equals(dbProductName)) {
				ps = connection.prepareStatement("USE " + schema);
			} else {
				ps = connection.prepareStatement("SET SCHEMA ?");
				ps.setString(1, schema);
			}
			ps.executeUpdate(); 
			ps.close();
		}

		logger.finest("Exiting " + CLASSNAME +".setSchemaOnConnection()");
	}
57641
@Override
    public synchronized void savepoint(String name) {

        int index = sessionContext.savepoints.getIndex(name);

        if (index != -1) {
            sessionContext.savepoints.remove(name);
            sessionContext.savepointTimestamps.remove(index);
        }

        sessionContext.savepoints.add(name,
                                      ValuePool.getInt(rowActionList.size()));
        sessionContext.savepointTimestamps.addLast(actionTimestamp);

        try {
            database.logger.writeToLog(this, getSavepointSQL(name));
        } catch (HsqlException e) {}
    }
208328
void releaseSavepoint(final String savepointName) {
		Savepoint savepoint = savepointMap.get(savepointName);

		int pos = savepointNames.lastIndexOf(savepointName);
		if (pos > -1) {
			List<String> subList = savepointNames.subList(pos, savepointNames.size());
			for (String name : subList) {
				savepointMap.remove(name);
			}
			subList.clear();
		}

		if (savepoint != null && connection != null) {
			try {
				connection.releaseSavepoint(savepoint);
			} catch (SQLException e) {
				throw new UroborosqlSQLException(e);
			}
		}
	}
536479
public void process(Connection connection, String directory) throws Exception
   {
      connection.setAutoCommit(true);

      //
      // Retrieve meta data about the connection
      //
      DatabaseMetaData dmd = connection.getMetaData();

      String[] types =
      {
         "TABLE"
      };

      FileWriter fw = new FileWriter(directory);
      PrintWriter pw = new PrintWriter(fw);

      pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
      pw.println();
      pw.println("<database>");

      ResultSet tables = dmd.getTables(null, null, null, types);
      while (tables.next() == true)
      {
         processTable(pw, connection, tables.getString("TABLE_NAME"));
      }

      pw.println("</database>");

      pw.close();

      tables.close();
   }
420054
private function saveMigration(Connection $connection, string $class): void
    {
        $format = $connection->getSchemaManager()->getDatabasePlatform()->getDateTimeFormatString();
        $now    = (new DateTimeImmutable())->format($format);
        $connection->insert(static::MIGRATIONS_TABLE, [
            static::MIGRATIONS_COLUMN_CLASS       => $class,
            static::MIGRATIONS_COLUMN_MIGRATED_AT => $now,
        ]);
    }