Search in sources :

Example 31 with QueryRunner

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

the class DataManagerTest method setUp.

@Before
public void setUp() throws Exception {
    dataManager = AppBeans.get(DataManager.class);
    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 32 with QueryRunner

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

the class DynamicAttributesTest method tearDown.

@After
public void tearDown() throws Exception {
    QueryRunner runner = new QueryRunner(cont.persistence().getDataSource());
    runner.update("delete from SYS_ATTR_VALUE");
    cont.deleteRecord(userRole, role, user, user2, group, group2);
    cont.deleteRecord(userAttribute, userRoleAttribute, userGroupAttribute, userGroupCollectionAttribute, userIntCollectionAttribute);
    cont.deleteRecord(userCategory, userRoleCategory);
}
Also used : QueryRunner(com.haulmont.bali.db.QueryRunner)

Example 33 with QueryRunner

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

the class NonEntityQueryTest method setUp.

@Before
public void setUp() throws Exception {
    dataManager = AppBeans.get(DataManager.class);
    passwordEncryption = AppBeans.get(PasswordEncryption.class);
    QueryRunner runner = new QueryRunner(cont.persistence().getDataSource());
    runner.update("delete from SYS_SERVER");
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        UserSessionSource uss = AppBeans.get(UserSessionSource.class);
        UserSession userSession = uss.getUserSession();
        Server server = new Server();
        server.setName("someServer");
        server.setRunning(false);
        serverId = server.getId();
        em.persist(server);
        EntitySnapshot entitySnapshot = cont.metadata().create(EntitySnapshot.class);
        entitySnapshot.setSnapshotDate(new Date());
        entitySnapshot.setAuthor(userSession.getCurrentOrSubstitutedUser());
        entitySnapshotId = entitySnapshot.getId();
        em.persist(entitySnapshot);
        Role role1 = new Role();
        role1Id = role1.getId();
        role1.setName("testRole1");
        em.persist(role1);
        Permission permission1 = new Permission();
        permission1Id = permission1.getId();
        permission1.setRole(role1);
        permission1.setType(PermissionType.ENTITY_ATTR);
        permission1.setTarget("sys$Server:name");
        permission1.setValue(0);
        em.persist(permission1);
        Permission permission2 = new Permission();
        permission2Id = permission2.getId();
        permission2.setRole(role1);
        permission2.setType(PermissionType.ENTITY_OP);
        permission2.setTarget("sys$EntitySnapshot:read");
        permission2.setValue(0);
        em.persist(permission2);
        Group group1 = new Group();
        group1Id = group1.getId();
        group1.setName("testGroup1");
        em.persist(group1);
        User user1 = new User();
        user1Id = user1.getId();
        user1.setName(USER_NAME_1);
        user1.setLogin(USER_NAME_1);
        user1.setPassword(passwordEncryption.getPasswordHash(user1Id, USER_PASSWORD));
        user1.setGroup(group1);
        em.persist(user1);
        UserRole userRole1 = new UserRole();
        userRole1Id = userRole1.getId();
        userRole1.setUser(user1);
        userRole1.setRole(role1);
        em.persist(userRole1);
        Group group2 = new Group();
        group2Id = group2.getId();
        group2.setName("testGroup2");
        em.persist(group2);
        Constraint constraint1 = new Constraint();
        constraint1Id = constraint1.getId();
        constraint1.setEntityName("sys$Server");
        constraint1.setWhereClause("{E}.running = true");
        constraint1.setGroup(group2);
        em.persist(constraint1);
        Constraint constraint2 = new Constraint();
        constraint2Id = constraint2.getId();
        constraint2.setEntityName("sys$EntitySnapshot");
        constraint2.setCheckType(ConstraintCheckType.MEMORY);
        constraint2.setGroovyScript("{E}.viewXml = 'xml'");
        constraint2.setGroup(group2);
        em.persist(constraint2);
        User user2 = new User();
        user2Id = user2.getId();
        user2.setName(USER_NAME_2);
        user2.setLogin(USER_NAME_2);
        user2.setPassword(passwordEncryption.getPasswordHash(user2Id, USER_PASSWORD));
        user2.setGroup(group2);
        em.persist(user2);
        tx.commit();
    } finally {
        tx.end();
    }
}
Also used : TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) Server(com.haulmont.cuba.core.entity.Server) QueryRunner(com.haulmont.bali.db.QueryRunner) Date(java.util.Date) EntitySnapshot(com.haulmont.cuba.core.entity.EntitySnapshot) UserSession(com.haulmont.cuba.security.global.UserSession) Before(org.junit.Before)

Example 34 with QueryRunner

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

the class PersistenceHelperTest method setUp.

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

Example 35 with QueryRunner

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

the class QueryResultTest method setUp.

@Before
public void setUp() throws Exception {
    QueryRunner runner = new QueryRunner(cont.persistence().getDataSource());
    try {
        runner.update("delete from SYS_QUERY_RESULT");
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    createEntities();
}
Also used : SQLException(java.sql.SQLException) QueryRunner(com.haulmont.bali.db.QueryRunner) Before(org.junit.Before)

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