package org.flymine.objectstore.ojb;

import junit.framework.*;

import org.flymine.sql.Database;
import org.flymine.sql.DatabaseFactory;
import org.flymine.objectstore.query.*;
import org.apache.ojb.broker.*;
import org.apache.ojb.broker.metadata.*;

import org.flymine.model.testmodel.Company;

public class SqlGeneratorFlymineImplTest extends TestCase
{

    public SqlGeneratorFlymineImplTest(String arg1) {
        super(arg1);
    }

    public void testPreparedSelectStatement() throws Exception {
        Database db = DatabaseFactory.getDatabase("db.unittest");
        ObjectStoreOjbImpl os = ObjectStoreOjbImpl.getInstance(db);
        PersistenceBroker broker = os.getPersistenceBroker();
        DescriptorRepository dr = broker.getDescriptorRepository();
        SqlGeneratorFlymineImpl gen = (SqlGeneratorFlymineImpl) broker.serviceSqlGenerator();

        Query q = new Query();
        QueryClass qc1 = new QueryClass(Company.class);
        q.addToSelect(qc1);
        q.addFrom(qc1);
        FlymineSqlSelectStatement s1 = new FlymineSqlSelectStatement(q, dr, 0, 10000);
        assertEquals(s1.getStatement(), gen.getPreparedSelectStatement(q, dr, 0, 10000));
    }


}

@@ -354,81 +354,535 @@
 e%0A%7B%0A
-%0A    public SqlGeneratorFlymineImplTest(String arg1) %7B%0A        super(arg1
+    Database db;%0A    ObjectStoreOjbImpl os;%0A    PersistenceBroker broker;%0A    DescriptorRepository dr;%0A    SqlGeneratorFlymineImpl gen;%0A%0A%0A    public SqlGeneratorFlymineImplTest(String arg1) %7B%0A        super(arg1);%0A    %7D%0A%0A    public void setUp() throws Exception %7B%0A        db = DatabaseFactory.getDatabase(%22db.unittest%22);%0A        os = ObjectStoreOjbImpl.getInstance(db);%0A        broker = os.getPersistenceBroker();%0A        dr = broker.getDescriptorRepository();%0A        gen = (SqlGeneratorFlymineImpl) broker.serviceSqlGenerator(
 );%0A 
@@ -1528,59 +1528,495 @@
 , dr
+);%0A        assertEquals(s1.getStatement(), gen.getPreparedSelectStatement(q, dr
 , 0, 
-1000
 0)
+)
 ;%0A    
-    assertEquals(s1.getStatement()
+%7D%0A%0A%0A    public void testLimitAndOffset() throws Exception %7B%0A        Query q = new Query();%0A        QueryClass qc1 = new QueryClass(Company.class);%0A        q.addToSelect(qc1);%0A        q.addFrom(qc1);%0A        FlymineSqlSelectStatement s1 = new FlymineSqlSelectStatement(q, dr);%0A        String string1 = s1.getStatement();%0A        string1 += %22 LIMIT 10300 OFFSET 47%22;%0A%0A        assertEquals(string1
 , ge
@@ -2055,14 +2055,15 @@
 dr, 
-0
+47
 , 10
-0
+3
 00))
@@ -2071,11 +2071,10 @@
 %0A    %7D%0A%0A
-%0A
 %7D%0A

test that LIMIT and OFFSET are appended correctly