1 ? ? ?数据库服务器连接
主要用于描述客户端是如何与数据库服务器建立连接,并且是如何执行sql语句的。
1.1 ? ? ?客户端连接处理(JDBCDriver)
1.1.1 ? ? 描述
(1) ? ? ? 客户端通过JDBCDriver类创建JDBCConnection建立连接,最终通过ClientConnectionHttp、ClientConnction类创建一个与服务器类Server的socket连接。
(2) ? ? ? 上文已经描述了数据服务器启动的时候通过Server类、HsqlSoketFactory类创建了一个ServerSocket同时,通过accept方法循环监听客户端发起的请求。
(3) ? ? ? 当Server接收到客户端的请求时创建一个新的线程同时将该线程加入到线程组中,从代码看是创建了一个ServerConnection此类实现了runable接口。
此类的run方法实现了接收到请求后的具体处理。
?
核心类是ServerConnection类,下面是对ServerConnection类的详细描述。
1.1.2 ? ? JDBCDriver
public Connection connect(String url, Properties info) throws SQLException { if (url.regionMatches(true, 0, DatabaseURL.S_URL_INTERNAL, 0, DatabaseURL.S_URL_INTERNAL.length())) { JDBCConnection conn = (JDBCConnection) threadConnection.get(); if (conn == null) { returnnull; } return conn; } return getConnection(url, info);//此方法实现对JDBCConnectio类的创建 }
?
1.1.3 ? ? JDBCConnection
? ??
public JDBCConnection(HsqlProperties props) throws SQLException { String user = props.getProperty("user"); String password = props.getProperty("password"); String connType = props.getProperty("connection_type"); String host = props.getProperty("host"); int port = props.getIntegerProperty("port", 0); String path = props.getProperty("path"); String database = props.getProperty("database"); boolean isTLS = (connType == DatabaseURL.S_HSQLS || connType == DatabaseURL.S_HTTPS); boolean isTLSWrapper = props.isPropertyTrue(HsqlDatabaseProperties.url_tls_wrapper, false); isTLSWrapper &= isTLS; if (user == null) { user = "SA"; } if (password == null) { password = ""; } Calendar cal = Calendar.getInstance(); int zoneSeconds = HsqlDateTime.getZoneSeconds(cal); try { if (DatabaseURL.isInProcessDatabaseType(connType)) { /** * @todo- fredt - this should be the only static reference to * a core class (apart form references to the Type package) * from the jdbc package - we might make it dynamic */ sessionProxy = DatabaseManager.newSession(connType, database, user, password, props, null, zoneSeconds); } elseif (connType == DatabaseURL.S_HSQL || connType == DatabaseURL.S_HSQLS) { sessionProxy = new ClientConnection(host, port, path, database, isTLS, isTLSWrapper, user, password, zoneSeconds); isNetConn = true; } elseif (connType == DatabaseURL.S_HTTP || connType == DatabaseURL.S_HTTPS) { sessionProxy = new ClientConnectionHTTP(host, port, path, database, isTLS, isTLSWrapper, user, password, zoneSeconds); isNetConn = true; } else { // alias: type not yet implemented throw JDBCUtil.invalidArgument(connType); } sessionProxy.setJDBCConnection(this); connProperties = props; clientProperties = sessionProxy.getClientProperties(); if (connProperties != null) { isCloseResultSet = connProperties.isPropertyTrue( HsqlDatabaseProperties.url_close_result, false); isUseColumnName = connProperties.isPropertyTrue( HsqlDatabaseProperties.url_get_column_name, true); }