提交 9c942768 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 f15cb116
...@@ -14,11 +14,13 @@ import javax.naming.NamingException; ...@@ -14,11 +14,13 @@ import javax.naming.NamingException;
import javax.naming.Reference; import javax.naming.Reference;
import javax.naming.Referenceable; import javax.naming.Referenceable;
import javax.naming.StringRefAddr; import javax.naming.StringRefAddr;
//#ifdef JDK14
import javax.sql.ConnectionPoolDataSource; import javax.sql.ConnectionPoolDataSource;
import javax.sql.DataSource; import javax.sql.DataSource;
import javax.sql.PooledConnection; import javax.sql.PooledConnection;
import javax.sql.XAConnection; import javax.sql.XAConnection;
import javax.sql.XADataSource; import javax.sql.XADataSource;
//#endif
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.message.TraceObject; import org.h2.message.TraceObject;
...@@ -34,16 +36,20 @@ import org.h2.message.Message; ...@@ -34,16 +36,20 @@ import org.h2.message.Message;
* *
* @author Tom * @author Tom
*/ */
public class JdbcDataSource extends TraceObject implements XADataSource, DataSource, ConnectionPoolDataSource, Serializable, Referenceable { public class JdbcDataSource extends TraceObject implements
//#ifdef JDK14
XADataSource, DataSource, ConnectionPoolDataSource,
//#endif
Serializable, Referenceable {
private static final long serialVersionUID = 1288136338451857771L; private static final long serialVersionUID = 1288136338451857771L;
private transient JdbcDataSourceFactory factory = new JdbcDataSourceFactory(); private transient JdbcDataSourceFactory factory = new JdbcDataSourceFactory();
private transient PrintWriter logWriter; private transient PrintWriter logWriter;
private int timeout; private int timeout;
private String user; private String user = "";
private String password; private String password = "";
private String url; private String url = "";
public JdbcDataSource() { public JdbcDataSource() {
int id = getNextId(TraceObject.DATASOURCE); int id = getNextId(TraceObject.DATASOURCE);
...@@ -129,6 +135,7 @@ public class JdbcDataSource extends TraceObject implements XADataSource, DataSou ...@@ -129,6 +135,7 @@ public class JdbcDataSource extends TraceObject implements XADataSource, DataSou
return ref; return ref;
} }
//#ifdef JDK14
public XAConnection getXAConnection() throws SQLException { public XAConnection getXAConnection() throws SQLException {
debugCodeCall("getXAConnection"); debugCodeCall("getXAConnection");
int id = getNextId(XA_DATASOURCE); int id = getNextId(XA_DATASOURCE);
...@@ -150,21 +157,22 @@ public class JdbcDataSource extends TraceObject implements XADataSource, DataSou ...@@ -150,21 +157,22 @@ public class JdbcDataSource extends TraceObject implements XADataSource, DataSou
debugCode("getPooledConnection("+quote(user)+", "+quote(password)+");"); debugCode("getPooledConnection("+quote(user)+", "+quote(password)+");");
return getXAConnection(user, password); return getXAConnection(user, password);
} }
//#endif
//#ifdef JDK16 //#ifdef JDK16
/* /*
public <T> T unwrap(Class<T> iface) throws SQLException { public <T> T unwrap(Class<T> iface) throws SQLException {
throw Message.getUnsupportedException(); throw Message.getUnsupportedException();
} }
*/ */
//#endif //#endif
//#ifdef JDK16 //#ifdef JDK16
/* /*
public boolean isWrapperFor(Class<?> iface) throws SQLException { public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw Message.getUnsupportedException(); throw Message.getUnsupportedException();
} }
*/ */
//#endif //#endif
} }
...@@ -4,24 +4,25 @@ ...@@ -4,24 +4,25 @@
*/ */
package org.h2.jdbcx; package org.h2.jdbcx;
//#ifdef JDK14
import java.sql.Connection; import java.sql.Connection;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Properties; import java.util.Properties;
import javax.sql.ConnectionEvent; import javax.sql.ConnectionEvent;
import javax.sql.ConnectionEventListener; import javax.sql.ConnectionEventListener;
import javax.sql.XAConnection; import javax.sql.XAConnection;
import javax.transaction.xa.XAException; import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource; import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid; import javax.transaction.xa.Xid;
import org.h2.jdbc.JdbcConnection;
import org.h2.message.TraceObject;
import org.h2.util.ByteUtils; import org.h2.util.ByteUtils;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.jdbc.JdbcConnection;
//#endif
import org.h2.message.TraceObject;
//#ifdef JDK16 //#ifdef JDK16
/* /*
...@@ -29,8 +30,13 @@ import javax.sql.StatementEventListener; ...@@ -29,8 +30,13 @@ import javax.sql.StatementEventListener;
*/ */
//#endif //#endif
public class JdbcXAConnection extends TraceObject implements XAConnection, JdbcConnectionListener, XAResource { public class JdbcXAConnection extends TraceObject
//#ifdef JDK14
implements XAConnection, XAResource, JdbcConnectionListener
//#endif
{
//#ifdef JDK14
private JdbcDataSourceFactory factory; private JdbcDataSourceFactory factory;
private String url, user, password; private String url, user, password;
private JdbcConnection conn; private JdbcConnection conn;
...@@ -272,22 +278,22 @@ public class JdbcXAConnection extends TraceObject implements XAConnection, JdbcC ...@@ -272,22 +278,22 @@ public class JdbcXAConnection extends TraceObject implements XAConnection, JdbcC
} }
getTrace().debug("committed"); getTrace().debug("committed");
} }
//#endif
//#ifdef JDK16 //#ifdef JDK16
/* /*
public void addStatementEventListener(StatementEventListener listener) { public void addStatementEventListener(StatementEventListener listener) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
*/ */
//#endif //#endif
//#ifdef JDK16 //#ifdef JDK16
/* /*
public void removeStatementEventListener(StatementEventListener listener) { public void removeStatementEventListener(StatementEventListener listener) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
*/ */
//#endif //#endif
} }
...@@ -7,13 +7,19 @@ package org.h2.jdbcx; ...@@ -7,13 +7,19 @@ package org.h2.jdbcx;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.StringTokenizer; import java.util.StringTokenizer;
//#ifdef JDK14
import javax.transaction.xa.Xid; import javax.transaction.xa.Xid;
//#endif
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.message.TraceObject; import org.h2.message.TraceObject;
import org.h2.util.ByteUtils; import org.h2.util.ByteUtils;
public class JdbcXid extends TraceObject implements Xid { public class JdbcXid extends TraceObject
//#ifdef JDK14
implements Xid
//#endif
{
private static final String PREFIX = "XID"; private static final String PREFIX = "XID";
......
...@@ -4,15 +4,18 @@ ...@@ -4,15 +4,18 @@
*/ */
package org.h2.security; package org.h2.security;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.SQLException;
//#ifdef JDK14
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.security.Key; import java.security.Key;
import java.security.KeyFactory; import java.security.KeyFactory;
import java.security.KeyStore; import java.security.KeyStore;
...@@ -24,20 +27,18 @@ import java.security.cert.Certificate; ...@@ -24,20 +27,18 @@ import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec;
import java.sql.SQLException;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import javax.net.ServerSocketFactory; import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocket; import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.util.ByteUtils; import org.h2.util.ByteUtils;
import org.h2.util.FileUtils; import org.h2.util.FileUtils;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
//#endif
/** /**
* *
...@@ -70,6 +71,39 @@ public class SecureSocketFactory { ...@@ -70,6 +71,39 @@ public class SecureSocketFactory {
return factory; return factory;
} }
public Socket createSocket(InetAddress address, int port) throws SQLException, IOException {
Socket socket = null;
//#ifdef JDK14
setKeystore();
SSLSocketFactory f = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket secureSocket = (SSLSocket) f.createSocket(address, port);
if (ENABLE_ANONYMOUS_SSL) {
String[] list = secureSocket.getEnabledCipherSuites();
list = addAnonymous(list);
secureSocket.setEnabledCipherSuites(list);
}
socket = secureSocket;
//#endif
return socket;
}
public ServerSocket createServerSocket(int port) throws IOException, SQLException {
ServerSocket socket = null;
//#ifdef JDK14
setKeystore();
ServerSocketFactory f = SSLServerSocketFactory.getDefault();
SSLServerSocket secureSocket = (SSLServerSocket) f.createServerSocket(port);
if (ENABLE_ANONYMOUS_SSL) {
String[] list = secureSocket.getEnabledCipherSuites();
list = addAnonymous(list);
secureSocket.setEnabledCipherSuites(list);
}
socket = secureSocket;
//#endif
return socket;
}
//#ifdef JDK14
private static byte[] getBytes(String hex) throws SQLException { private static byte[] getBytes(String hex) throws SQLException {
return ByteUtils.convertStringToBytes(hex); return ByteUtils.convertStringToBytes(hex);
} }
...@@ -178,18 +212,6 @@ public class SecureSocketFactory { ...@@ -178,18 +212,6 @@ public class SecureSocketFactory {
} }
} }
public ServerSocket createServerSocket(int port) throws IOException, SQLException {
setKeystore();
ServerSocketFactory f = SSLServerSocketFactory.getDefault();
SSLServerSocket socket = (SSLServerSocket) f.createServerSocket(port);
if (ENABLE_ANONYMOUS_SSL) {
String[] list = socket.getEnabledCipherSuites();
list = addAnonymous(list);
socket.setEnabledCipherSuites(list);
}
return socket;
}
private String[] addAnonymous(String[] list) { private String[] addAnonymous(String[] list) {
String[] newList = new String[list.length + 1]; String[] newList = new String[list.length + 1];
System.arraycopy(list, 0, newList, 1, list.length); System.arraycopy(list, 0, newList, 1, list.length);
...@@ -197,18 +219,6 @@ public class SecureSocketFactory { ...@@ -197,18 +219,6 @@ public class SecureSocketFactory {
return newList; return newList;
} }
public Socket createSocket(InetAddress address, int port) throws SQLException, IOException {
setKeystore();
SSLSocketFactory f = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket) f.createSocket(address, port);
if (ENABLE_ANONYMOUS_SSL) {
String[] list = socket.getEnabledCipherSuites();
list = addAnonymous(list);
socket.setEnabledCipherSuites(list);
}
return socket;
}
// private void listCipherSuites(SSLServerSocketFactory f) { // private void listCipherSuites(SSLServerSocketFactory f) {
// String[] def = f.getDefaultCipherSuites(); // String[] def = f.getDefaultCipherSuites();
// for(int i=0; i<def.length; i++) { // for(int i=0; i<def.length; i++) {
...@@ -219,5 +229,6 @@ public class SecureSocketFactory { ...@@ -219,5 +229,6 @@ public class SecureSocketFactory {
// System.out.println("supported = " + sup[i]); // System.out.println("supported = " + sup[i]);
// } // }
// } // }
//#endif
} }
...@@ -80,7 +80,7 @@ public class OdbcServer implements Service { ...@@ -80,7 +80,7 @@ public class OdbcServer implements Service {
if(allowOthers) { if(allowOthers) {
return true; return true;
} }
return socket.getInetAddress().isLoopbackAddress(); return NetUtils.isLoopbackAddress(socket);
} }
public void start() throws SQLException { public void start() throws SQLException {
......
...@@ -27,6 +27,7 @@ import org.h2.engine.ConnectionInfo; ...@@ -27,6 +27,7 @@ import org.h2.engine.ConnectionInfo;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.value.DataType;
/** /**
* @author Thomas * @author Thomas
...@@ -645,7 +646,7 @@ public class OdbcServerThread implements Runnable { ...@@ -645,7 +646,7 @@ public class OdbcServerThread implements Runnable {
return sqlType; return sqlType;
case Types.TINYINT: case Types.TINYINT:
case Types.BIT: case Types.BIT:
case Types.BOOLEAN: case DataType.TYPE_BOOLEAN:
return Types.INTEGER; return Types.INTEGER;
case Types.BIGINT: case Types.BIGINT:
case Types.BINARY: case Types.BINARY:
......
...@@ -108,7 +108,7 @@ public class TcpServer implements Service { ...@@ -108,7 +108,7 @@ public class TcpServer implements Service {
if(allowOthers) { if(allowOthers) {
return true; return true;
} }
return socket.getInetAddress().isLoopbackAddress(); return NetUtils.isLoopbackAddress(socket);
} }
public void start() throws SQLException { public void start() throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论