提交 391f3743 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 8294e0f1
......@@ -353,6 +353,17 @@ This is achieved using different database URLs. The settings in the URLs are not
jdbc:h2:&lt;url&gt;;ACCESS_MODE_LOG=rws;ACCESS_MODE_DATA=rws<br />
</td>
</tr>
<tr>
<td>In-Memory (private)</td>
<td>jdbc:h2:mem:</td>
</tr>
<tr>
<td>Database in Jar or Zip File</td>
<td>
jdbc:h2:zip:&lt;zipFileName&gt;!/&lt;databaseName&gt;<br />
jdbc:h2:zip:db.zip!/test
</td>
</tr>
<tr>
<td>Changing Other Settings</td>
<td>
......
......@@ -33,7 +33,8 @@ import org.h2.message.Message;
//#endif
/**
* A data source for H2 database connections
* A data source for H2 database connections. It is a factory for XAConnection and Connection objects.
* This class is usually registered in a JNDI naming service.
*/
public class JdbcDataSource extends TraceObject implements
//#ifdef JDK14
......@@ -45,7 +46,7 @@ Serializable, Referenceable {
private transient JdbcDataSourceFactory factory;
private transient PrintWriter logWriter;
private int timeout;
private int loginTimeout;
private String user = "";
private String password = "";
private String url = "";
......@@ -54,6 +55,9 @@ Serializable, Referenceable {
org.h2.Driver.load();
}
/**
* Public constructor.
*/
public JdbcDataSource() {
initFactory();
int id = getNextId(TraceObject.DATA_SOURCE);
......@@ -69,37 +73,72 @@ Serializable, Referenceable {
factory = new JdbcDataSourceFactory();
}
/**
* Get the login timeout in seconds, 0 meaning no timeout.
*
* @return the timeout in seconds
*/
public int getLoginTimeout() throws SQLException {
debugCodeCall("getLoginTimeout");
return timeout;
return loginTimeout;
}
/**
* Set the login timeout in seconds, 0 meaning no timeout.
* The default value is 0.
* This value is ignored by this database.
*
* @param timeout the timeout in seconds
*/
public void setLoginTimeout(int timeout) throws SQLException {
debugCodeCall("setLoginTimeout", timeout);
this.timeout = timeout;
this.loginTimeout = timeout;
}
/**
* Get the current log writer for this object.
*
* @return the log writer
*/
public PrintWriter getLogWriter() throws SQLException {
debugCodeCall("getLogWriter");
return logWriter;
}
/**
* Set the current log writer for this object.
* This value is ignored by this database.
*
* @param out the log writer
*/
public void setLogWriter(PrintWriter out) throws SQLException {
debugCodeCall("setLogWriter(out)");
logWriter = out;
}
/**
* Open a new connection using the current URL, user name and password.
*
* @return the connection
*/
public Connection getConnection() throws SQLException {
debugCodeCall("getConnection");
return getJdbcConnection(user, password);
}
/**
* Open a new connection using the current URL and the specified user name and password.
*
* @param the user name
* @param the password
* @return the connection
*/
public Connection getConnection(String user, String password) throws SQLException {
debugCode("getConnection("+quote(user)+", "+quote(password)+");");
return getJdbcConnection(user, password);
}
public JdbcConnection getJdbcConnection(String user, String password) throws SQLException {
private JdbcConnection getJdbcConnection(String user, String password) throws SQLException {
debugCode("getJdbcConnection("+quote(user)+", "+quote(password)+");");
Properties info = new Properties();
info.setProperty("user", user);
......@@ -107,43 +146,79 @@ Serializable, Referenceable {
return new JdbcConnection(url, info);
}
/**
* Get the current URL.
*
* @return the URL
*/
public String getURL() {
debugCodeCall("getURL");
return url;
}
/**
* Set the current URL.
*
* @param url the new URL
*/
public void setURL(String url) {
debugCodeCall("setURL", url);
this.url = url;
}
public String getPassword() {
debugCodeCall("getPassword");
return password;
}
/**
* Set the current password
*
* @param password the new password.
*/
public void setPassword(String password) {
debugCodeCall("setPassword", password);
this.password = password;
}
/**
* Get the current password.
*
* @return the password
*/
public String getPassword() {
debugCodeCall("getPassword");
return password;
}
/**
* Get the current user name.
*
* @return the user name
*/
public String getUser() {
debugCodeCall("getUser");
return user;
}
/**
* Set the current user name.
*
* @param user the new user name
*/
public void setUser(String user) {
debugCodeCall("setUser", user);
this.user = user;
}
/**
* Get a new reference for this object, using the current settings.
*
* @return the new reference
*/
public Reference getReference() throws NamingException {
debugCodeCall("getReference");
String factoryClassName = JdbcDataSourceFactory.class.getName();
Reference ref = new Reference(getClass().getName(), factoryClassName, null);
ref.add(new StringRefAddr("url", getURL()));
ref.add(new StringRefAddr("user", getUser()));
ref.add(new StringRefAddr("url", url));
ref.add(new StringRefAddr("user", user));
ref.add(new StringRefAddr("password", password));
ref.add(new StringRefAddr("loginTimeout", String.valueOf(loginTimeout)));
return ref;
}
......
......@@ -39,6 +39,8 @@ public class JdbcDataSourceFactory implements ObjectFactory {
dataSource.setURL((String) ref.get("url").getContent());
dataSource.setUser((String) ref.get("user").getContent());
dataSource.setPassword((String) ref.get("password").getContent());
String s = (String) ref.get("loginTimeout").getContent();
dataSource.setLoginTimeout(Integer.parseInt(s));
return dataSource;
}
return null;
......
......@@ -54,8 +54,7 @@ public class TableFilter implements ColumnResolver {
private Row current;
private int state;
private ObjectArray joins;
// private TableFilter join;
private TableFilter join;
private boolean outerJoin;
private boolean foundOne;
......@@ -82,15 +81,11 @@ public class TableFilter implements ColumnResolver {
public void lock(Session session, boolean exclusive, boolean force) throws SQLException {
table.lock(session, exclusive, force);
for (int i = 0; joins != null && i < joins.size(); i++) {
getTableFilter(i).lock(session, exclusive, force);
if (join != null) {
join.lock(session, exclusive, force);
}
}
private TableFilter getTableFilter(int i) {
return (TableFilter) joins.get(i);
}
public PlanItem getBestPlanItem(Session session) throws SQLException {
PlanItem item;
if (indexConditions.size() == 0) {
......@@ -114,8 +109,7 @@ public class TableFilter implements ColumnResolver {
}
item = table.getBestPlanItem(session, masks);
}
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
setEvaluatable(join);
item.setJoinPlan(join.getBestPlanItem(session));
// TODO optimizer: calculate cost of a join: should use separate
......@@ -138,8 +132,7 @@ public class TableFilter implements ColumnResolver {
public void setPlanItem(PlanItem item) {
setIndex(item.getIndex());
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
if (item.getJoinPlan() != null) {
join.setPlanItem(item.getJoinPlan());
}
......@@ -158,8 +151,7 @@ public class TableFilter implements ColumnResolver {
}
}
}
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
if (SysProperties.CHECK && join == this) {
throw Message.getInternalError("self join");
}
......@@ -176,15 +168,13 @@ public class TableFilter implements ColumnResolver {
public void startQuery(Session session) throws SQLException {
this.session = session;
scanCount = 0;
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
join.startQuery(session);
}
}
public void reset() {
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
join.reset();
}
state = BEFORE_FIRST;
......@@ -233,23 +223,14 @@ public class TableFilter implements ColumnResolver {
}
if (!alwaysFalse) {
cursor = index.find(session, start, end);
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
join.reset();
}
}
} else {
// state == FOUND || LAST_ROW
// the last row was ok - try next row of the join
boolean found = joins != null;
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (!join.next()) {
found = false;
break;
}
}
if (found) {
if (join != null && join.next()) {
return true;
}
}
......@@ -290,13 +271,11 @@ public class TableFilter implements ColumnResolver {
if (state == FOUND && joinConditionOk) {
foundOne = true;
}
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
join.reset();
}
boolean doContinue = false;
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
if (!join.next()) {
doContinue = true;
}
......@@ -376,16 +355,13 @@ public class TableFilter implements ColumnResolver {
if (on != null) {
on.mapColumns(this, 0);
}
if (joins == null) {
this.joins = new ObjectArray();
joins.add(filter);
if (join == null) {
this.join = filter;
filter.outerJoin = outer;
if (on != null) {
filter.mapAndAddFilter(on);
}
} else {
int todoAddJoinNestedOrSameLevel;
TableFilter join = getTableFilter(0);
join.addJoin(filter, outer, on);
}
}
......@@ -394,15 +370,13 @@ public class TableFilter implements ColumnResolver {
on.mapColumns(this, 0);
addFilterCondition(on, true);
on.createIndexConditions(session, this);
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
join.mapAndAddFilter(on);
}
}
public TableFilter getJoin() {
int todoGetJoin;
return joins == null ? null : getTableFilter(0);
return join;
}
public boolean isJoinOuter() {
......@@ -495,8 +469,7 @@ public class TableFilter implements ColumnResolver {
}
public void removeJoin() {
int todoRemoveJoin;
this.joins = null;
this.join = null;
}
public Expression getJoinCondition() {
......@@ -517,8 +490,7 @@ public class TableFilter implements ColumnResolver {
public void setFullCondition(Expression condition) {
this.fullCondition = condition;
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
join.setFullCondition(condition);
}
}
......@@ -526,8 +498,7 @@ public class TableFilter implements ColumnResolver {
public void optimizeFullCondition(boolean fromOuterJoin) {
if (fullCondition != null) {
fullCondition.addFilterConditions(this, fromOuterJoin || outerJoin);
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
join.optimizeFullCondition(fromOuterJoin || outerJoin);
}
}
......@@ -540,8 +511,7 @@ public class TableFilter implements ColumnResolver {
if (joinCondition != null) {
joinCondition.setEvaluatable(filter, b);
}
for (int i = 0; joins != null && i < joins.size(); i++) {
TableFilter join = getTableFilter(i);
if (join != null) {
join.setEvaluatable(filter, b);
}
}
......
......@@ -47,6 +47,7 @@ import org.h2.test.db.TestTransaction;
import org.h2.test.db.TestTriggersConstraints;
import org.h2.test.db.TestTwoPhaseCommit;
import org.h2.test.db.TestView;
import org.h2.test.jdbc.TestCallableStatement;
import org.h2.test.jdbc.TestCancel;
import org.h2.test.jdbc.TestDataSource;
import org.h2.test.jdbc.TestDatabaseEventListener;
......@@ -148,16 +149,10 @@ java org.h2.test.TestAll timer
/*
Compile and include FullTextLucene.java
start writing javadocs for jdbcx package
toString() method to print something useful
getDisplaySize
"The display size gives you the limit for how many characters normally fit in a specified column"
start writing javadocs for jdbcx package
Feature request: file system that writes to two file systems (for replication)
Feature request: file system with background thread writing file system (all writes)
......@@ -602,6 +597,7 @@ Features of H2
new TestPgServer().runTest(this);
// jdbc
new TestCallableStatement().runTest(this);
new TestCancel().runTest(this);
new TestDatabaseEventListener().runTest(this);
new TestDataSource().runTest(this);
......
/*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.jdbc;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import org.h2.test.TestBase;
public class TestCallableStatement extends TestBase {
public void test() throws Exception {
deleteDb("callableStatement");
Connection conn = getConnection("preparedStatement");
testPrepare(conn);
conn.close();
}
private void testPrepare(Connection conn) throws Exception {
Statement stat = conn.createStatement();
CallableStatement call;
ResultSet rs;
stat.execute("CREATE TABLE TEST(ID INT, NAME VARCHAR)");
call = conn.prepareCall("INSERT INTO TEST VALUES(?, ?)");
call.setInt(1, 1);
call.setString(2, "Hello");
call.execute();
call = conn.prepareCall("SELECT * FROM TEST", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
rs = call.executeQuery();
rs.next();
check(1, rs.getInt(1));
check("Hello", rs.getString(2));
checkFalse(rs.next());
call = conn.prepareCall("SELECT * FROM TEST", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
rs = call.executeQuery();
rs.next();
check(1, rs.getInt(1));
check("Hello", rs.getString(2));
checkFalse(rs.next());
}
}
......@@ -63,6 +63,7 @@ public class TestMetaData extends TestBase {
checkFalse(rs.next());
rs = meta.getTables(null, Constants.SCHEMA_MAIN, null, new String[] { "TABLE" });
check(rs.getStatement() == null);
rs.next();
check(rs.getString("TABLE_NAME"), "TEST");
checkFalse(rs.next());
......
......@@ -53,6 +53,7 @@ public class TestResultSet extends TestBase {
testBlob();
testClob();
testAutoIncrement();
testSerialize();
conn.close();
......@@ -60,7 +61,11 @@ public class TestResultSet extends TestBase {
private void testColumnLength() throws Exception {
trace("Test ColumnLength");
int todo;
}
private void testSerialize() throws Exception {
int todo;
}
private void testLimitMaxRows() throws Exception {
......
......@@ -10,6 +10,7 @@ import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;
import org.h2.jdbc.JdbcStatement;
import org.h2.test.TestBase;
public class TestStatement extends TestBase {
......@@ -22,6 +23,7 @@ public class TestStatement extends TestBase {
if (config.jdk14) {
testSavepoint();
}
testConnectionRollback();
testStatement();
if (config.jdk14) {
testIdentity();
......@@ -29,6 +31,18 @@ public class TestStatement extends TestBase {
conn.close();
}
private void testConnectionRollback() throws Exception {
Statement stat = conn.createStatement();
conn.setAutoCommit(false);
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
conn.rollback();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
checkFalse(rs.next());
stat.execute("DROP TABLE TEST");
conn.setAutoCommit(true);
}
void testSavepoint() throws Exception {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
......@@ -86,6 +100,36 @@ public class TestStatement extends TestBase {
void testStatement() throws Exception {
Statement stat = conn.createStatement();
//#ifdef JDK14
check(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn.getHoldability());
conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
check(ResultSet.CLOSE_CURSORS_AT_COMMIT, conn.getHoldability());
//#endif
// ignored
stat.setCursorName("x");
// fixed return value
check(stat.getFetchDirection(), ResultSet.FETCH_FORWARD);
// ignored
stat.setFetchDirection(ResultSet.FETCH_REVERSE);
// ignored
stat.setMaxFieldSize(100);
check(0, stat.getFetchSize());
stat.setFetchSize(10);
check(10, stat.getFetchSize());
check(ResultSet.TYPE_FORWARD_ONLY, stat.getResultSetType());
Statement stat2 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
check(ResultSet.TYPE_SCROLL_SENSITIVE, stat2.getResultSetType());
check(ResultSet.HOLD_CURSORS_OVER_COMMIT, stat2.getResultSetHoldability());
check(ResultSet.CONCUR_UPDATABLE, stat2.getResultSetConcurrency());
check(0, stat.getMaxFieldSize());
check(!((JdbcStatement) stat2).isClosed());
stat2.close();
check(((JdbcStatement) stat2).isClosed());
ResultSet rs;
int count;
boolean result;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论