Search in sources :

Example 96 with Savepoint

use of java.sql.Savepoint in project adempiere by adempiere.

the class Migrate method dropClient.

/**
	 * remove client entries from all tables
	 *
	 * @param clientID
	 *            client to remove
	 */
private boolean dropClient(int clientID) {
    boolean result = false;
    // Do not drop system client AD-Client_ID=0
    if (clientID == s_parameters.SYSTEMCLIENTID)
        return result;
    // list of none-AD tables in which system client data is to be preserved
    // (for example C_UOM, C_Region)
    // use UPPERCASE table tames
    ArrayList<String> tablesToPreserve = new ArrayList<String>();
    Collections.addAll(tablesToPreserve, "C_UOM", "C_UOM_CONVERSION", "C_REGION");
    String clientName = m_target.getSystemClients().get(clientID);
    s_logger.log(Level.FINE, "dropClient", new Object[] { m_objectType, clientName, m_direction });
    // iterate through all tables
    Savepoint sp = m_target.setSavepoint(clientName);
    Vector<String> v = new Vector<String>(m_targetMap.keySet());
    java.util.Collections.sort(v);
    for (Iterator<String> it = v.iterator(); it.hasNext(); ) {
        String key = it.next();
        DBObject obj = m_targetMap.get(key);
        // but only use those where an AD_Client_ID field exists.
        HashMap<Integer, DBObjectDefinition> columns = obj.getContents();
        for (Iterator<Integer> it2 = columns.keySet().iterator(); it2.hasNext(); ) {
            int key2 = it2.next();
            DBObject_Table_Column col = (DBObject_Table_Column) columns.get(key2);
            if (col.getName().equalsIgnoreCase("AD_Client_ID")) {
                String vendor = m_target.getVendor();
                String catalog = m_target.getCatalog();
                String schema = m_target.getSchema();
                String table = col.getTable();
                String whereClause = new StringBuffer("AD_Client_ID = ").append(clientID).toString();
                Statement stmt = m_target.setStatement();
                String sqlCommand = s_dbEngine.sql_deleteByCondition(vendor, catalog, schema, table, whereClause);
                Integer sqlResult = m_target.executeUpdate(stmt, sqlCommand, false, false);
                if (sqlResult != null) {
                    logDropDetail(sqlResult, null);
                    result = true;
                }
                m_target.releaseStatement(stmt);
            }
        }
    }
    m_target.releaseSavepoint(sp);
    return result;
}
Also used : Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Savepoint(java.sql.Savepoint) Savepoint(java.sql.Savepoint) Vector(java.util.Vector)

Example 97 with Savepoint

use of java.sql.Savepoint in project adempiere by adempiere.

the class DBObject method update.

/**
	 * update this object
	 * @param sourceObj the object to use as template
	 * @return whether or not the object was successfully updated
	 */
public boolean update(DBObject sourceObj) {
    s_logger.log(Level.FINE, "updateThisObject", new Object[] { getObjectType(), m_name, m_parent.getDirection() });
    // remember savepoint for rollback
    Savepoint sp = m_parent.setSavepoint("update object");
    // update the object
    boolean result = m_interface.updateObject(s_parameters, s_logger, s_dbEngine, m_parent, m_name, m_headers, m_contents, sourceObj);
    // release savepoint
    m_parent.releaseSavepoint(sp);
    return result;
}
Also used : Savepoint(java.sql.Savepoint)

Example 98 with Savepoint

use of java.sql.Savepoint in project adempiere by adempiere.

the class DBObject method create.

/** 
	 * create this object
	 * @param db database in which to create this object
	 * @return whether or not the object was successfully created 
	 */
public boolean create(DBConnection db) {
    s_logger.log(Level.FINE, "createThisObject", new Object[] { getObjectType(), m_name, db.getDirection() });
    // remember savepoint for rollback
    Savepoint sp = db.setSavepoint("create object");
    // create the object
    boolean result = m_interface.createObject(s_parameters, s_logger, s_dbEngine, db, m_name, m_headers, m_contents);
    // release savepoint
    db.releaseSavepoint(sp);
    return result;
}
Also used : Savepoint(java.sql.Savepoint)

Example 99 with Savepoint

use of java.sql.Savepoint in project spanner-jdbc by olavloite.

the class AbstractCloudSpannerConnectionTest method testRollback.

@Test
public void testRollback() throws Exception {
    thrown.expect(SQLFeatureNotSupportedException.class);
    AbstractCloudSpannerConnection testSubject;
    Savepoint savepoint = null;
    // default test
    testSubject = createTestSubject();
    testSubject.rollback(savepoint);
}
Also used : Savepoint(java.sql.Savepoint) Test(org.junit.Test)

Example 100 with Savepoint

use of java.sql.Savepoint in project derby by apache.

the class VerifySignatures method collectClassesFromConnection.

/**
 * Perform JDBC operations on a <code>Connection</code>. Collect
 * the classes of all JDBC objects that are found.
 *
 * @param conn connection to a database
 * @param classes set into which classes are collected
 * @exception SQLException if a database error occurs
 */
private static void collectClassesFromConnection(Connection conn, Set<ClassInfo> classes) throws SQLException {
    conn.setAutoCommit(false);
    addClass(classes, conn.getClass(), java.sql.Connection.class);
    Savepoint sp = conn.setSavepoint();
    addClass(classes, sp.getClass(), java.sql.Savepoint.class);
    conn.releaseSavepoint(sp);
    DatabaseMetaData dmd = conn.getMetaData();
    addClass(classes, dmd.getClass(), java.sql.DatabaseMetaData.class);
    collectClassesFromStatement(conn, classes);
    collectClassesFromPreparedStatement(conn, classes);
    collectClassesFromCallableStatement(conn, classes);
    conn.rollback();
    conn.close();
}
Also used : Savepoint(java.sql.Savepoint) DatabaseMetaData(java.sql.DatabaseMetaData)

Aggregations

Savepoint (java.sql.Savepoint)167 Statement (java.sql.Statement)61 Connection (java.sql.Connection)56 SQLException (java.sql.SQLException)55 PreparedStatement (java.sql.PreparedStatement)32 Test (org.junit.Test)31 ResultSet (java.sql.ResultSet)26 DatabaseMetaData (java.sql.DatabaseMetaData)13 UnitTest (nl.topicus.jdbc.test.category.UnitTest)13 TransactionStatus (org.springframework.transaction.TransactionStatus)12 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)12 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)12 ArrayList (java.util.ArrayList)11 Vector (java.util.Vector)11 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 SQLClientInfoException (java.sql.SQLClientInfoException)7 HashMap (java.util.HashMap)5 ConcurrencyFailureException (org.springframework.dao.ConcurrencyFailureException)5 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)4