本文整理汇总了Java中org.h2.jdbc.JdbcConnection类的典型用法代码示例。如果您正苦于以下问题:Java JdbcConnection类的具体用法?Java JdbcConnection怎么用?Java JdbcConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JdbcConnection类属于org.h2.jdbc包,在下文中一共展示了JdbcConnection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: convertTo
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
/**
* Convert a value to the specified class.
*
* @param conn the database connection
* @param v the value
* @param paramClass the target class
* @return the converted object
*/
public static Object convertTo(JdbcConnection conn, Value v,
Class<?> paramClass) {
if (paramClass == Blob.class) {
return new JdbcBlob(conn, v, 0);
} else if (paramClass == Clob.class) {
return new JdbcClob(conn, v, 0);
}
if (v.getType() == Value.JAVA_OBJECT) {
Object o = SysProperties.serializeJavaObject ? JdbcUtils.deserialize(v.getBytes(),
conn.getSession().getDataHandler()) : v.getObject();
if (paramClass.isAssignableFrom(o.getClass())) {
return o;
}
}
throw DbException.getUnsupportedException("converting to class " + paramClass.getName());
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:DataType.java
示例2: parseKey
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
/**
* Parse a primary key condition into the primary key columns.
*
* @param conn the database connection
* @param key the primary key condition as a string
* @return an array containing the column name list and the data list
*/
protected static Object[][] parseKey(Connection conn, String key) {
ArrayList<String> columns = New.arrayList();
ArrayList<String> data = New.arrayList();
JdbcConnection c = (JdbcConnection) conn;
Session session = (Session) c.getSession();
Parser p = new Parser(session);
Expression expr = p.parseExpression(key);
addColumnData(columns, data, expr);
Object[] col = new Object[columns.size()];
columns.toArray(col);
Object[] dat = new Object[columns.size()];
data.toArray(dat);
Object[][] columnData = { col, dat };
return columnData;
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:FullText.java
示例3: connect
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
/**
* Open a database connection.
* This method should not be called by an application.
* Instead, the method DriverManager.getConnection should be used.
*
* @param url the database URL
* @param info the connection properties
* @return the new connection or null if the URL is not supported
*/
@Override
public Connection connect(String url, Properties info) throws SQLException {
try {
if (info == null) {
info = new Properties();
}
if (!acceptsURL(url)) {
return null;
}
if (url.equals(DEFAULT_URL)) {
return DEFAULT_CONNECTION.get();
}
Connection c = DbUpgrade.connectOrUpgrade(url, info);
if (c != null) {
return c;
}
return new JdbcConnection(url, info);
} catch (Exception e) {
throw DbException.toSQLException(e);
}
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:31,代码来源:Driver.java
示例4: getJdbcConnection
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
private JdbcConnection getJdbcConnection(String user, char[] password)
throws SQLException {
if (isDebugEnabled()) {
debugCode("getJdbcConnection("+quote(user)+", new char[0]);");
}
Properties info = new Properties();
info.setProperty("user", user);
info.put("password", password);
Connection conn = Driver.load().connect(url, info);
if (conn == null) {
throw new SQLException("No suitable driver found for " + url,
"08001", 8001);
} else if (!(conn instanceof JdbcConnection)) {
throw new SQLException(
"Connecting with old version is not supported: " + url,
"08001", 8001);
}
return (JdbcConnection) conn;
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:JdbcDataSource.java
示例5: test
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
@Override
public void test() throws Exception {
deleteDb("lob");
testUnsupportedOperations();
testLobStaysOpenUntilCommitted();
testInputStreamThrowsException(true);
testInputStreamThrowsException(false);
conn = (JdbcConnection) getConnection("lob");
stat = conn.createStatement();
stat.execute("create table test(id int, x blob)");
testBlob(0);
testBlob(1);
testBlob(100);
testBlob(100000);
stat.execute("drop table test");
stat.execute("create table test(id int, x clob)");
testClob(0);
testClob(1);
testClob(100);
testClob(100000);
stat.execute("drop table test");
conn.close();
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:TestLobApi.java
示例6: testKillWriter
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
private void testKillWriter() throws Exception {
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized";
String writeUrl = url +
";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;WRITE_DELAY=0";
Connection conn = getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key)");
((JdbcConnection) conn).setPowerOffCount(1);
assertThrows(ErrorCode.DATABASE_IS_CLOSED, stat).execute(
"insert into test values(1)");
Connection conn2 = getConnection(writeUrl, "sa", "sa");
Statement stat2 = conn2.createStatement();
stat2.execute("insert into test values(1)");
printResult(stat2, "select * from test");
conn2.close();
assertThrows(ErrorCode.DATABASE_IS_CLOSED, conn).close();
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:TestFileLockSerialized.java
示例7: testReadOnly
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
private void testReadOnly() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore;MV_STORE=TRUE";
Connection conn;
Statement stat;
conn = getConnection(dbName);
stat = conn.createStatement();
stat.execute("create table test(id int)");
conn.close();
FileUtils.setReadOnly(getBaseDir() + "/mvstore" +
Constants.SUFFIX_MV_FILE);
conn = getConnection(dbName);
Database db = (Database) ((JdbcConnection) conn).getSession()
.getDataHandler();
assertTrue(db.getMvStore().getStore().getFileStore().isReadOnly());
conn.close();
FileUtils.deleteRecursive(getBaseDir(), true);
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:19,代码来源:TestMVTableEngine.java
示例8: testReuseDiskSpace
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
private void testReuseDiskSpace() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore;MV_STORE=TRUE";
Connection conn;
Statement stat;
long maxSize = 0;
for (int i = 0; i < 20; i++) {
conn = getConnection(dbName);
Database db = (Database) ((JdbcConnection) conn).
getSession().getDataHandler();
db.getMvStore().getStore().setRetentionTime(0);
stat = conn.createStatement();
stat.execute("create table test(id int primary key, data varchar)");
stat.execute("insert into test select x, space(1000) " +
"from system_range(1, 1000)");
stat.execute("drop table test");
conn.close();
long size = FileUtils.size(getBaseDir() + "/mvstore"
+ Constants.SUFFIX_MV_FILE);
if (i < 10) {
maxSize = (int) (Math.max(size, maxSize) * 1.1);
} else if (size > maxSize) {
fail(i + " size: " + size + " max: " + maxSize);
}
}
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:TestMVTableEngine.java
示例9: createConnection
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
private static Connection createConnection(@Nullable File dbFile) throws SQLException {
if (dbFile == null) {
// db_close_on_exit=false since jvm shutdown hook is handled by DataSource
return new JdbcConnection("jdbc:h2:mem:;compress=true;db_close_on_exit=false",
new Properties());
} else {
String dbPath = dbFile.getPath();
dbPath = dbPath.replaceFirst(".h2.db$", "");
Properties props = new Properties();
props.setProperty("user", "sa");
props.setProperty("password", "");
// db_close_on_exit=false since jvm shutdown hook is handled by DataSource
String url = "jdbc:h2:" + dbPath + ";compress=true;db_close_on_exit=false;cache_size="
+ CACHE_SIZE;
return new JdbcConnection(url, props);
}
}
开发者ID:glowroot,项目名称:glowroot,代码行数:18,代码来源:DataSource.java
示例10: createConnection
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
/**
* Create an internal connection. This connection is used when initializing
* triggers, and when calling user defined functions.
*
* @param columnList if the url should be 'jdbc:columnlist:connection'
* @return the internal connection
*/
public JdbcConnection createConnection(boolean columnList) {
String url;
if (columnList) {
url = Constants.CONN_URL_COLUMNLIST;
} else {
url = Constants.CONN_URL_INTERNAL;
}
return new JdbcConnection(this, getUser().getName(), url);
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:Session.java
示例11: getLobConnectionForInit
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
public JdbcConnection getLobConnectionForInit() {
String url = Constants.CONN_URL_INTERNAL;
JdbcConnection conn = new JdbcConnection(
systemSession, systemUser.getName(), url);
conn.setTraceLevel(TraceSystem.OFF);
return conn;
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:8,代码来源:Database.java
示例12: getLobConnectionForRegularUse
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
public JdbcConnection getLobConnectionForRegularUse() {
String url = Constants.CONN_URL_INTERNAL;
JdbcConnection conn = new JdbcConnection(
lobSession, systemUser.getName(), url);
conn.setTraceLevel(TraceSystem.OFF);
return conn;
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:8,代码来源:Database.java
示例13: readBlobDb
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
/**
* INTERNAL
*/
public static Value.ValueBlob readBlobDb(Connection conn, long lobId,
long precision) {
DataHandler h = ((JdbcConnection) conn).getSession().getDataHandler();
verifyPageStore(h);
return ValueLobDb.create(Value.BLOB, h, LobStorageFrontend.TABLE_TEMP,
lobId, null, precision);
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:11,代码来源:Recover.java
示例14: readClobDb
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
/**
* INTERNAL
*/
public static Value.ValueClob readClobDb(Connection conn, long lobId,
long precision) {
DataHandler h = ((JdbcConnection) conn).getSession().getDataHandler();
verifyPageStore(h);
return ValueLobDb.create(Value.CLOB, h, LobStorageFrontend.TABLE_TEMP,
lobId, null, precision);
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:11,代码来源:Recover.java
示例15: testLobCrash
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
private void testLobCrash() throws SQLException {
if (config.networked) {
return;
}
deleteDb(dir, DB_NAME);
Connection conn = getConnection(url);
Statement stat = conn.createStatement();
stat.execute("create table test(id identity, data clob)");
conn.close();
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("set write_delay 0");
((JdbcConnection) conn).setPowerOffCount(Integer.MAX_VALUE);
stat.execute("insert into test values(null, space(11000))");
int max = Integer.MAX_VALUE - ((JdbcConnection) conn).getPowerOffCount();
for (int i = 0; i < max + 10; i++) {
conn.close();
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("insert into test values(null, space(11000))");
stat.execute("set write_delay 0");
((JdbcConnection) conn).setPowerOffCount(i);
try {
stat.execute("insert into test values(null, space(11000))");
} catch (SQLException e) {
// ignore
}
JdbcUtils.closeSilently(conn);
}
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:31,代码来源:TestPowerOff.java
示例16: testCrash
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
private void testCrash() throws SQLException {
if (config.networked) {
return;
}
deleteDb(dir, DB_NAME);
Random random = new Random(1);
int repeat = getSize(1, 20);
for (int i = 0; i < repeat; i++) {
Connection conn = getConnection(url);
conn.close();
conn = getConnection(url);
Statement stat = conn.createStatement();
stat.execute("SET WRITE_DELAY 0");
((JdbcConnection) conn).setPowerOffCount(random.nextInt(100));
try {
stat.execute("DROP TABLE IF EXISTS TEST");
stat.execute("CREATE TABLE TEST" +
"(ID INT PRIMARY KEY, NAME VARCHAR(255))");
conn.setAutoCommit(false);
int len = getSize(3, 100);
for (int j = 0; j < len; j++) {
stat.execute("INSERT INTO TEST VALUES(" + j + ", 'Hello')");
if (random.nextInt(5) == 0) {
conn.commit();
}
if (random.nextInt(10) == 0) {
stat.execute("DROP TABLE IF EXISTS TEST");
stat.execute("CREATE TABLE TEST" +
"(ID INT PRIMARY KEY, NAME VARCHAR(255))");
}
}
stat.execute("DROP TABLE IF EXISTS TEST");
conn.close();
} catch (SQLException e) {
if (!e.getSQLState().equals("90098")) {
TestBase.logError("power", e);
}
}
}
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:41,代码来源:TestPowerOff.java
示例17: recoverAndCheckConsistency
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
private int recoverAndCheckConsistency() throws SQLException {
int state;
Database.setInitialPowerOffCount(0);
Connection conn = getConnection(url);
assertEquals(0, ((JdbcConnection) conn).getPowerOffCount());
Statement stat = conn.createStatement();
DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getTables(null, null, "TEST", null);
if (!rs.next()) {
state = 0;
} else {
// table does not exist
rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
if (!rs.next()) {
state = 1;
} else {
assertEquals(1, rs.getInt(1));
String name1 = rs.getString(2);
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
String name2 = rs.getString(2);
assertFalse(rs.next());
if ("Hello".equals(name1)) {
assertEquals("World", name2);
state = 2;
} else {
assertEquals("Hallo", name1);
assertEquals("Welt", name2);
state = 3;
}
}
}
conn.close();
return state;
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:36,代码来源:TestPowerOff.java
示例18: testJavaObject
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
private void testJavaObject() throws SQLException {
deleteDb("lob");
JdbcConnection conn = (JdbcConnection) getConnection("lob");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA OTHER)");
PreparedStatement prep = conn.prepareStatement(
"INSERT INTO TEST VALUES(1, ?)");
prep.setObject(1, new TestLobObject("abc"));
prep.execute();
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
rs.next();
Object oa = rs.getObject(2);
assertEquals(TestLobObject.class.getName(), oa.getClass().getName());
Object ob = rs.getObject("DATA");
assertEquals(TestLobObject.class.getName(), ob.getClass().getName());
assertEquals("TestLobObject: abc", oa.toString());
assertEquals("TestLobObject: abc", ob.toString());
assertFalse(rs.next());
conn.createStatement().execute("drop table test");
stat.execute("create table test(value other)");
prep = conn.prepareStatement("insert into test values(?)");
prep.setObject(1, JdbcUtils.serialize("", conn.getSession().getDataHandler()));
prep.execute();
rs = stat.executeQuery("select value from test");
while (rs.next()) {
assertEquals("", (String) rs.getObject("value"));
}
conn.close();
}
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:31,代码来源:TestLob.java
示例19: isClosed
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see org.openstreetmap.osm.data.h2.IConnection#isClosed()
*/
public boolean isClosed() throws SQLException {
if (myConnection.isClosed()) {
return true;
}
if (myConnection instanceof JdbcConnection) {
return ((JdbcConnection) myConnection).getSession().isClosed();
}
return false;
}
开发者ID:xafero,项目名称:travelingsales,代码行数:14,代码来源:H2DataSet.java
示例20: shouldReadIndexes
import org.h2.jdbc.JdbcConnection; //导入依赖的package包/类
@Test
public void shouldReadIndexes() throws Exception {
// given
Connection connection = new JdbcConnection("jdbc:h2:mem:", new Properties());
Statement statement = connection.createStatement();
statement.execute("create table tab (a varchar, b bigint)");
statement.execute("create index tab_idx on tab (a)");
// when
Set<Index> indexes = Schemas.getIndexes("tab", connection);
// then
assertThat(indexes).hasSize(1);
assertThat(indexes.iterator().next())
.isEqualTo(ImmutableIndex.of("tab_idx", ImmutableList.of("a")));
}
开发者ID:glowroot,项目名称:glowroot,代码行数:15,代码来源:SchemasTest.java
注:本文中的org.h2.jdbc.JdbcConnection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论