Search in sources :

Example 11 with Entity

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));
}
Also used : Entity(cn.hutool.db.Entity) SqlRunner(cn.hutool.db.SqlRunner) DruidDSFactory(cn.hutool.db.ds.druid.DruidDSFactory) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 12 with Entity

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));
}
Also used : Entity(cn.hutool.db.Entity) SqlRunner(cn.hutool.db.SqlRunner) PooledDSFactory(cn.hutool.db.ds.pooled.PooledDSFactory) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 13 with Entity

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));
}
Also used : Entity(cn.hutool.db.Entity) HikariDSFactory(cn.hutool.db.ds.hikari.HikariDSFactory) SqlRunner(cn.hutool.db.SqlRunner) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 14 with Entity

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());
}
Also used : Entity(cn.hutool.db.Entity) User(cn.hutool.db.test.pojo.User) Test(org.junit.Test)

Example 15 with Entity

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;
}
Also used : Entity(cn.hutool.db.Entity)

Aggregations

Entity (cn.hutool.db.Entity)15 Test (org.junit.Test)14 SqlRunner (cn.hutool.db.SqlRunner)7 DataSource (javax.sql.DataSource)7 ActiveEntity (cn.hutool.db.ActiveEntity)4 User (cn.hutool.db.test.pojo.User)4 Ignore (org.junit.Ignore)4 C3p0DSFactory (cn.hutool.db.ds.c3p0.C3p0DSFactory)1 DbcpDSFactory (cn.hutool.db.ds.dbcp.DbcpDSFactory)1 DruidDSFactory (cn.hutool.db.ds.druid.DruidDSFactory)1 HikariDSFactory (cn.hutool.db.ds.hikari.HikariDSFactory)1 PooledDSFactory (cn.hutool.db.ds.pooled.PooledDSFactory)1 TomcatDSFactory (cn.hutool.db.ds.tomcat.TomcatDSFactory)1 EntityListHandler (cn.hutool.db.handler.EntityListHandler)1