use of cn.hutool.db.Entity in project hutool by looly.
the class DsTest method druidDsTest.
@Test
public void druidDsTest() throws SQLException {
DSFactory.setCurrentDSFactory(new DruidDSFactory());
DataSource ds = DSFactory.get();
SqlRunner runner = SqlRunner.create(ds);
List<Entity> all = runner.findAll("user");
Assert.assertTrue(CollUtil.isNotEmpty(all));
}
use of cn.hutool.db.Entity in project hutool by looly.
the class DsTest method hutoolPoolTest.
@Test
public void hutoolPoolTest() throws SQLException {
DSFactory.setCurrentDSFactory(new PooledDSFactory());
DataSource ds = DSFactory.get();
SqlRunner runner = SqlRunner.create(ds);
List<Entity> all = runner.findAll("user");
Assert.assertTrue(CollUtil.isNotEmpty(all));
}
use of cn.hutool.db.Entity in project hutool by looly.
the class DsTest method hikariDsTest.
@Test
public void hikariDsTest() throws SQLException {
DSFactory.setCurrentDSFactory(new HikariDSFactory());
DataSource ds = DSFactory.get();
SqlRunner runner = SqlRunner.create(ds);
List<Entity> all = runner.findAll("user");
Assert.assertTrue(CollUtil.isNotEmpty(all));
}
use of cn.hutool.db.Entity in project hutool by looly.
the class EntityTest method entityToBeanIgnoreCaseTest.
@Test
public void entityToBeanIgnoreCaseTest() {
Entity entity = Entity.create().set("ID", 2).set("NAME", "testName");
User user = entity.toBeanIgnoreCase(User.class);
Assert.assertEquals(Integer.valueOf(2), user.getId());
Assert.assertEquals("testName", user.getName());
}
use of cn.hutool.db.Entity in project hutool by looly.
the class Wrapper method wrap.
/**
* 包装表名和字段名,此方法返回一个新的Entity实体类<br>
* 有时字段与SQL的某些关键字冲突,导致SQL出错,因此需要将字段名用单引号或者反引号包装起来,避免冲突
*
* @param entity 被包装的实体
* @return 新的实体
*/
public Entity wrap(Entity entity) {
if (null == entity) {
return null;
}
final Entity wrapedEntity = new Entity();
// wrap table name
wrapedEntity.setTableName(wrap(entity.getTableName()));
// wrap fields
for (Entry<String, Object> entry : entity.entrySet()) {
wrapedEntity.set(wrap(entry.getKey()), entry.getValue());
}
return wrapedEntity;
}
Aggregations