Search in sources :

Example 21 with SqlBoxContext

use of com.github.drinkjava2.jsqlbox.SqlBoxContext in project jSqlBox by drinkjava2.

the class UsuageAndSpeedTest method sqlMapperUseText.

@Test
public void sqlMapperUseText() {
    SqlBoxContext ctx = new SqlBoxContext(dataSource);
    // use global default context
    SqlBoxContext.setGlobalSqlBoxContext(ctx);
    TextedUser user = new TextedUser();
    for (int i = 0; i < REPEAT_TIMES; i++) {
        user.insertOneUser("Sam", "Canada");
        user.ctx().nUpdate(user.updateAllUserPreSql("Tom", "China"));
        // List<Map<String, Object>> users = user.selectUsersByText("Tom", "China");
        // Assert.assertEquals(1, users.size());
        List<TextedUser> users2 = user.selectUsersByText2("Tom", "China");
        Assert.assertEquals(1, users2.size());
        user.deleteUsers("Tom", "China");
        Assert.assertEquals(0, user.ctx().nQueryForLongValue("select count(*) from users"));
    }
}
Also used : SqlBoxContext(com.github.drinkjava2.jsqlbox.SqlBoxContext) TextedUser(activerecordtext.TextedUser) Test(org.junit.Test)

Example 22 with SqlBoxContext

use of com.github.drinkjava2.jsqlbox.SqlBoxContext in project jSqlBox by drinkjava2.

the class UsuageAndSpeedTest method iXxxStyle2.

@Test
public void iXxxStyle2() {
    SqlBoxContext ctx = new SqlBoxContext(dataSource);
    for (int i = 0; i < REPEAT_TIMES; i++) {
        // 
        ctx.iExecute(// 
        "insert into ", // 
        UserAR.USER, // 
        " ( ", // 
        UserAR.NAME, // 
        ",", // 
        param0("Sam"), // 
        UserAR.ADDRESS, // 
        " ", // 
        param("Canada"), ") ", valuesQuesions());
        param0("Tom", "China");
        ctx.iExecute("update users set name=?,address=?");
        Assert.assertEquals(1L, ctx.iQueryForObject("select count(*) from users where name=? and address=?" + param0("Tom", "China")));
        ctx.iExecute("delete from users where name=", question0("Tom"), " or address=", question("China"));
    }
}
Also used : SqlBoxContext(com.github.drinkjava2.jsqlbox.SqlBoxContext) Test(org.junit.Test)

Example 23 with SqlBoxContext

use of com.github.drinkjava2.jsqlbox.SqlBoxContext in project jSqlBox by drinkjava2.

the class UsuageAndSpeedTest method abstractSqlMapperUseText.

@Test
public void abstractSqlMapperUseText() {
    SqlBoxContext ctx = new SqlBoxContext(dataSource);
    // use global default context
    SqlBoxContext.setGlobalSqlBoxContext(ctx);
    AbstractUser user = ActiveRecord.create(AbstractUser.class);
    for (int i = 0; i < REPEAT_TIMES; i++) {
        user.insertOneUser("Sam", "Canada");
        user.ctx().nUpdate(user.updateUserPreparedSQL("Tom", "China"));
        // List<Map<String, Object>> users = user.selectUserListMap("Tom", "China");
        // Assert.assertEquals(1, users.size());
        List<AbstractUser> users2 = user.selectAbstractUserList("Tom", "China");
        Assert.assertEquals(1, users2.size());
        user.deleteUsers("Tom", "China");
        Assert.assertEquals(0, user.ctx().nQueryForLongValue("select count(*) from	 users"));
    }
}
Also used : AbstractUser(activerecordtext.AbstractUser) SqlBoxContext(com.github.drinkjava2.jsqlbox.SqlBoxContext) Test(org.junit.Test)

Example 24 with SqlBoxContext

use of com.github.drinkjava2.jsqlbox.SqlBoxContext in project jSqlBox by drinkjava2.

the class UsuageAndSpeedTest method activeRecordStyle.

@Test
public void activeRecordStyle() {
    SqlBoxContext ctx = new SqlBoxContext(dataSource);
    UserAR user = new UserAR();
    // Use ctx as SqlBoxContext
    user.useContext(ctx);
    for (int i = 0; i < REPEAT_TIMES; i++) {
        user.setName("Sam");
        user.setAddress("Canada");
        user.insert();
        user.setAddress("China");
        user.update();
        UserAR user2 = user.load("Sam");
        user2.delete();
    }
}
Also used : SqlBoxContext(com.github.drinkjava2.jsqlbox.SqlBoxContext) Test(org.junit.Test)

Example 25 with SqlBoxContext

use of com.github.drinkjava2.jsqlbox.SqlBoxContext in project jSqlBox by drinkjava2.

the class UsuageAndSpeedTest method iXxxStyle.

@Test
public void iXxxStyle() {
    SqlBoxContext ctx = new SqlBoxContext(dataSource);
    for (int i = 0; i < REPEAT_TIMES; i++) {
        // 
        ctx.iExecute(// 
        "insert into users (", // 
        " name ,", // 
        param0("Sam"), // 
        " address ", // 
        param("Canada"), ") ", valuesQuesions());
        param0("Tom", "China");
        ctx.iExecute("update users set name=?,address=?");
        Assert.assertEquals(1L, ctx.iQueryForObject("select count(*) from users where name=? and address=?" + param0("Tom", "China")));
        ctx.iExecute("delete from users where name=", question0("Tom"), " or address=", question("China"));
    }
}
Also used : SqlBoxContext(com.github.drinkjava2.jsqlbox.SqlBoxContext) Test(org.junit.Test)

Aggregations

SqlBoxContext (com.github.drinkjava2.jsqlbox.SqlBoxContext)23 Test (org.junit.Test)18 TableModel (com.github.drinkjava2.jdialects.model.TableModel)7 Map (java.util.Map)6 HikariDataSource (com.zaxxer.hikari.HikariDataSource)5 Method (java.lang.reflect.Method)5 ColumnModel (com.github.drinkjava2.jdialects.model.ColumnModel)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 SqlBoxContextConfig (com.github.drinkjava2.jsqlbox.SqlBoxContextConfig)2 Before (org.junit.Before)2 AbstractUser (activerecordtext.AbstractUser)1 TextedUser (activerecordtext.TextedUser)1 Team (com.demo.model.Team)1 DataSourceBox (com.github.drinkjava2.config.DataSourceConfig.DataSourceBox)1 Type (com.github.drinkjava2.jdialects.Type)1 GenerationType (com.github.drinkjava2.jdialects.annotation.jpa.GenerationType)1 IdGenerator (com.github.drinkjava2.jdialects.id.IdGenerator)1 IdentityIdGenerator (com.github.drinkjava2.jdialects.id.IdentityIdGenerator)1