Re: !%@$#%@ DataSource

[email protected] Sat, 29 Aug 2009 13:50:38 +1000
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
Hello Ryan,

I'm glad you asked.

Traditionally you just create a class that extends DataSource and returns a new connections for getConnection.  An example of this is in TestUte.

But if you download the just released version, you no longer need to do this.  See the code below.

BTW.  Please subscribe and post to the main list for support.

Anthony

/** Minimal amount of code just to demo API. */
public class A0TinyExample {
        
        public static void main(String[] argv) throws Exception {
        Class.forName("org.hsqldb.jdbcDriver");
        Connection con = java.sql.DriverManager.getConnection("jdbc:hsqldb:hsqlTempFiles;shutdown=true;", "sa", "");
                SSessionJdbc ses = SSessionJdbc.open(con, "Tiny");
                
                ses.begin();
                ses.getDriver().dropTableNoError("XX_DEPARTMENT");
                ses.commit();
                
                ses.begin();
        ses.rawUpdateDB(ses.getDriver().createTableSQL(Department.DEPARTMENT));
                ses.commit();
                
                ses.begin();
                SDataLoader deptDL = new SDataLoader(ses, Department.DEPARTMENT);
                deptDL.insertRecords(new Object[][] {
                                { "100", "One00", "Count Pennies", 10000, 200000 },
                                { "200", "Two00", "Be Happy", 20000, 300000 },
                                { "300", "Three00", "Enjoy Life", 30000, 150000 } });
                ses.commit();

                ses.begin();
                SQueryResult<Department> res  = ses.query(new SQuery(Department.DEPARTMENT));
                SLog.getSessionlessLogger().message("Departments: " + res);             
                ses.commit();
                ses.close();
        }

}


At 08:56 AM 29/08/2009, you wrote:
>Hi Anthony,
>
>How do I wrap a Connection in a DataSource?
>
>Or better yet... I'm using the JavaDB that comes with Java6 (which is really Derby) and I'm able to create a Connection to the Derby database. What is the best way to create a DataSource for that database so I can use SimpleORM with it?
>
>Thanks,
>Ryan
>
>--- In [email protected], anthony@... wrote:
>> The reason that SimpleORM takes a DataSource parameter instead of a JDBC Connection was so that it could open a second connection as a way to generate sequence numbers.  However this sequence number generation was never implemented, and realistically is not likely to be implemented given that now all databases have internal hacks that do essentially the same thing.
>> 
>> So yes, I think that we could go back to Connection, and deprecate DataSource or leave it there for convenience.
>> 
>> For now, it is trivial to wrap a Connection in a DataSource.  It only ever needs to produce one.

Dr Anthony Berglas, [email protected]       Mobile: +61 4 4838 8874
Just because it is possible to push twigs along the ground with ones nose
does not necessarily mean that is the best way to collect firewood.



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/SimpleORM/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/SimpleORM/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/