Search in sources :

Example 36 with QueryRunner

use of com.haulmont.bali.db.QueryRunner in project cuba by cuba-platform.

the class ViewTest method getCurrentUpdateTs.

private long getCurrentUpdateTs() {
    String sql = "select UPDATE_TS from SEC_USER where ID = '" + userId.toString() + "'";
    QueryRunner runner = new QueryRunner(cont.persistence().getDataSource());
    try {
        return runner.query(sql, new ResultSetHandler<Long>() {

            @Override
            public Long handle(ResultSet rs) throws SQLException {
                rs.next();
                return rs.getTimestamp("UPDATE_TS").getTime();
            }
        });
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) QueryRunner(com.haulmont.bali.db.QueryRunner)

Example 37 with QueryRunner

use of com.haulmont.bali.db.QueryRunner in project cuba by cuba-platform.

the class TestContainer method deleteRecord.

public void deleteRecord(String table, String primaryKeyCol, Object... ids) {
    for (Object id : ids) {
        String sql = "delete from " + table + " where " + primaryKeyCol + " = '" + id.toString() + "'";
        QueryRunner runner = new QueryRunner(persistence().getDataSource());
        try {
            runner.update(sql);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) QueryRunner(com.haulmont.bali.db.QueryRunner)

Example 38 with QueryRunner

use of com.haulmont.bali.db.QueryRunner in project cuba by cuba-platform.

the class TestAfterCompleteTxListener method testRollback.

private void testRollback(boolean committed, Collection<Entity> detachedEntities) {
    assertFalse(committed);
    User user = null;
    for (Entity entity : detachedEntities) {
        if (entity instanceof User && ((User) entity).getLogin().startsWith("TxLstnrTst-1-"))
            user = (User) entity;
    }
    if (user != null) {
        assertEquals("updated by testRollback", user.getName());
        try {
            QueryRunner runner = new QueryRunner(persistence.getDataSource());
            runner.update("update SEC_USER set NAME = 'updated by TestAfterCompleteTxListener' where ID = ?", user.getId().toString());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) User(com.haulmont.cuba.security.entity.User) SQLException(java.sql.SQLException) QueryRunner(com.haulmont.bali.db.QueryRunner)

Aggregations

QueryRunner (com.haulmont.bali.db.QueryRunner)38 SQLException (java.sql.SQLException)14 Before (org.junit.Before)10 DbTypeConverter (com.haulmont.cuba.core.sys.persistence.DbTypeConverter)6 User (com.haulmont.cuba.security.entity.User)4 EntityManager (com.haulmont.cuba.core.EntityManager)3 Transaction (com.haulmont.cuba.core.Transaction)3 After (org.junit.After)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 Entity (com.haulmont.cuba.core.entity.Entity)2 UserSession (com.haulmont.cuba.security.global.UserSession)2 IOException (java.io.IOException)2 ResultSet (java.sql.ResultSet)2 ArrayHandler (com.haulmont.bali.db.ArrayHandler)1 ResultSetHandler (com.haulmont.bali.db.ResultSetHandler)1 EntitySnapshot (com.haulmont.cuba.core.entity.EntitySnapshot)1 Server (com.haulmont.cuba.core.entity.Server)1 View (com.haulmont.cuba.core.global.View)1 EntityListenerManager (com.haulmont.cuba.core.sys.listener.EntityListenerManager)1 Group (com.haulmont.cuba.security.entity.Group)1