Search in sources :

Example 16 with QueryRunner

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

the class TransactionTest method setUp.

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

Example 17 with QueryRunner

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

the class TestListener method onAfterUpdate.

@Override
public void onAfterUpdate(Server entity, Connection connection) {
    events.add("onAfterUpdate: " + entity.getId());
    Set<String> dirtyFields = persistence.getTools().getDirtyFields(entity);
    System.out.println(dirtyFields);
    // Using EntityManager is prohibited as it may lead to unpredicted results
    // EntityManager em = persistence.getEntityManager();
    // Query q = em.createQuery("select max(s.createTs) from sys$Server s");
    // Date maxDate = (Date) q.getSingleResult();
    // System.out.println(maxDate);
    // JPA update queries don't work: reentrant flush error
    // Query q = em.createQuery("update sys$Server s set s.name = :name where s.id = :id");
    // Query q = em.createNativeQuery("update SYS_SERVER set NAME = ?1 where ID = ?2");
    // q.setParameter(1, "some other");
    // q.setParameter(2, entity.getId());
    // q.executeUpdate();
    QueryRunner runner = new QueryRunner();
    try {
        runner.update(persistence.getEntityManager().getConnection(), "update SYS_SERVER set NAME = ? where ID = ?", new Object[] { "some other", persistence.getDbTypeConverter().getSqlObject(entity.getId()) });
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) QueryRunner(com.haulmont.bali.db.QueryRunner)

Example 18 with QueryRunner

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

the class CompositeKeyTest method setUp.

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

Example 19 with QueryRunner

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

the class IntIdentityTest method setUp.

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

Example 20 with QueryRunner

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

the class QueryResultsManager method deleteForCurrentSession.

@Override
public void deleteForCurrentSession() {
    QueryRunner runner = new QueryRunner(persistence.getDataSource());
    try {
        DbTypeConverter converter = persistence.getDbTypeConverter();
        UUID userSessionId = userSessionSource.getUserSession().getId();
        String userSessionIdStr = converter.getSqlObject(userSessionId).toString();
        runner.update("delete from SYS_QUERY_RESULT where SESSION_ID = '" + userSessionIdStr + "'");
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) QueryRunner(com.haulmont.bali.db.QueryRunner) DbTypeConverter(com.haulmont.cuba.core.sys.persistence.DbTypeConverter)

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