[Biojava-dev] BioSQLRichSequenceDB and BioSQLBioEntryDB

mark.schreiber at novartis.com mark.schreiber at novartis.com
Mon Jan 23 22:35:46 EST 2006


So I should be able to get atomic transactions by doing this...

Session sess = factory.openSession();
Transaction tx;
RichObjectFactory.connectToHibernate(session); // bind BioJavaX to the 
hibernate session
RichSequenceDB db = new BioSQLRichSequenceDB(session);

RichSequence seq = ... //make a RichSequence

try {
     tx = sess.beginTransaction();
     //do something the the DB
     db.addSequence(seq1);
     tx.commit();
 }
 catch (Exception e) {
     if (tx!=null) tx.rollback();
     throw e;
 }
 finally {
     sess.close();
 }





"Richard HOLLAND" <hollandr at gis.a-star.edu.sg>
Sent by: biojava-dev-bounces at portal.open-bio.org
01/24/2006 11:22 AM

 
        To:     Mark Schreiber/GP/Novartis at PH
        cc:     biojava-dev at biojava.org
        Subject:        RE: [Biojava-dev] BioSQLRichSequenceDB and BioSQLBioEntryDB


All BJX needs is a Hibernate session. By default, Hibernate
auto-commits, but you can wrap any part of your application in code like
this to make it transactional (example from the Hibernate Session
javadocs):

 Session sess = factory.openSession();
 Transaction tx;
 try {
     tx = sess.beginTransaction();
     //do some work
     ...
     tx.commit();
 }
 catch (Exception e) {
     if (tx!=null) tx.rollback();
     throw e;
 }
 finally {
     sess.close();
 }
 

So BJX doesn't need to worry about transactions - its entirely the
user's responsibility.

cheers,
Richard

Richard Holland
Bioinformatics Specialist
GIS extension 8199
---------------------------------------------
This email is confidential and may be privileged. If you are not the
intended recipient, please delete it and notify us immediately. Please
do not copy or use it for any purpose, or disclose its content to any
other person. Thank you.
---------------------------------------------


> -----Original Message-----
> From: mark.schreiber at novartis.com 
> [mailto:mark.schreiber at novartis.com] 
> Sent: Tuesday, January 24, 2006 11:17 AM
> To: Richard HOLLAND
> Cc: biojava-dev at biojava.org
> Subject: Re: [Biojava-dev] BioSQLRichSequenceDB and BioSQLBioEntryDB
> 
> 
> Very cool use of reflection in there!
> 
> I don't see how commits and rollbacks are handled though??
> 
> - Mark
> 
> 
> 
> 
> 
> "Richard HOLLAND" <hollandr at gis.a-star.edu.sg>
> Sent by: biojava-dev-bounces at portal.open-bio.org
> 01/24/2006 10:51 AM
> 
> 
>         To:     <biojava-dev at biojava.org>
>         cc:     Mark Schreiber/GP/Novartis at PH
>         Subject:        [Biojava-dev] BioSQLRichSequenceDB 
> and BioSQLBioEntryDB
> 
> 
> We've added two new modules to BioJavaX that allow you to wrap a 
> BioSQL/Hibernate database in a SequenceDB compatible wrapper. 
> More for 
> convenience sake than anything else (its not foolproof) but 
> it might be 
> useful. 
> 
> They are:
> 
>                  org.biojavax.bio.db.biosql.BioSQLBioEntryDB
>                  org.biojavax.bio.db.biosql.BioSQLRichSequenceDB
> 
> The code depends on you having unique values in the 'name' 
> column of the 
> BioEntry table in your BioSQL database. You'll get 
> 'IllegalIDExceptions' 
> thrown all over the place if this does not hold true. If this 
> is the case, 
> you should use Hibernate directly rather than this 
> convenience wrapper 
> code.
> 
> To use it, make sure Hibernate is on your classpath. Then you can do 
> things like this:
> 
>                  Session session = ...;  // get a Hibernate 
> session from 
> somewhere
> 
> 
> RichObjectFactory.connectToHibernate(session); // bind 
> BioJavaX to the hibernate session
>                  RichSequenceDB db = new 
> BioSQLRichSequenceDB(session); // 
> connect the hibernate session to our SequenceDB
> 
>                  System.out.println(db.ids()); // prints out 
> a list of all 
> the values in the 'name' column of the BioEntry table in the 
> database 
> 
>                  for (Iterator i = db.getRichSequences("bloggs"); 
> i.hasNext(); ) {  // retrieve all sequences where the name is 'bloggs'
>                      RichSequence seq = 
> (RichSequence)i.next(); // get the 
> next one
>                      ... // do something with it here
>                  }
> 
> To add sequences to your database:
> 
>                  RichSequence seq = ...; // get a RichSequence from 
> somewhere
>                  db.addRichSequence(seq);
> 
> To remove them again:
> 
>                  db.removeRichSequence("bloggs"); // removes 
> the sequence 
> with the name 'bloggs'
> 
> The BioSQLBioEntryDB works in exactly the same way but returns only 
> BioEntry objects - ie. sequences without the sequence data 
> attached. This 
> might help with performance in some cases.
> 
> Finally, we also added a GenbankRichSequenceDB object that 
> behaves much 
> like the old GenbankSequenceDB object but returns 
> RichSequence objects 
> instead.
> 
> cheers,
> Richard
> 
> Richard Holland
> Bioinformatics Specialist
> Genome Institute of Singapore
> 60 Biopolis Street, #02-01 Genome, Singapore 138672
> Tel: (65) 6478 8000   DID: (65) 6478 8199
> Email: hollandr at gis.a-star.edu.sg
> ---------------------------------------------
> This email is confidential and may be privileged. If you are not the 
> intended recipient, please delete it and notify us 
> immediately. Please do 
> not copy or use it for any purpose, or disclose its content 
> to any other 
> person. Thank you.
> ---------------------------------------------
> 
> 
> _______________________________________________
> biojava-dev mailing list
> biojava-dev at biojava.org
> http://biojava.org/mailman/listinfo/biojava-dev
> 
> 
> 
> 

_______________________________________________
biojava-dev mailing list
biojava-dev at biojava.org
http://biojava.org/mailman/listinfo/biojava-dev





More information about the biojava-dev mailing list