com.mckoi.database.jdbcserver

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » mckoi » com.mckoi.database.jdbcserver 
com.mckoi.database.jdbcserver
com.mckoi.database.jdbcserver - Server and embedded-database classes

Implementation of the DatabaseInterface interface, including classes to handle local (embedded) mode and remote (client/server) mode.

See DatabaseInterface.

Local (Embedded) mode

When accessing a local database, the client uses an instance of LocalDatabaseInterface (as set up while Establishing a Connection) to directly access the underlying database. See Local Queries.

Remote (Client/Server) mode

When accessing a remote database, requests in the client are directed to an instance of JDBCDatabaseInterface (as set up while Establishing a Connection) to send the requests over a TCP connection to the database server. The server uses an instance of LocalDatabaseInterface to execute SQL statements in local mode on behalf of the client. See Remote Queries.

Local Queries

When an application is accessing a local database, or when considering query processing within the database server, SQL queries all go through LocalDatabaseInterface.execQuery. This method uses com.mckoi.database.DatabaseSystem.execute to execute the execQuery method (see Query Execution) of the contained JDBCDatabaseInterface in the first available WorkerThread. The calling thread waits for the WorkerThread to finish and return a QueryResponse, which is used by the caller to set up a MResultSet.

Remote Queries

When an application is running in remote mode, SQL queries are processed by the private ConnectionThread class within
com.mckoi.jdbc.RemoteDatabaseInterface. The executeQuery method in this class writes the sql query string to the socket attached to the server and returns an integer ID for that sql request. This is followed by a call to the getCommand method, which blocks until it times out or until it gets a reply from the server for the right ID. If a reply is received, the first byte is decoded as a status byte. On success, an inner-class instance of QueryResponse is returned; on error, error info is read from the response and used to create and throw an exception.

Data is written to the server in the calling thread. There is a separate thread (an instance of the private class RemoteDatabaseInterface.ConnectionThread in RemoteDatabaseInterface) to read the data coming back from the server, which is placed into a buffer where it can be accessed by other threads.

Query Execution

Queries in local mode and queries handled by the database server are both processed by JDBCDatabaseInterface.execQuery. This method always runs in a WorkerThread. The execQuery method takes these steps to execute the query:
  • Set user and connection data into the WorkerThread.
  • Output debug log info.
  • Record start time.
  • Parse sql statement into statement_tree, check cache.
  • Bind values for query parameters.
  • Prepare all expression in statement tree.
  • Convert to instance of some Statement subclass (such as Insert or Delete.) These are all in the package com.mckoi.database.interpret.
  • Set up locking.
  • Finish preparing statement.
  • Get list of tables to read and write.
  • Lock tables.
  • Evaluate the Statement using Statement.evaluate. This is different for each different type of Statement.
  • Place results into result set cache.
  • Unlock tables.
  • Check autoCommit, do commit or rollback if set.
  • Record end time.
  • Return QueryResponse info (an instance of the private class JDIQueryResponse in JDBCDatabaseInterface).

Service Initialization

After the database server has been started and initialized its database, it begins listening for client connections. This happens in TCPServer.start. The server creates a ConnectionPoolServer, either a SingleThreadedConnectionPoolServer (when running in single-thead mode) or a MultiThreadedConnectionPoolServer (when running in multi-thread mode). The start method starts a listener thread and then returns.

The server listener thread sits in a loop blocked waiting for new connections. When a new connection is accepted, the server creates a new JDBCDatabaseInterface for that connection, wraps it in a TCPJDBCServerConnection, and adds that to the ConnectionPoolServer.

Client Requests

In single-thread mode, the SingleThreadedConnectionPoolServer handles all client reads in a single thread. For each connection with a request, it calls TCPJDBCServerConnection.processRequest on that connection, using com.mckoi.database.DatabaseSystem.execute to execute it in a WorkerThread.

In multi-thread mode, the MultiThreadedConnectionPoolServer starts a separate thread to handle reads for each connection. Each thread blocks until it has a request available, then calls TCPJDBCServerConnection.processRequest on that connection, using com.mckoi.database.DatabaseSystem.execute to execute it in a WorkerThread.

In either single-thread or multi-thread mode, client requests end up getting passed to TCPJDBCServerConnection.processRequest. This method reads the command data, then calls JDBCProcessor.processJDBCCommand with those bytes. That method calls JDBCProcessor.processQuery, which looks at the first byte of the requests to see what it is. If the request type is a database query (as opposed to retrieval of part of a ResultSet), it creates a SQLQuery from the data and calls execQuery on its JDBCDatabaseInterface (see Query Execution above). The result is encoded as a QueryResponse, which is converted back to bytes and written back to the client. Note that this is all running in a WorkerThread, so the call to DatabaseInterface.execQuery is in a WorkerThread, as required.

If there is an exception during processing of a client request, the message and traceback for the exception are encoded and returned to the client, which recognizes the packet as an exception, decodes the data on its side, and throws an exception in the client.

Java Source File NameTypeComment
AbstractJDBCDatabaseInterface.javaClass An abstract implementation of JDBCDatabaseInterface that provides a connection between a single DatabaseConnection and a DatabaseInterface implementation.

This receives database commands from the JDBC layer and dispatches the queries to the database system.

ConnectionPoolServer.javaInterface An interface for the connection pool for a server.
DefaultLocalBootable.javaClass A bootable object that filters through to a JDBCDatabaseInterface but is thread-safe and multi-threaded.
JDBCDatabaseInterface.javaClass An implementation of jdbc.DatabaseInterface on the server-side.

This receives database commands and dispatches them to the database system.

JDBCProcessor.javaClass This processes JDBC commands from a JDBC client and dispatches the commands to the database.
MultiThreadedConnectionPoolServer.javaClass A multi-threaded implementation of a connection pool server.
ServerConnection.javaInterface A server side connection with a client.
SingleThreadedConnectionPoolServer.javaClass A generic database server class that provides a thread that dispatches commands to the underlying database.
StreamJDBCServerConnection.javaClass A generic JDBC stream protocol server that reads JDBC commands from a stream from each connection and dispatches the commands appropriately.
TCPJDBCServerConnection.javaClass A ServerConnection that processes JDBC queries from a client from a TCP Socket.
TCPServer.javaClass A TCP/IP socket server that opens a single port and allows JDBC clients to connect through the port to talk with the database.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.