Search in sources :

Example 6 with Address

use of com.github.drinkjava2.functionstest.entitynet.entities.Address in project jSqlBox by drinkjava2.

the class UsuageAndSpeedTest method xXxxStyle.

@Test
public void xXxxStyle() {
    SqlBoxContext ctx = new SqlBoxContext(dataSource);
    for (int i = 0; i < REPEAT_TIMES; i++) {
        UserAR user = new UserAR("Sam", "Canada");
        UserAR tom = new UserAR("Tom", "China");
        put0("user", user);
        ctx.xExecute("insert into users (name, address) values(#{user.name},:user.address)");
        put0("user", tom);
        ctx.xExecute("update users set name=#{user.name}, address=:user.address");
        Assert.assertEquals(1L, ctx.xQueryForObject("select count(*) from users where ${col}=#{name} and address=#{addr}", put0("name", "Tom"), put("addr", "China"), replace("col", "name")));
        ctx.xExecute("delete from users where name=#{u.name} or address=#{u.address}", put0("u", tom));
    }
}
Also used : SqlBoxContext(com.github.drinkjava2.jsqlbox.SqlBoxContext) Test(org.junit.Test)

Example 7 with Address

use of com.github.drinkjava2.functionstest.entitynet.entities.Address in project jSqlBox by drinkjava2.

the class UsuageAndSpeedTest method dbUtilsWithConnMethod.

