SimpleORM – working with multiple db connections

Share

In a recent project I had to handle with two simultaneous DB connections using SimpleORM. As you probably know SimpleORM, according with the official web site, is “a full featured Java object relational mapping system that avoids exotic technologies such as byte code generation [more]”. After spending some time in searching more info about how to implement the mechanism with SimpleORM I’ve decided to create my own mechanism.

Context:   I have a temporary table (called X_TBL) from a temporary DB  (called X_DB_TEMP)  and the same table into another DB (called X_DB).

Scenario:  Synchronize and process the records from the two tables, meaning: load records from temporary, process them and insert them into the second DB. Because I had to process a large number of records I’ve decided to split the records in small parts and process them separately.

Below you will find the most significant parts of code:

// X_DB_TEMP connection Handler
public class DBConnectionHandler1 implements Runnable {
   private Connection connection; // X_DB_TEMP Connection
 
   public void run() {
      SConnection.attach(connection, Thread.currentThread()
                 .getName());
      SConnection.begin();
      // ...
      // take a defined number of records and process them
      List records;
      Thread thread = new Thread(new DBConnectionHandler2(records));
      thread.start();
      thread.join();
      // ...
     SConnection.commit();
     SConnection.detachWithoutClosing();
   }
}
// X_DB connection Handler
public class DBConnectionHandler2 implements Runnable {
   private Connection connection;
   public DBConnectionHandler2 (List records) { // .... }
   public void run() {
      SConnection.attach(connection, Thread.currentThread()
                   .getName());
      SConnection.begin();
      // process records
      SConnection.commit();
      SConnection.detachWithoutClosing();
   }
}

And the main class

public class Tester {
   public void main(String args[]){
      // start the first DB Connection handler
      Thread thread = new Thread(new DBConnectionHandler1());
      thread.start();
   }
}

Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.

2 thoughts on “SimpleORM – working with multiple db connections”
  • Ciprian Radu says:

    You mistyped implements 😉

    Surely you must agree that you don’t do any parallel work. The work of thread 2 is serialized after the work of the first thread. With join() you merely wait for the second thread to finish its job and then you carry on.

    September 14, 2009 at 9:10 am
  • Laurentiu Ciovica says:

    Hi Ciprian,

    Thank you for your remark regarding the mistyped “implements” word.
    I do not think i mentioned in the post about parallel work :).
    I do not think I can do parallel processing with SimpleORM, probably from version 3.x+.
    Perhaps you are confused by the statement “simultaneous DB connections”. Surely you must agree that at a given time there are two simultaneous open connections to two different databases.
    If you have another approach please fell free to add a new post or a comment to this post.

    Thank you!
    All the best,
    Laurentiu C.

    September 14, 2009 at 10:36 am

Comments are closed.

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close