mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add h2 and derby test
This commit is contained in:
parent
e8c0a75e7f
commit
01ac0f94dc
@ -135,5 +135,11 @@
|
||||
<version>1.7.26</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.200</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -45,9 +45,7 @@ public class DialectFactory {
|
||||
/** JDBC 驱动 H2 */
|
||||
public static final String DRIVER_H2 = "org.h2.Driver";
|
||||
/** JDBC 驱动 Derby */
|
||||
public static final String DRIVER_DERBY = "org.apache.derby.jdbc.ClientDriver";
|
||||
/** JDBC 驱动 Derby嵌入式 */
|
||||
public static final String DRIVER_DERBY_EMBEDDED = "org.apache.derby.jdbc.EmbeddedDriver";
|
||||
public static final String DRIVER_DERBY = "org.apache.derby.jdbc.AutoloadedDriver";
|
||||
/** JDBC 驱动 HSQLDB */
|
||||
public static final String DRIVER_HSQLDB = "org.hsqldb.jdbc.JDBCDriver";
|
||||
/** JDBC 驱动 达梦7 */
|
||||
@ -126,12 +124,9 @@ public class DialectFactory {
|
||||
driver = DRIVER_HIVE;
|
||||
} else if (nameContainsProductInfo.contains("h2")) {
|
||||
driver = DRIVER_H2;
|
||||
} else if (nameContainsProductInfo.startsWith("jdbc:derby://")) {
|
||||
// Derby数据库网络连接方式
|
||||
driver = DRIVER_DERBY;
|
||||
} else if (nameContainsProductInfo.contains("derby")) {
|
||||
// 嵌入式Derby数据库
|
||||
driver = DRIVER_DERBY_EMBEDDED;
|
||||
driver = DRIVER_DERBY;
|
||||
} else if (nameContainsProductInfo.contains("hsqldb")) {
|
||||
// HSQLDB
|
||||
driver = DRIVER_HSQLDB;
|
||||
|
@ -3,19 +3,17 @@ package cn.hutool.db.dialect.impl;
|
||||
import cn.hutool.db.Page;
|
||||
import cn.hutool.db.dialect.DialectName;
|
||||
import cn.hutool.db.sql.SqlBuilder;
|
||||
import cn.hutool.db.sql.Wrapper;
|
||||
|
||||
/**
|
||||
* H2数据库方言
|
||||
*
|
||||
* @author loolly
|
||||
*
|
||||
*/
|
||||
public class H2Dialect extends AnsiSqlDialect {
|
||||
private static final long serialVersionUID = 1490520247974768214L;
|
||||
|
||||
public H2Dialect() {
|
||||
wrapper = new Wrapper('"', '"');
|
||||
// wrapper = new Wrapper('"');
|
||||
}
|
||||
|
||||
@Override
|
||||
|
50
hutool-db/src/test/java/cn/hutool/db/DerbyTest.java
Normal file
50
hutool-db/src/test/java/cn/hutool/db/DerbyTest.java
Normal file
@ -0,0 +1,50 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Derby数据库单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class DerbyTest {
|
||||
|
||||
private static final String DS_GROUP_NAME = "derby";
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws SQLException {
|
||||
Db db = Db.use(DS_GROUP_NAME);
|
||||
try{
|
||||
db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
|
||||
}catch (SQLException e){
|
||||
// 数据库已存在
|
||||
return;
|
||||
}
|
||||
|
||||
db.insert(Entity.create("test").set("a", 1).set("b", 11));
|
||||
db.insert(Entity.create("test").set("a", 2).set("b", 21));
|
||||
db.insert(Entity.create("test").set("a", 3).set("b", 31));
|
||||
db.insert(Entity.create("test").set("a", 4).set("b", 41));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void queryTest() throws SQLException {
|
||||
List<Entity> query = Db.use(DS_GROUP_NAME).query("select * from test");
|
||||
Assert.assertEquals(4, query.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void findTest() throws SQLException {
|
||||
List<Entity> query = Db.use(DS_GROUP_NAME).find(Entity.create("test"));
|
||||
Assert.assertEquals(4, query.size());
|
||||
}
|
||||
}
|
42
hutool-db/src/test/java/cn/hutool/db/H2Test.java
Normal file
42
hutool-db/src/test/java/cn/hutool/db/H2Test.java
Normal file
@ -0,0 +1,42 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* H2数据库单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class H2Test {
|
||||
|
||||
private static final String DS_GROUP_NAME = "h2";
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws SQLException {
|
||||
Db db = Db.use(DS_GROUP_NAME);
|
||||
db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
|
||||
|
||||
db.insert(Entity.create("test").set("a", 1).set("b", 11));
|
||||
db.insert(Entity.create("test").set("a", 2).set("b", 21));
|
||||
db.insert(Entity.create("test").set("a", 3).set("b", 31));
|
||||
db.insert(Entity.create("test").set("a", 4).set("b", 41));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryTest() throws SQLException {
|
||||
List<Entity> query = Db.use(DS_GROUP_NAME).query("select * from test");
|
||||
Assert.assertEquals(4, query.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findTest() throws SQLException {
|
||||
List<Entity> query = Db.use(DS_GROUP_NAME).find(Entity.create("test"));
|
||||
Assert.assertEquals(4, query.size());
|
||||
}
|
||||
}
|
@ -1,15 +1,12 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.db.Db;
|
||||
import cn.hutool.db.Entity;
|
||||
|
||||
/**
|
||||
* HSQLDB数据库单元测试
|
||||
*
|
||||
@ -20,8 +17,8 @@ public class HsqldbTest {
|
||||
|
||||
private static final String DS_GROUP_NAME = "hsqldb";
|
||||
|
||||
@Before
|
||||
public void init() throws SQLException {
|
||||
@BeforeClass
|
||||
public static void init() throws SQLException {
|
||||
Db db = Db.use(DS_GROUP_NAME);
|
||||
db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
|
||||
db.insert(Entity.create("test").set("a", 1).set("b", 11));
|
||||
@ -35,4 +32,10 @@ public class HsqldbTest {
|
||||
List<Entity> query = Db.use(DS_GROUP_NAME).query("select * from test");
|
||||
Assert.assertEquals(4, query.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findTest() throws SQLException {
|
||||
List<Entity> query = Db.use(DS_GROUP_NAME).find(Entity.create("test"));
|
||||
Assert.assertEquals(4, query.size());
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,16 @@ url = jdbc:hsqldb:mem:mem_hutool
|
||||
user = SA
|
||||
pass =
|
||||
|
||||
# 测试用HSQLDB数据库
|
||||
[h2]
|
||||
url = jdbc:h2:mem:h2_hutool
|
||||
user = sa
|
||||
pass =
|
||||
|
||||
# 测试用HSQLDB数据库
|
||||
[derby]
|
||||
url = jdbc:derby:.derby/test_db;create=true
|
||||
|
||||
# 测试用Oracle数据库
|
||||
[orcl]
|
||||
url = jdbc:oracle:thin:@//looly.centos:1521/XE
|
||||
|
Loading…
x
Reference in New Issue
Block a user