提交 b299be02 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 9d0af5f0
......@@ -34,7 +34,7 @@
</delete>
</target>
<target name="compile" depends="switchSourceAuto, resources, downloadServletJar, downloadLuceneJar">
<target name="compile" depends="switchSourceAuto, resources, download">
<javac destdir="bin" debug="true" debuglevel="lines,source" >
<classpath location="ext/servlet-api-2.4.jar" />
<classpath location="ext/lucene-core-2.2.0.jar" />
......@@ -60,20 +60,24 @@
<javac srcdir="bin" destdir="bin" debug="true" debuglevel="lines,source" includes="org/h2/**"/>
</target>
<target name="downloadServletJar" depends="init" unless="servlet.jar.present">
<target name="download" depends="init" unless="ext.present">
<get dest="ext/servlet-api-2.4.jar"
src="http://repo1.maven.org/maven2/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar" />
</target>
<target name="downloadLuceneJar" depends="init" unless="lucene.jar.present">
<get dest="ext/lucene-core-2.2.0.jar"
src="http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/2.2.0/lucene-core-2.2.0.jar" />
<get dest="ext/slf4j-api-1.5.0.jar"
src="http://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.5.0/slf4j-api-1.5.0.jar" />
</target>
<target name="init">
<mkdir dir="ext"/>
<available file="ext/servlet-api-2.4.jar" property="servlet.jar.present"/>
<available file="ext/lucene-core-2.2.0.jar" property="lucene.jar.present"/>
<condition property="ext.present">
<and>
<available file="ext/servlet-api-2.4.jar"/>
<available file="ext/lucene-core-2.2.0.jar"/>
<available file="ext/slf4j-api-1.5.0.jar"/>
</and>
</condition>
</target>
<target name="jar" depends="compile, manifest">
......
......@@ -51,6 +51,8 @@ Features
Compatibility</a><br />
<a href="#trace_options">
Using the Trace Options</a><br />
<a href="#other_logging">
Using Other Logging APIs</a><br />
<a href="#read_only">
Read Only Databases</a><br />
<a href="#database_in_zip">
......@@ -1026,6 +1028,34 @@ However, if the start file is read only, the database engine cannot delete the f
will always enable the trace mode when connecting.
</p>
<br /><a name="other_logging"></a>
<h2>Using Other Logging APIs</h2>
<p>
By default, this database uses its own native 'trace' facility. This facility is called 'trace' and not
'log' within this database to avoid confusion with the transaction log. Trace messages can be
written to both file and System.out. In most cases, this is sufficient, however sometimes
it is better to use the same facility as the application, for example Log4j. To do that, this
database support SLF4J.
</p>
<p>
<a href="http://www.slf4j.org">SLF4J</a> is a simple facade for various logging APIs
and allows to plug in the desired implementation at deployment time.
SLF4J supports implementations such as Logback, Log4j, Jakarta Commons Logging (JCL),
JDK 1.4 logging, x4juli, and Simple Log.
</p>
<p>
To enable SLF4J, set the file trace level to 4 in the database URL:
</p>
<pre>
jdbc:h2:~/test;TRACE_LEVEL_FILE=4
</pre>
<p>
Changing the log mechanism is not possible after the database is open, that means
executing the SQL statement SET TRACE_LEVEL_FILE 4 when the database is already open
will not have the desired effect. To use SLF4J, all required jar files need to be in the classpath.
If it does not work, check in the file &lt;database&gt;.trace.db for error messages.
</p>
<br /><a name="read_only"></a>
<h2>Read Only Databases</h2>
<p>
......
......@@ -53,7 +53,6 @@ Roadmap
<li>Automatic mode: jdbc:h2:auto: (embedded mode if possible, if not use server mode). Keep the server running until all have disconnected.
</li><li>Support OSGi: http://oscar-osgi.sourceforge.net, http://incubator.apache.org/felix/index.html
</li><li>Better space re-use in the files after deleting data: shrink the data file without closing the database (if the end of the file is empty)
</li><li>Pluggable tracing system
</li><li>Full outer joins
</li><li>Procedural language / script language (Javascript)
</li><li>Change LOB mechanism (less files, keep index of lob files, point to files and row, delete unused files earlier, maybe bundle files into a tar file)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -177,7 +177,7 @@ public abstract class Command implements CommandInterface {
session.unlockReadLocks();
}
}
if (trace.info()) {
if (trace.isInfoEnabled()) {
long time = System.currentTimeMillis() - startTime;
if (time > Constants.LONG_QUERY_LIMIT_MS) {
trace.info("long query: " + time);
......
......@@ -278,7 +278,7 @@ public abstract class Prepared {
}
void trace(long startTime, int count) throws SQLException {
if (session.getTrace().info()) {
if (session.getTrace().isInfoEnabled()) {
long time = System.currentTimeMillis() - startTime;
String params;
if (parameters.size() > 0) {
......
......@@ -371,7 +371,7 @@ public class SessionRemote implements SessionInterface, DataHandler {
* @param id the id of the operation
*/
public void traceOperation(String operation, int id) {
if (trace.debug()) {
if (trace.isDebugEnabled()) {
trace.debug(operation + " " + id);
}
}
......
......@@ -88,7 +88,7 @@ public class JdbcConnection extends TraceObject implements Connection {
public Statement createStatement() throws SQLException {
try {
int id = getNextId(TraceObject.STATEMENT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("Statement", TraceObject.STATEMENT, id, "createStatement()");
}
checkClosed();
......@@ -109,7 +109,7 @@ public class JdbcConnection extends TraceObject implements Connection {
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
try {
int id = getNextId(TraceObject.STATEMENT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("Statement", TraceObject.STATEMENT, id, "createStatement(" + resultSetType + ", " + resultSetConcurrency + ")");
}
checkClosed();
......@@ -132,7 +132,7 @@ public class JdbcConnection extends TraceObject implements Connection {
throws SQLException {
try {
int id = getNextId(TraceObject.STATEMENT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("Statement", TraceObject.STATEMENT, id,
"createStatement(" + resultSetType + ", " + resultSetConcurrency + ", " + resultSetHoldability + ")");
}
......@@ -155,7 +155,7 @@ public class JdbcConnection extends TraceObject implements Connection {
public PreparedStatement prepareStatement(String sql) throws SQLException {
try {
int id = getNextId(TraceObject.PREPARED_STATEMENT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("PreparedStatement", TraceObject.PREPARED_STATEMENT, id, "prepareStatement(" + quote(sql) + ")");
}
checkClosed();
......@@ -169,7 +169,7 @@ public class JdbcConnection extends TraceObject implements Connection {
PreparedStatement prepareAutoCloseStatement(String sql) throws SQLException {
try {
int id = getNextId(TraceObject.PREPARED_STATEMENT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("PreparedStatement", TraceObject.PREPARED_STATEMENT, id, "prepareStatement(" + quote(sql) + ")");
}
checkClosed();
......@@ -190,7 +190,7 @@ public class JdbcConnection extends TraceObject implements Connection {
public DatabaseMetaData getMetaData() throws SQLException {
try {
int id = getNextId(TraceObject.DATABASE_META_DATA);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("DatabaseMetaData", TraceObject.DATABASE_META_DATA, id, "getMetaData()");
}
checkClosed();
......@@ -290,7 +290,7 @@ public class JdbcConnection extends TraceObject implements Connection {
*/
public synchronized void setAutoCommit(boolean autoCommit) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("setAutoCommit(" + autoCommit + ");");
}
checkClosed();
......@@ -408,7 +408,7 @@ public class JdbcConnection extends TraceObject implements Connection {
*/
public void setReadOnly(boolean readOnly) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("setReadOnly(" + readOnly + ");");
}
checkClosed();
......@@ -515,7 +515,7 @@ public class JdbcConnection extends TraceObject implements Connection {
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
try {
int id = getNextId(TraceObject.PREPARED_STATEMENT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("PreparedStatement", TraceObject.PREPARED_STATEMENT, id, "prepareStatement(" + quote(sql) + ", " + resultSetType + ", " + resultSetConcurrency + ")");
}
checkClosed();
......@@ -717,7 +717,7 @@ public class JdbcConnection extends TraceObject implements Connection {
public CallableStatement prepareCall(String sql) throws SQLException {
try {
int id = getNextId(TraceObject.CALLABLE_STATEMENT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("CallableStatement", TraceObject.CALLABLE_STATEMENT, id, "prepareCall(" + quote(sql) + ")");
}
checkClosed();
......@@ -740,7 +740,7 @@ public class JdbcConnection extends TraceObject implements Connection {
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
try {
int id = getNextId(TraceObject.CALLABLE_STATEMENT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("CallableStatement", TraceObject.CALLABLE_STATEMENT, id, "prepareCall(" + quote(sql) + ", " + resultSetType + ", " + resultSetConcurrency + ")");
}
checkClosed();
......@@ -765,7 +765,7 @@ public class JdbcConnection extends TraceObject implements Connection {
int resultSetConcurrency, int resultSetHoldability) throws SQLException {
try {
int id = getNextId(TraceObject.CALLABLE_STATEMENT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("CallableStatement", TraceObject.CALLABLE_STATEMENT, id,
"prepareCall(" + quote(sql) + ", " + resultSetType + ", " + resultSetConcurrency + ", "
+ resultSetHoldability + ")");
......@@ -789,7 +789,7 @@ public class JdbcConnection extends TraceObject implements Connection {
public Savepoint setSavepoint() throws SQLException {
try {
int id = getNextId(TraceObject.SAVEPOINT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("Savepoint", TraceObject.SAVEPOINT, id, "setSavepoint()");
}
checkClosed();
......@@ -813,7 +813,7 @@ public class JdbcConnection extends TraceObject implements Connection {
public Savepoint setSavepoint(String name) throws SQLException {
try {
int id = getNextId(TraceObject.SAVEPOINT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("Savepoint", TraceObject.SAVEPOINT, id, "setSavepoint(" + quote(name) + ")");
}
checkClosed();
......@@ -876,7 +876,7 @@ public class JdbcConnection extends TraceObject implements Connection {
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
try {
int id = getNextId(TraceObject.PREPARED_STATEMENT);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("PreparedStatement", TraceObject.PREPARED_STATEMENT, id,
"prepareStatement(" + quote(sql) + ", " + resultSetType + ", " + resultSetConcurrency + ", "
+ resultSetHoldability + ")");
......@@ -901,7 +901,7 @@ public class JdbcConnection extends TraceObject implements Connection {
*/
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("prepareStatement(" + quote(sql) + ", " + autoGeneratedKeys + ");");
}
return prepareStatement(sql);
......@@ -920,7 +920,7 @@ public class JdbcConnection extends TraceObject implements Connection {
*/
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("prepareStatement(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");");
}
return prepareStatement(sql);
......@@ -939,7 +939,7 @@ public class JdbcConnection extends TraceObject implements Connection {
*/
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("prepareStatement(" + quote(sql) + ", " + quoteArray(columnNames) + ");");
}
return prepareStatement(sql);
......@@ -979,7 +979,7 @@ public class JdbcConnection extends TraceObject implements Connection {
int id = getNextId(TraceObject.CONNECTION);
setTrace(trace, TraceObject.CONNECTION, id);
this.user = ci.getUserName();
if (info()) {
if (isInfoEnabled()) {
trace.infoCode("Connection " + getTraceObjectName()
+ " = DriverManager.getConnection(" + quote(ci.getOriginalURL())
+ ", " + quote(user) + ", \"\")");
......
......@@ -115,7 +115,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
*/
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getTables(" + quote(catalog) + ", " + quote(schemaPattern) + ", " + quote(tableNamePattern)
+ ", " + quoteArray(types) + ");");
}
......@@ -199,7 +199,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
String tableNamePattern, String columnNamePattern)
throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getColumns(" + quote(catalog)+", "
+quote(schemaPattern)+", "
+quote(tableNamePattern)+", "
......@@ -277,7 +277,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
public ResultSet getIndexInfo(String catalog, String schema, String tableName, boolean unique, boolean approximate)
throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getIndexInfo(" + quote(catalog) + ", " + quote(schema) + ", " + quote(tableName) + ", "
+ unique + ", " + approximate + ");");
}
......@@ -339,7 +339,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
*/
public ResultSet getPrimaryKeys(String catalog, String schema, String tableName) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getPrimaryKeys("
+quote(catalog)+", "
+quote(schema)+", "
......@@ -507,7 +507,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
public ResultSet getProcedures(String catalog, String schemaPattern,
String procedureNamePattern) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getProcedures("
+quote(catalog)+", "
+quote(schemaPattern)+", "
......@@ -562,7 +562,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
String procedureNamePattern, String columnNamePattern)
throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getProcedureColumns("
+quote(catalog)+", "
+quote(schemaPattern)+", "
......@@ -708,7 +708,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
public ResultSet getColumnPrivileges(String catalog, String schema,
String table, String columnNamePattern) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getColumnPrivileges("
+quote(catalog)+", "
+quote(schema)+", "
......@@ -767,7 +767,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
*/
public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getTablePrivileges("
+quote(catalog)+", "
+quote(schemaPattern)+", "
......@@ -822,7 +822,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
public ResultSet getBestRowIdentifier(String catalog, String schema,
String tableName, int scope, boolean nullable) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getBestRowIdentifier("
+quote(catalog)+", "
+quote(schema)+", "
......@@ -882,7 +882,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
public ResultSet getVersionColumns(String catalog, String schema,
String tableName) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getVersionColumns("
+quote(catalog)+", "
+quote(schema)+", "
......@@ -939,7 +939,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
*/
public ResultSet getImportedKeys(String catalog, String schema, String tableName) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getImportedKeys("
+quote(catalog)+", "
+quote(schema)+", "
......@@ -1009,7 +1009,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
public ResultSet getExportedKeys(String catalog, String schema, String tableName)
throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getExportedKeys("
+quote(catalog)+", "
+quote(schema)+", "
......@@ -1086,7 +1086,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
String primarySchema, String primaryTable, String foreignCatalog,
String foreignSchema, String foreignTable) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getCrossReference("
+quote(primaryCatalog)+", "
+quote(primarySchema)+", "
......@@ -1155,7 +1155,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
public ResultSet getUDTs(String catalog, String schemaPattern,
String typeNamePattern, int[] types) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getUDTs("
+quote(catalog)+", "
+quote(schemaPattern)+", "
......@@ -1429,7 +1429,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* @return true
*/
public boolean supportsConvert(int fromType, int toType) {
if (debug()) {
if (isDebugEnabled()) {
debugCode("supportsConvert("+fromType+", "+fromType+");");
}
return true;
......@@ -2030,7 +2030,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* @return true if the type is not ResultSet.TYPE_SCROLL_SENSITIVE
*/
public boolean supportsResultSetConcurrency(int type, int concurrency) {
if (debug()) {
if (isDebugEnabled()) {
debugCode("supportsResultSetConcurrency("+type+", "+concurrency+");");
}
return type != ResultSet.TYPE_SCROLL_SENSITIVE;
......@@ -2448,7 +2448,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
public ResultSet getSuperTypes(String catalog, String schemaPattern,
String typeNamePattern) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getSuperTypes("
+quote(catalog)+", "
+quote(schemaPattern)+", "
......@@ -2476,7 +2476,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
public ResultSet getSuperTables(String catalog, String schemaPattern,
String tableNamePattern) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getSuperTables("
+quote(catalog)+", "
+quote(schemaPattern)+", "
......@@ -2503,7 +2503,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
String typeNamePattern, String attributeNamePattern)
throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getAttributes("
+quote(catalog)+", "
+quote(schemaPattern)+", "
......
......@@ -50,7 +50,7 @@ public class JdbcStatement extends TraceObject implements Statement {
public ResultSet executeQuery(String sql) throws SQLException {
try {
int id = getNextId(TraceObject.RESULT_SET);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id, "executeQuery(" + quote(sql) + ")");
}
checkClosed();
......@@ -132,7 +132,7 @@ public class JdbcStatement extends TraceObject implements Statement {
public boolean execute(String sql) throws SQLException {
try {
int id = getNextId(TraceObject.RESULT_SET);
if (debug()) {
if (isDebugEnabled()) {
debugCodeCall("execute", sql);
}
checkClosed();
......@@ -482,7 +482,7 @@ public class JdbcStatement extends TraceObject implements Statement {
*/
public void setEscapeProcessing(boolean enable) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("setEscapeProcessing("+enable+");");
}
checkClosed();
......@@ -637,7 +637,7 @@ public class JdbcStatement extends TraceObject implements Statement {
public ResultSet getGeneratedKeys() throws SQLException {
try {
int id = getNextId(TraceObject.RESULT_SET);
if (debug()) {
if (isDebugEnabled()) {
debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id, "getGeneratedKeys()");
}
checkClosed();
......@@ -674,7 +674,7 @@ public class JdbcStatement extends TraceObject implements Statement {
*/
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("executeUpdate("+quote(sql)+", "+autoGeneratedKeys+");");
}
return executeUpdate(sql);
......@@ -696,7 +696,7 @@ public class JdbcStatement extends TraceObject implements Statement {
*/
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("executeUpdate("+quote(sql)+", "+quoteIntArray(columnIndexes)+");");
}
return executeUpdate(sql);
......@@ -718,7 +718,7 @@ public class JdbcStatement extends TraceObject implements Statement {
*/
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("executeUpdate("+quote(sql)+", "+quoteArray(columnNames)+");");
}
return executeUpdate(sql);
......@@ -740,7 +740,7 @@ public class JdbcStatement extends TraceObject implements Statement {
*/
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("execute("+quote(sql)+", "+autoGeneratedKeys+");");
}
return execute(sql);
......@@ -762,7 +762,7 @@ public class JdbcStatement extends TraceObject implements Statement {
*/
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("execute("+quote(sql)+", "+quoteIntArray(columnIndexes)+");");
}
return execute(sql);
......@@ -784,7 +784,7 @@ public class JdbcStatement extends TraceObject implements Statement {
*/
public boolean execute(String sql, String[] columnNames) throws SQLException {
try {
if (debug()) {
if (isDebugEnabled()) {
debugCode("execute("+quote(sql)+", "+quoteArray(columnNames)+");");
}
return execute(sql);
......@@ -893,7 +893,7 @@ public class JdbcStatement extends TraceObject implements Statement {
* @param poolable the requested value
*/
public void setPoolable(boolean poolable) throws SQLException {
if (debug()) {
if (isDebugEnabled()) {
debugCode("setPoolable("+poolable+");");
}
}
......
......@@ -164,14 +164,14 @@ implements XADataSource, DataSource, ConnectionPoolDataSource, Serializable, Ref
* @return the connection
*/
public Connection getConnection(String user, String password) throws SQLException {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getConnection("+quote(user)+", "+quote(password)+");");
}
return getJdbcConnection(user, password);
}
private JdbcConnection getJdbcConnection(String user, String password) throws SQLException {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getJdbcConnection("+quote(user)+", "+quote(password)+");");
}
Properties info = new Properties();
......@@ -281,7 +281,7 @@ implements XADataSource, DataSource, ConnectionPoolDataSource, Serializable, Ref
*/
//## Java 1.4 begin ##
public XAConnection getXAConnection(String user, String password) throws SQLException {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getXAConnection("+quote(user)+", "+quote(password)+");");
}
int id = getNextId(XA_DATA_SOURCE);
......@@ -311,7 +311,7 @@ implements XADataSource, DataSource, ConnectionPoolDataSource, Serializable, Ref
*/
//## Java 1.4 begin ##
public PooledConnection getPooledConnection(String user, String password) throws SQLException {
if (debug()) {
if (isDebugEnabled()) {
debugCode("getPooledConnection("+quote(user)+", "+quote(password)+");");
}
return getXAConnection(user, password);
......
......@@ -60,7 +60,7 @@ implements ObjectFactory
*/
//## Java 1.4 begin ##
public synchronized Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception {
if (trace.debug()) {
if (trace.isDebugEnabled()) {
trace.debug("getObjectInstance obj=" + obj + " name=" + name + " nameCtx=" + nameCtx + " environment=" + environment);
}
Reference ref = (Reference) obj;
......
......@@ -252,7 +252,7 @@ implements XAConnection, XAResource, JdbcConnectionListener
*/
//## Java 1.4 begin ##
public int prepare(Xid xid) throws XAException {
if (debug()) {
if (isDebugEnabled()) {
debugCode("prepare("+quoteXid(xid)+");");
}
checkOpen();
......@@ -283,7 +283,7 @@ implements XAConnection, XAResource, JdbcConnectionListener
*/
//## Java 1.4 begin ##
public void forget(Xid xid) throws XAException {
if (debug()) {
if (isDebugEnabled()) {
debugCode("forget("+quoteXid(xid)+");");
}
}
......@@ -296,7 +296,7 @@ implements XAConnection, XAResource, JdbcConnectionListener
*/
//## Java 1.4 begin ##
public void rollback(Xid xid) throws XAException {
if (debug()) {
if (isDebugEnabled()) {
debugCode("rollback("+quoteXid(xid)+");");
}
try {
......@@ -317,7 +317,7 @@ implements XAConnection, XAResource, JdbcConnectionListener
*/
//## Java 1.4 begin ##
public void end(Xid xid, int flags) throws XAException {
if (debug()) {
if (isDebugEnabled()) {
debugCode("end("+quoteXid(xid)+", "+quoteFlags(flags)+");");
}
// TODO transaction end: implement this method
......@@ -339,7 +339,7 @@ implements XAConnection, XAResource, JdbcConnectionListener
*/
//## Java 1.4 begin ##
public void start(Xid xid, int flags) throws XAException {
if (debug()) {
if (isDebugEnabled()) {
debugCode("start("+quoteXid(xid)+", "+quoteFlags(flags)+");");
}
if (flags == TMRESUME) {
......@@ -367,7 +367,7 @@ implements XAConnection, XAResource, JdbcConnectionListener
*/
//## Java 1.4 begin ##
public void commit(Xid xid, boolean onePhase) throws XAException {
if (debug()) {
if (isDebugEnabled()) {
debugCode("commit("+quoteXid(xid)+", "+onePhase+");");
}
Statement stat = null;
......@@ -437,7 +437,7 @@ implements XAConnection, XAResource, JdbcConnectionListener
}
private XAException convertException(SQLException e) {
if (debug()) {
if (isDebugEnabled()) {
getTrace().debug("throw XAException("+e.getMessage()+");");
}
return new XAException(e.getMessage());
......
......@@ -14,9 +14,7 @@ import org.h2.util.StringUtils;
*/
public class Trace {
// TODO trace: java code generation does not always work
private TraceSystem traceSystem;
private TraceWriter traceWriter;
private String module;
private String lineSeparator;
......@@ -38,44 +36,45 @@ public class Trace {
public static final String SESSION = "session";
public static final String AGGREGATE = "aggregate";
public Trace(TraceSystem traceSystem, String module) {
this.traceSystem = traceSystem;
Trace(TraceWriter traceWriter, String module) {
this.traceWriter = traceWriter;
this.module = module;
this.lineSeparator = SysProperties.LINE_SEPARATOR;
}
public boolean info() {
return traceSystem.isEnabled(TraceSystem.INFO);
public boolean isInfoEnabled() {
return traceWriter.isEnabled(TraceSystem.INFO);
}
public boolean debug() {
return traceSystem.isEnabled(TraceSystem.DEBUG);
public boolean isDebugEnabled() {
return traceWriter.isEnabled(TraceSystem.DEBUG);
}
public void error(String s) {
traceSystem.write(TraceSystem.ERROR, module, s, null);
traceWriter.write(TraceSystem.ERROR, module, s, null);
}
public void error(String s, Throwable t) {
traceSystem.write(TraceSystem.ERROR, module, s, t);
traceWriter.write(TraceSystem.ERROR, module, s, t);
}
public void info(String s) {
traceSystem.write(TraceSystem.INFO, module, s, null);
traceWriter.write(TraceSystem.INFO, module, s, null);
}
public void debugCode(String java) {
traceSystem.write(TraceSystem.DEBUG, module, lineSeparator + "/**/" + java, null);
traceWriter.write(TraceSystem.DEBUG, module, lineSeparator + "/**/" + java, null);
}
public void infoCode(String java) {
traceSystem.write(TraceSystem.INFO, module, lineSeparator + "/**/" + java, null);
traceWriter.write(TraceSystem.INFO, module, lineSeparator + "/**/" + java, null);
}
public void infoSQL(String sql, String params, int count, long time) {
StringBuffer buff = new StringBuffer(sql.length() + 20);
buff.append(lineSeparator);
buff.append("/*SQL ");
buff.append("/*SQL");
boolean space = false;
if (params.length() > 0) {
// This looks like a bug, but it is intentional:
// If there are no parameters, the SQL statement is
......@@ -83,31 +82,37 @@ public class Trace {
// are appended at the end of the line. Knowing the size
// of the statement simplifies separating the SQL statement
// from the parameters (no need to parse).
buff.append("l:");
space = true;
buff.append(" l:");
buff.append(sql.length());
}
if (count > 0) {
space = true;
buff.append(" #:");
buff.append(count);
}
if (time > 0) {
space = true;
buff.append(" t:");
buff.append(time);
}
if (!space) {
buff.append(' ');
}
buff.append("*/");
buff.append(StringUtils.javaEncode(sql));
buff.append(params);
buff.append(';');
sql = buff.toString();
traceSystem.write(TraceSystem.INFO, module, sql, null);
traceWriter.write(TraceSystem.INFO, module, sql, null);
}
public void debug(String s) {
traceSystem.write(TraceSystem.DEBUG, module, s, null);
traceWriter.write(TraceSystem.DEBUG, module, s, null);
}
public void debug(String s, Throwable t) {
traceSystem.write(TraceSystem.DEBUG, module, s, t);
traceWriter.write(TraceSystem.DEBUG, module, s, t);
}
}
......@@ -60,12 +60,12 @@ public class TraceObject {
return ID[type]++;
}
protected boolean debug() {
return trace.debug();
protected boolean isDebugEnabled() {
return trace.isDebugEnabled();
}
protected boolean info() {
return trace.info();
protected boolean isInfoEnabled() {
return trace.isInfoEnabled();
}
protected Trace getTrace() {
......@@ -73,31 +73,31 @@ public class TraceObject {
}
protected void debugCodeAssign(String className, int type, int id, String value) {
if (trace.debug()) {
if (trace.isDebugEnabled()) {
trace.debugCode(className + " " + PREFIX[type] + id + " = " + getTraceObjectName() + "." + value + ";");
}
}
protected void debugCodeCall(String text) {
if (trace.debug()) {
if (trace.isDebugEnabled()) {
trace.debugCode(getTraceObjectName() + "." + text + "();");
}
}
protected void debugCodeCall(String text, long param) {
if (trace.debug()) {
if (trace.isDebugEnabled()) {
trace.debugCode(getTraceObjectName() + "." + text + "(" + param + ");");
}
}
protected void debugCodeCall(String text, String param) {
if (trace.debug()) {
if (trace.isDebugEnabled()) {
trace.debugCode(getTraceObjectName() + "." + text + "(" + quote(param) + ");");
}
}
protected void debugCode(String text) {
if (trace.debug()) {
if (trace.isDebugEnabled()) {
trace.debugCode(getTraceObjectName() + "." + text);
}
}
......
......@@ -17,6 +17,7 @@ import java.util.Date;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.util.ClassUtils;
import org.h2.util.FileUtils;
import org.h2.util.SmallLRUCache;
......@@ -27,10 +28,9 @@ import org.h2.util.SmallLRUCache;
* is possible to write after close was called, but that means for each write
* the log file will be opened and closed again (which is slower).
*/
public class TraceSystem {
public class TraceSystem implements TraceWriter {
public static final int OFF = 0, ERROR = 1, INFO = 2, DEBUG = 3;
// TODO log total and free memory from time to time
public static final int ADAPTER = 4;
// max file size is currently 64 MB,
// and then there could be a .old file of the same size
......@@ -52,6 +52,7 @@ public class TraceSystem {
private boolean closed;
private boolean manualEnabling = true;
private boolean writingErrorLogged;
private TraceWriter writer = this;
public static void traceThrowable(Throwable e) {
PrintWriter writer = DriverManager.getLogWriter();
......@@ -80,7 +81,7 @@ public class TraceSystem {
public Trace getTrace(String module) {
Trace t = (Trace) traces.get(module);
if (t == null) {
t = new Trace(this, module);
t = new Trace(writer, module);
traces.put(module, t);
}
return t;
......@@ -99,24 +100,33 @@ public class TraceSystem {
this.maxFileSize = max;
}
public int getMaxFileSize() {
return maxFileSize;
}
public void setLevelSystemOut(int l) {
levelSystemOut = l;
}
public int getLevelFile() {
return levelFile;
}
public int getLevelSystemOut() {
return levelSystemOut;
public void setLevelSystemOut(int level) {
levelSystemOut = level;
}
public void setLevelFile(int l) {
levelFile = l;
public void setLevelFile(int level) {
if (level == ADAPTER) {
String adapterClass = "org.h2.message.TraceWriterAdapter";
try {
writer = (TraceWriter) ClassUtils.loadSystemClass(adapterClass).newInstance();
} catch (Throwable e) {
e = Message.getSQLException(ErrorCode.CLASS_NOT_FOUND_1, new String[] { adapterClass }, e);
write(ERROR, Trace.DATABASE, adapterClass, e);
return;
}
String name = fileName;
if (name != null) {
if (name.endsWith(Constants.SUFFIX_TRACE_FILE)) {
name = name.substring(0, name.length() - Constants.SUFFIX_TRACE_FILE.length());
}
int idx = Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\'));
if (idx >= 0) {
name = name.substring(idx + 1);
}
writer.setName(name);
}
}
levelFile = level;
}
private String format(String module, String s) {
......@@ -125,18 +135,18 @@ public class TraceSystem {
}
}
void write(int l, String module, String s, Throwable t) {
if (l <= levelSystemOut) {
public void write(int level, String module, String s, Throwable t) {
if (level <= levelSystemOut) {
System.out.println(format(module, s));
if (t != null && levelSystemOut == DEBUG) {
t.printStackTrace();
}
}
if (fileName != null) {
if (l > levelFile) {
if (level > levelFile) {
enableIfRequired();
}
if (l <= levelFile) {
if (level <= levelFile) {
writeFile(format(module, s), t);
}
}
......@@ -195,7 +205,6 @@ public class TraceSystem {
return;
}
writingErrorLogged = true;
// TODO translate trace messages
SQLException se = Message.getSQLException(ErrorCode.TRACE_FILE_ERROR_2, new String[] { fileName, e.toString() },
e);
// print this error only once
......@@ -258,4 +267,7 @@ public class TraceSystem {
close();
}
public void setName(String name) {
}
}
/*
* Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.message;
/**
* The backend of the trace system must implement this interface. Two
* implementations are supported: the (default) native trace writer
* implementation that can write to a file and to system out, and an adapter
* that uses SLF4J (Simple Logging Facade for Java).
*/
interface TraceWriter {
/**
* Set the name of the database or trace object.
*/
void setName(String name);
/**
* Write a message.
*
* @param level the trace level
* @param module the name of the module
* @param s the message
* @param t the exception (may be null)
*/
void write(int level, String module, String s, Throwable t);
/**
* Check the given trace / log level is enabled.
*
* @param level the level
* @return true if the level is enabled
*/
boolean isEnabled(int level);
}
/*
* Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This adapter sends log output to SLF4J. SLF4J supports multiple
* implementations such as Logback, Log4j, Jakarta Commons Logging (JCL), JDK
* 1.4 logging, x4juli, and Simple Log. To use SLF4J, you need to add the
* required jar files to the classpath, and set the trace level to 4 when opening
* a database:
*
* <pre>
* jdbc:h2:&tilde;/test;TRACE_LEVEL_FILE=4
* </pre>
*
* The logger name is 'h2database'.
*/
public class TraceWriterAdapter implements TraceWriter {
private String name;
private Logger logger = LoggerFactory.getLogger("h2database");
public void setName(String name) {
this.name = name;
}
public boolean isEnabled(int level) {
switch (level) {
case TraceSystem.DEBUG:
return logger.isDebugEnabled();
case TraceSystem.INFO:
return logger.isInfoEnabled();
case TraceSystem.ERROR:
return logger.isErrorEnabled();
}
return false;
}
public void write(int level, String module, String s, Throwable t) {
if (isEnabled(level)) {
if (name != null) {
s = name + ":" + module + " " + s;
} else {
s = module + " " + s;
}
switch (level) {
case TraceSystem.DEBUG:
logger.debug(s, t);
break;
case TraceSystem.INFO:
logger.info(s, t);
break;
case TraceSystem.ERROR:
logger.error(s, t);
break;
}
}
}
}
......@@ -1111,10 +1111,11 @@ SET THROTTLE 200
SET {TRACE_LEVEL_FILE | TRACE_LEVEL_SYSTEM_OUT} int
","
Sets the trace level for file the file or system out stream.
Levels: 0=off, 1=error, 2=info, 3=debug.
Levels are: 0=off, 1=error, 2=info, 3=debug.
This setting is not persistent.
Admin rights are required to execute this command.
This setting can be appended to the database URL: jdbc:h2:test;TRACE_LEVEL_SYSTEM_OUT=3
To use SLF4J, append ;TRACE_LEVEL_FILE=4 to the database URL when opening the database.
","
SET TRACE_LEVEL_SYSTEM_OUT 3
"
......
......@@ -398,7 +398,7 @@ public class TableData extends Table implements RecordReader {
}
private void traceLock(Session session, boolean exclusive, String s) {
if (traceLock.debug()) {
if (traceLock.isDebugEnabled()) {
traceLock.debug(session.getId() + " " + (exclusive ? "exclusive write lock" : "shared read lock") + " " + s + " " + getName());
}
}
......
......@@ -160,14 +160,12 @@ java org.h2.test.TestAll timer
/*
test and document log_level_file=4
deactivate triggers during alter table (during re-creating a table)
improve javadocs
Pluggable tracing system
test japanese translation
upload jazoon
test case for out of memory (try to corrupt the database using out of memory)
......@@ -227,7 +225,8 @@ History:
for INSERT and UPDATE statements.
H2 Shell: DESCRIBE now supports an schema name.
A subset of the PostgreSQL 'dollar quoting' feature is now supported.
SLF4J is now supported by using adding TRACE_LEVEL_FILE=4
to the database URL.
Roadmap:
......
......@@ -106,6 +106,9 @@ public class Build extends BuildBase {
download("ext/lucene-core-2.2.0.jar",
"http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/2.2.0/lucene-core-2.2.0.jar",
"47b6eee2e17bd68911e7045896a1c09de0b2dda8");
download("ext/slf4j-api-1.5.0.jar",
"http://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.5.0/slf4j-api-1.5.0.jar",
"b2df265d02350ecfe87b6c1773c7c4fab2b33505");
}
private String getVersion() {
......
......@@ -508,4 +508,4 @@ informs negotiations collectively omissions trial nor qualify steward neither
worldwide everyone additions expense lawsuit checksums jazoon flashback
dieguez dfile mvn dversion dgroup dpackaging dartifact durl dpom pom
subpackages slowed deactivate throttled noindex expired arizona export
intentional knowing
intentional knowing jcl plug facade deployment logback confusion
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论