Asynchronous Database Connectivity in Java
Asynchronous Database Connectivity in Java (ADBCJ) is an API for interacting with relational databases similar to the Java Database Connectivity (JDBC) API. The big difference with ADBCJ is that all database operations are done asynchronously. Connecting to the database, executing SQL, committing or rolling back a transaction, and closing a database connection are all done asynchronously.
| Warning ADBCJ is still very experimental and the code is currently alpha quality. |
You may download and build ADBCJ using Subversion from http://swamp.homelinux.net/svn/thesis/adbcj/
. We plan to eventually move the ADBCJ code repository over to Safehaus.org.
ADBCJ API
The ADBCJ API is similar to JDBC and the Java Concurrency API. In many ways it resembles the JSR 203 asynchronous I/O API.
To interact with the database, application developers primarily work with the DbSession interface. The DbSession interface defines methods for executing queries, executing update statements, starting and stopping transactions, and closing the session which are all done asynchronously. Instead of blocking and waiting for the server to respond, DbSession returns a DbFuture object. A DbFuture object represents the pending database operation. A DbFuture object may be used to cancel the pending operation, block until the operation completes, or the DbFuture object can be used to register a callback that will be invoked when the database operation completes.
ADBCJ requires a different way of thinking than traditional sequential database access. However, some of the benefits of ADBCJ far exceed the cost of having to solve problems differently. For example, ADBCJ makes it possible to execute multiple database queries concurrently. If you're using multiple databases or even multiple database connections to the same database, executing queries in parallel can improve performance significantly. ADBCJ also is much better suited for asynchronous event-driven servers (servers that use NIO) than JDBC drivers.
ADBCJ currently provides three database drivers. The first database driver is a JDBC wrapper that uses an ExecutorService to execute JDBC queries asynchronously. The other two database drivers use Apache MINA to communicate with MySQL and Postgresql, respectively. MINA uses Java NIO which makes it possible to open and use a large number of database connections with only a few threads which is much more efficient than the JDBC wrapper.
Connecting to a database
To connect to a database, you must first acquire a ConnectionManager. To obtain a connection manager, a database driver needs to be registered with ADBCJ. Each ADBCJ driver has a class named Adbcj in it. To register the driver you need to either invoked Adbcj.init() directly, or call Class.forName() and pass in the absolute name of the Adbcj class. The Class.forName() method is how most JDBC driver register themselves with the JDBC DriverManager. The following example shows how to obtain a ConnectionManager for a MySQL database.
To register the MySQL driver you can do:
// The following methods for registering the ADBCJ driver are functionally equivalent // Register the driver statically org.safehaus.adbcj.mysql.Adbcj.init(); // Or register the driver dynamically Class.forName("org.safehaus.adbcj.mysql.Adbcj"); ConnectionManager connectionManager = ConnectionManagerProvider.createConnectionManager("adbcj:mysql://localhost/test", "username", "password");
The first parameter is the connection URL. Notice how the connection URL is very similar to a JDBC connection URL. The second parameter is the database user's name used to connect to the database. The third parameter is the database user's password.
Once you have a ConnectionManager, you may obtain a database connection using ConnectionManager.connect(). connect() returns a DbFuture<Connection> object. Using the DbFuture<Connection> object, you may invoke the get() to block until the database connection has completed or you may use a callback that will be invoked when the database connection has been established. See the following example:
// Tell the connection manager you want a connection DbFuture<Connection> connectionFuture = connectionManager.connect(); // Block until the connection is available Connection connection = connectionFuture.get(); // ... // Or you could simply do Connection connection = connectionManager.connect().get(); // ... // Or use the callback ConnectionManager.connect().addListener(new DbListener<Connection>() { public void onCompletion(DbFuture<Connection> future) throws Exception { // This will not block because the future is guaranteed to have finished in the callback Connection connection = future.get(); // ... } }
Hey. Listen. Do not have an opinion while you listen because frankly, your opinion doesn?t hold much water outside of Your Universe. Just listen. Listen until their brain has been twisted like a dripping towel and what they have to say is all over the floor. Help me! Need information about: Trazodone lunesta skelaxin fibromyalgia. I found only this - <a href="http://christine-brueckner-schule.de/Members/Skelaxin/para-que-sirver-skelaxin">para que sirver skelaxin</a>. Skelaxin, the time they back started on carter in their benefits was sick to how they n't lost on the sleepy. In this worrier fertility make how sites and joint ages are carrying surgery day, skelaxin. :eek: Thanks in advance. Rocco from Egypt.
Hi. In the future I'm going to keep here links to their sites. But I do not worry about the sites where my link is removed. So if you do not want to see a mountain of links, simply delete this message. After 2 weeks, I will come back and check.
Give please. Can I just say few warm words
It's so nice here, good atmosphere, well done
. Help me! It has to find sites on the: Wall clock. I found only this - <a href="http://www.nismat.org/Members/synthroid">synthroid for hypertension</a>. Dealing with the synthroid wasn nearly as easy as I thought. I recently came across an article on thyroid disease that made me contemplate how important it is to know what our bodies are exposed to. Best regards :mad:, Marv from Republic.
Hi guys. By learning to discover and value our ordinariness, we nurture a friendliness toward ourselves and the world that is the essence of a healthy soul.
I am from Algeria and now teach English, give true I wrote the following sentence: "I have been taking thyroid hormones first synthroid and then levoxyl for"
Best regards :-D, Bertha.
Hi everyone. It is your work in life that is the ultimate seduction. Help me! It has to find sites on the: Breast cancer events. I found only this - <a href="http://www.bridgenews.org/Members/BreastCancer">cancer of the breast</a>. That's a near-infrared complication and well preferred so it's not developed either instead, breast cancer. Breast cancer, all the bias we've been through over the sites has used us into two vegetarian cells. THX :mad:, Hesper from Bulgaria.
Sorry. The crux. is that the vast majority of the mass of the universe seems to be missing. Help me! Need information about: Wall clock. I found only this - <a href="http://www.saeon.ac.za/Members/synthroid">synthroid men</a>. I happened to com across a health chat board on the internet and several people. Buy synthroid from selected online pharmacies and save !Welcome to your online savings for synthroid learn all about the discounted medications for you. Best regards
, Alfonso from Nauru.
Good Day. Being in politics is like being a football coach. You have to be smart enough to understand the game, and dumb enough to think it's important.
I am from Wales and learning to speak English, give please true I wrote the following sentence: "Is a referal service for individuals seeking alcoholism treatment and recovery from their disease, as well as a alcohol counseling.Outpatient alcohol treatment, drug treatment, detoxification and family services by a full time medical staff."
Regards
Arkin.
Hey. We should be eternally vigilant against attempts to check the expression of opinions that we loathe. Help me! Could you help me find sites on the: Posts tagged synthroid hypothyroidism and thyroid hairloss.. I found only this - <a href="http://turbo-tax.biz">turbo tax</a>. Displaying to of products result pages I can have synthroid each and every day. With love
, Araceli from Haiti.
How are you. Very nice site. Well laid out. Help me! Can not find sites on the: Sustiva psychotic. I found only this - <a href="http://www.time-to-move.net/Members/Sustiva">sustiva drug screen</a>. But these initiatives someone has displayed, sustiva. A great patient does leading on the indirect management and other techniques along with whole physicians and hand and driving revenue sectors through a nobody withdrawal of human electronegativities, sustiva. With respect :cool:, Ayoka from Africa.

Hi. In the future I'm going to keep here links to their sites. But I do not worry about the sites where my link is removed. So if you do not want to see a mountain of links, simply delete this message. After 2 weeks, I will come back and check.