Search in sources :

Example 1 with Email

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

the class TableModelTest method cloneTest.

@Test
public void cloneTest() {
    TableModel t1 = new TableModel("customers");
    t1.column("name").STRING(20).pkey();
    t1.column("email").STRING(20).pkey().entityField("email").updatable(true).insertable(false);
    t1.column("address").VARCHAR(50).defaultValue("'Beijing'").comment("address comment");
    t1.column("phoneNumber").VARCHAR(50).singleIndex("IDX2");
    t1.column("age").INTEGER().notNull().check("'>0'");
    t1.index("idx3").columns("address", "phoneNumber").unique();
    Assert.assertNotNull(t1.getColumn("name").getTableModel());
    TableModel t2 = t1.newCopy();
    System.out.println(t1);
    System.out.println(t2);
    Assert.assertNotEquals(t1, t2);
    Assert.assertNotNull(t2.getColumn("name").getTableModel());
    System.out.println("================");
    for (ColumnModel item : t1.getColumns()) {
        System.out.println(item);
    }
    System.out.println("================");
    for (ColumnModel item : t2.getColumns()) {
        System.out.println(item);
    }
}
Also used : ColumnModel(com.github.drinkjava2.jdialects.model.ColumnModel) TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Example 2 with Email

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

the class DDLTest method sampleTest.

@Test
public void sampleTest() {
    // An example used to put on README.md
    TableModel t1 = new TableModel("customers");
    t1.column("name").STRING(20).pkey();
    t1.column("email").STRING(20).pkey().entityField("email").updatable(true).insertable(false);
    t1.column("address").VARCHAR(50).defaultValue("'Beijing'").comment("address comment");
    t1.column("phoneNumber").VARCHAR(50).singleIndex("IDX2");
    t1.column("age").INTEGER().notNull().check("'>0'");
    t1.index("idx3").columns("address", "phoneNumber").unique();
    TableModel t2 = new TableModel("orders").comment("order comment");
    t2.column("id").LONG().autoId().pkey();
    t2.column("name").STRING(20);
    t2.column("email").STRING(20);
    t2.column("name2").STRING(20).pkey().tail(" default 'Sam'");
    t2.column("email2").STRING(20);
    t2.fkey().columns("name2", "email2").refs("customers", "name", "email");
    t2.fkey("fk1").columns("name", "email").refs("customers", "name", "email");
    t2.unique("uk1").columns("name2", "email2");
    TableModel t3 = new TableModel("sampletable");
    t3.column("id").LONG().identityId().pkey();
    t3.tableGenerator("table_gen1", "tb1", "pkcol2", "valcol", "pkval", 1, 10);
    t3.column("id1").INTEGER().idGenerator("table_gen1");
    t3.sequenceGenerator("seq1", "seq_1", 1, 1);
    t3.column("id2").INTEGER().idGenerator("seq1");
    t3.engineTail(" DEFAULT CHARSET=utf8");
    String[] dropAndCreateDDL = Dialect.H2Dialect.toDropAndCreateDDL(t1, t2, t3);
    for (String ddl : dropAndCreateDDL) System.out.println(ddl);
    testOnCurrentRealDatabase(t1, t2, t3);
}
Also used : TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Example 3 with Email

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

the class EntityNetDemoTest method testReturnDifferentType.

@Test
public void testReturnDifferentType() {
    insertDemoData();
    EntityNet net = ctx.netLoad(new User(), new Email());
    Map<Class<?>, Set<Object>> result = net.findEntityMap(new Path("S+", Email.class).nextPath("P+", User.class, "userId"));
    System.out.println("user selected:" + result.get(User.class).size());
    System.out.println("email selected:" + result.get(Email.class).size());
}
Also used : Path(com.github.drinkjava2.jsqlbox.entitynet.Path) User(com.github.drinkjava2.functionstest.entitynet.entities.User) Email(com.github.drinkjava2.functionstest.entitynet.entities.Email) Set(java.util.Set) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Test(org.junit.Test)

Example 4 with Email

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

the class EntityNetDemoTest method testManualLoadAndJoin.

