Search in sources :

Example 41 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)

Example 42 with QueryRunner

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

the class TestEntityChangedEventListener method isCommitted.

private boolean isCommitted(Id<Order, UUID> entityId) {
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<Boolean> future = executor.submit(() -> {
        QueryRunner runner = new QueryRunner(persistence.getDataSource());
        try {
            Object[] row = runner.query("select id from SALES1_ORDER where id = ?", entityId.getValue().toString(), new ArrayHandler());
            return row != null;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    });
    try {
        return future.get(200L, TimeUnit.MILLISECONDS);
    } catch (InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    } catch (TimeoutException e) {
        return false;
    }
}
Also used : SQLException(java.sql.SQLException) QueryRunner(com.haulmont.bali.db.QueryRunner) ArrayHandler(com.haulmont.bali.db.ArrayHandler)

Example 43 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(String.format("Unable to delete record %s from %s", id.toString(), table), e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) QueryRunner(com.haulmont.bali.db.QueryRunner)

Example 44 with QueryRunner

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

the class IdentityUuidTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    QueryRunner runner = new QueryRunner(cont.persistence().getDataSource());
    runner.update("delete from TEST_IDENTITY_UUID");
    metadata = cont.metadata();
    persistence = cont.persistence();
}
Also used : QueryRunner(com.haulmont.bali.db.QueryRunner) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 45 with QueryRunner

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

the class IdentityTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    QueryRunner runner = new QueryRunner(cont.persistence().getDataSource());
    runner.update("delete from TEST_IDENTITY");
    metadata = cont.metadata();
    persistence = cont.persistence();
}
Also used : QueryRunner(com.haulmont.bali.db.QueryRunner) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

QueryRunner (com.haulmont.bali.db.QueryRunner)45 SQLException (java.sql.SQLException)17 BeforeEach (org.junit.jupiter.api.BeforeEach)13 DbTypeConverter (com.haulmont.cuba.core.sys.persistence.DbTypeConverter)6 User (com.haulmont.cuba.security.entity.User)5 AfterEach (org.junit.jupiter.api.AfterEach)4 ArrayHandler (com.haulmont.bali.db.ArrayHandler)3 EntityManager (com.haulmont.cuba.core.EntityManager)3 Transaction (com.haulmont.cuba.core.Transaction)3 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 Entity (com.haulmont.cuba.core.entity.Entity)2 Stores.storeNameToString (com.haulmont.cuba.core.global.Stores.storeNameToString)2 View (com.haulmont.cuba.core.global.View)2 PersistenceImpl (com.haulmont.cuba.core.sys.PersistenceImpl)2 Group (com.haulmont.cuba.security.entity.Group)2 UserSession (com.haulmont.cuba.security.global.UserSession)2 IOException (java.io.IOException)2 ResultSet (java.sql.ResultSet)2 Gson (com.google.gson.Gson)1