@Test
public void dbUtilsWithConnMethod() {
    SqlBoxContext ctx = new SqlBoxContext(dataSource);
    for (int i = 0; i < REPEAT_TIMES; i++) {
        Connection conn = null;
        try {
            conn = ctx.prepareConnection();
            ctx.execute(conn, "insert into users (name,address) values(?,?)", "Sam", "Canada");
            ctx.execute(conn, "update users set name=?, address=?", "Tom", "China");
            Assert.assertEquals(1L, ctx.queryForObject(conn, "select count(*) from users where name=? and address=?", "Tom", "China"));
            ctx.execute(conn, "delete from users where name=? or address=?", "Tom", "China");
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                ctx.close(conn);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) SqlBoxContext(com.github.drinkjava2.jsqlbox.SqlBoxContext) Test(org.junit.Test)

Example 8 with Address

use of com.github.drinkjava2.functionstest.entitynet.entities.Address in project jDialects by drinkjava2.

the class TableTest method testFKEY.

@Test
public void testFKEY() {
    // FKEY
    Table t = new Table("master");
    t.column("id").INTEGER().pkey();
    t.column("name").STRING(20);
    t.column("address").INTEGER().pkey();
    Table t2 = new Table("child");
    t2.column("id").INTEGER().pkey();
    t2.column("address2").VARCHAR(20).fkey("master", "name", "address");
    t2.column("masterid3").VARCHAR(20).fkey("master", "id");
    t2.column("aaaaa").VARCHAR(20).fkey("master", "name", "address");
    printAllDialectsDDLs(t, t2);
}
Also used : Table(com.github.drinkjava2.jdialects.model.Table) Test(org.junit.Test)

Example 9 with Address

use of com.github.drinkjava2.functionstest.entitynet.entities.Address in project jDialects by drinkjava2.

the class DDLTest method singleXxxMethodTest.

@Test
public void singleXxxMethodTest() {
    // Test singleXxx methods
    TableModel t1 = new TableModel("customers");
    t1.column("name").STRING(20).singleUnique();
    t1.column("email").VARCHAR(50).defaultValue("'Beijing'").comment("address comment").singleIndex("IDX1");
    TableModel t2 = new TableModel("orders");
    t2.column("item").STRING(20).singleUnique("A");
    t2.column("name").STRING(20).singleFKey("customers", "name");
    String[] dropAndCreateDDL = Dialect.H2Dialect.toDropAndCreateDDL(t1, t2);
    for (String ddl : dropAndCreateDDL) System.out.println(ddl);
    testOnCurrentRealDatabase(t1, t2);
}
Also used : TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Example 10 with Address

use of com.github.drinkjava2.functionstest.entitynet.entities.Address in project jSqlBox by drinkjava2.

the class EntityNetDemoTest method insertDemoData.

protected void insertDemoData() {
    // @formatter:off
    // Batch insert enabled
    ctx.nBatchBegin();
    new User().put("id", "u1").put("userName", "user1").insert();
    new User().put("id", "u2").put("userName", "user2").insert();
    new User().put("id", "u3").put("userName", "user3").insert();
    new User().put("id", "u4").put("userName", "user4").insert();
    new User().put("id", "u5").put("userName", "user5").insert();
    new Address().put("id", "a1", "addressName", "address1", "userId", "u1").insert();
    new Address().put("id", "a2", "addressName", "address2", "userId", "u2").insert();
    new Address().put("id", "a3", "addressName", "address3", "userId", "u3").insert();
    new Address().put("id", "a4", "addressName", "address4", "userId", "u4").insert();
    new Address().put("id", "a5", "addressName", "address5", "userId", "u5").insert();
    new Email().putFields("id", "emailName", "userId");
    new Email().putValues("e1", "email1", "u1").insert();
    new Email().putValues("e2", "email2", "u1").insert();
    new Email().putValues("e3", "email3", "u2").insert();
    new Email().putValues("e4", "email4", "u2").insert();
    new Email().putValues("e5", "email5", "u3").insert();
    Role r = new Role();
    r.setId("r1");
    r.setRoleName("role1");
    r.insert();
    r.setId("r2");
    r.setRoleName("role2");
    r.insert();
    r.setId("r3");
    r.setRoleName("role3");
    r.insert();
    r.setId("r4");
    r.setRoleName("role4");
    r.insert();
    r.setId("r5");
    r.setRoleName("role5");
    r.insert();
    Privilege p = new Privilege();
    p.setId("p1");
    p.setPrivilegeName("privilege1");
    p.insert();
    p.setId("p2");
    p.setPrivilegeName("privilege2");
    p.insert();
    p.setId("p3");
    p.setPrivilegeName("privilege3");
    p.insert();
    p.setId("p4");
    p.setPrivilegeName("privilege4");
    p.insert();
    p.setId("p5");
    p.setPrivilegeName("privilege5");
    p.insert();
    UserRole ur = new UserRole();
    ur.setUserId("u1");
    ur.setRid("r1");
    ur.insert();
    ur.setUserId("u2");
    ur.setRid("r1");
    ur.insert();
    ur.setUserId("u2");
    ur.setRid("r2");
    ur.insert();
    ur.setUserId("u2");
    ur.setRid("r3");
    ur.insert();
    ur.setUserId("u3");
    ur.setRid("r4");
    ur.insert();
    ur.setUserId("u4");
    ur.setRid("r1");
    ur.insert();
    new RolePrivilege().putFields("rid", "pid");
    new RolePrivilege().putValues("r1", "p1").insert();
    new RolePrivilege().putValues("r2", "p1").insert();
    new RolePrivilege().putValues("r2", "p2").insert();
    new RolePrivilege().putValues("r2", "p3").insert();
    new RolePrivilege().putValues("r3", "p3").insert();
    new RolePrivilege().putValues("r4", "p1").insert();
    // Batch insert end
    ctx.nBatchEnd();
// @formatter:on
}
Also used : UserRole(com.github.drinkjava2.functionstest.entitynet.entities.UserRole) Role(com.github.drinkjava2.functionstest.entitynet.entities.Role) User(com.github.drinkjava2.functionstest.entitynet.entities.User) Email(com.github.drinkjava2.functionstest.entitynet.entities.Email) Address(com.github.drinkjava2.functionstest.entitynet.entities.Address) UserRole(com.github.drinkjava2.functionstest.entitynet.entities.UserRole) RolePrivilege(com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege) RolePrivilege(com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege) Privilege(com.github.drinkjava2.functionstest.entitynet.entities.Privilege)

Aggregations

Test (org.junit.Test)14 SqlBoxContext (com.github.drinkjava2.jsqlbox.SqlBoxContext)8 TableModel (com.github.drinkjava2.jdialects.model.TableModel)4 User (com.github.drinkjava2.functionstest.entitynet.entities.User)2 SQLException (java.sql.SQLException)2 Address (com.github.drinkjava2.functionstest.entitynet.entities.Address)1 Email (com.github.drinkjava2.functionstest.entitynet.entities.Email)1 Privilege (com.github.drinkjava2.functionstest.entitynet.entities.Privilege)1 Role (com.github.drinkjava2.functionstest.entitynet.entities.Role)1 RolePrivilege (com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege)1 UserRole (com.github.drinkjava2.functionstest.entitynet.entities.UserRole)1 ColumnModel (com.github.drinkjava2.jdialects.model.ColumnModel)1 Table (com.github.drinkjava2.jdialects.model.Table)1 SqlBoxContextConfig (com.github.drinkjava2.jsqlbox.SqlBoxContextConfig)1 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1