@Test
public void testManualLoadAndJoin() {
    insertDemoData();
    List<Map<String, Object>> mapList1 = ctx.nQuery(new EntitySqlMapListHandler(User.class, Address.class), "select u.**, a.** from usertb u, addresstb a where a.userId=u.id");
    EntityNet net = ctx.netCreate(mapList1);
    Assert.assertEquals(10, net.size());
    Email e = new Email();
    e.alias("e");
    List<Map<String, Object>> mapList2 = ctx.nQuery(new EntitySqlMapListHandler(e), "select e.id as e_id from emailtb as e");
    ctx.netJoinList(net, mapList2);
    Assert.assertEquals(15, net.size());
    List<Map<String, Object>> mapList3 = ctx.nQuery(new EntitySqlMapListHandler(Role.class, UserRole.class, RolePrivilege.class, Privilege.class), "select r.**, ur.**, rp.**, p.** from roletb r, userroletb ur, RolePrivilegetb rp, privilegetb p");
    Assert.assertEquals(900, mapList3.size());
    ctx.netJoinList(net, mapList3);
    Assert.assertEquals(37, net.size());
}
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) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) RolePrivilege(com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege) RolePrivilege(com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege) Privilege(com.github.drinkjava2.functionstest.entitynet.entities.Privilege) Map(java.util.Map) EntitySqlMapListHandler(com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler) Test(org.junit.Test)

Example 5 with Email

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

the class EntityNetQueryTest method testJoinParents.

@Test
public void testJoinParents() {
    System.out.println("==============testJoinParents================ ");
    new User().put("id", "u1").put("userName", "user1").insert();
    new User().put("id", "u2").put("userName", "user2").insert();
    new Email().putFields("id", "emailName", "userId");
    new Email().putValues("e1", "email1", "u1").insert();
    new Email().putValues("e2", "email2", "u1").insert();
    List<Map<String, Object>> listMap = ctx.nQuery(new EntitySqlMapListHandler(new Email().alias("e")), "select e.id as e_id from emailtb e");
    EntityNet net = (EntityNet) ctx.netCreate(listMap);
    Assert.assertEquals(2, net.size());
    Node emailNode = net.getOneNode(Email.class, "e1");
    // e1 have no userId
    Assert.assertNull(emailNode.getParentRelations());
    // field
    List<Map<String, Object>> listMap2 = ctx.nQuery(new EntitySqlMapListHandler(Email.class), "select e.** from emailtb e");
    ctx.netJoinList(net, listMap2);
    Assert.assertEquals(2, net.size());
    emailNode = net.getOneNode(Email.class, "e1");
    Assert.assertNotNull(emailNode.getParentRelations());
}
Also used : User(com.github.drinkjava2.functionstest.entitynet.entities.User) Email(com.github.drinkjava2.functionstest.entitynet.entities.Email) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Node(com.github.drinkjava2.jsqlbox.entitynet.Node) Map(java.util.Map) EntitySqlMapListHandler(com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 Email (com.github.drinkjava2.functionstest.entitynet.entities.Email)11 User (com.github.drinkjava2.functionstest.entitynet.entities.User)11 EntityNet (com.github.drinkjava2.jsqlbox.entitynet.EntityNet)10 Path (com.github.drinkjava2.jsqlbox.entitynet.Path)8 Set (java.util.Set)4 Privilege (com.github.drinkjava2.functionstest.entitynet.entities.Privilege)3 Role (com.github.drinkjava2.functionstest.entitynet.entities.Role)3 RolePrivilege (com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege)3 UserRole (com.github.drinkjava2.functionstest.entitynet.entities.UserRole)3 TableModel (com.github.drinkjava2.jdialects.model.TableModel)3 Address (com.github.drinkjava2.functionstest.entitynet.entities.Address)2 EntitySqlMapListHandler (com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler)2 Map (java.util.Map)2 ColumnModel (com.github.drinkjava2.jdialects.model.ColumnModel)1 Node (com.github.drinkjava2.jsqlbox.entitynet.Node)1 EntityNetHandler (com.github.drinkjava2.jsqlbox.handler.EntityNetHandler)1