Search in sources :

Example 11 with User

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

the class EntityNetQueryTest method testRemoveEntity.

@Test
public void testRemoveEntity() {
    System.out.println("==============testRemoveEntity================ ");
    new User().put("id", "u1").put("userName", "user1").insert();
    new User().put("id", "u2").put("userName", "user2").insert();
    EntityNet net = ctx.netLoad(User.class);
    Assert.assertEquals(2, net.size());
    User u2 = net.getOneEntity(User.class, "u2");
    ctx.netRemoveEntity(net, u2);
    Assert.assertEquals(1, net.size());
}
Also used : User(com.github.drinkjava2.functionstest.entitynet.entities.User) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Test(org.junit.Test)

Example 12 with User

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

the class EntityNetQueryTest method testAddEntity.

@Test
public void testAddEntity() {
    System.out.println("==============testAddEntity================ ");
    new User().put("id", "u1").put("userName", "user1").insert();
    EntityNet net = ctx.netLoad(User.class);
    Assert.assertEquals(1, net.size());
    User u2 = new User();
    u2.setId("u2");
    u2.setUserName("user2");
    u2.insert();
    ctx.netAddEntity(net, u2);
    Assert.assertEquals(2, net.size());
    User u = net.getOneEntity(User.class, "u2");
    Assert.assertEquals("user2", u.getUserName());
}
Also used : User(com.github.drinkjava2.functionstest.entitynet.entities.User) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Test(org.junit.Test)

Example 13 with User

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

the class TinyParserTest method testSpeed.

@Test
public void testSpeed() {
    User user = new User();
    user.setId("001");
    user.setUserName("Tom");
    Map<String, Object> preset = new HashMap<String, Object>();
    preset.put("FOO", 123);
    preset.put("BAR", "456");
    long start = System.currentTimeMillis();
    for (int i = 0; i < 10000; i++) Assert.assertEquals(true, TinyParser.instance.doParse(user, preset, "(1+2)*3/4>0.1/(9+?) and (userName equals ?) and id equals ? and (200 = ? ) and (FOO = 123 or BAR equals '456')", 100, "Tom", "001", 200));
    Double secondsUsed = (System.currentTimeMillis() - start) / 1000.0;
    System.out.println("TinyParser repeat 10000 REPEAT_TIMES cost " + secondsUsed + "s");
    Assert.assertTrue(secondsUsed < 5);
}
Also used : User(com.github.drinkjava2.functionstest.entitynet.entities.User) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 14 with User

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

the class UsuageAndSpeedTest method xXxxStyle_BasicTemplate.

@Test
public void xXxxStyle_BasicTemplate() {
    SqlBoxContextConfig config = new SqlBoxContextConfig();
    config.setTemplateEngine(BasicSqlTemplate.instance());
    SqlBoxContext ctx = new SqlBoxContext(dataSource, config);
    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 : SqlBoxContextConfig(com.github.drinkjava2.jsqlbox.SqlBoxContextConfig) SqlBoxContext(com.github.drinkjava2.jsqlbox.SqlBoxContext) Test(org.junit.Test)

Example 15 with User

use of com.github.drinkjava2.functionstest.entitynet.entities.User 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)

Aggregations

Test (org.junit.Test)35 User (com.github.drinkjava2.functionstest.entitynet.entities.User)25 EntityNet (com.github.drinkjava2.jsqlbox.entitynet.EntityNet)18 SqlBoxContext (com.github.drinkjava2.jsqlbox.SqlBoxContext)12 Path (com.github.drinkjava2.jsqlbox.entitynet.Path)11 Email (com.github.drinkjava2.functionstest.entitynet.entities.Email)9 Role (com.github.drinkjava2.functionstest.entitynet.entities.Role)7 UserRole (com.github.drinkjava2.functionstest.entitynet.entities.UserRole)7 HashMap (java.util.HashMap)6 Privilege (com.github.drinkjava2.functionstest.entitynet.entities.Privilege)5 RolePrivilege (com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege)5 Map (java.util.Map)4 Set (java.util.Set)4 HikariDataSource (com.zaxxer.hikari.HikariDataSource)3 EntitySqlMapListHandler (com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler)2 AbstractUser (activerecordtext.AbstractUser)1 TextedUser (activerecordtext.TextedUser)1 Address (com.github.drinkjava2.functionstest.entitynet.entities.Address)1 TableModel (com.github.drinkjava2.jdialects.model.TableModel)1 SqlBoxContextConfig (com.github.drinkjava2.jsqlbox.SqlBoxContextConfig)1