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);
}
}
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);
}
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());
}
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());
}
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());
}
Aggregations