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");
}
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);
}
}
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();
}
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();
}
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);
}
}
Aggregations