You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Robert Smol <ro...@dhl.com> on 2004/09/27 16:25:43 UTC
new OJB user: newOQLQuery() no such method error
Hello,
I am trying to setup OJB for my little project. I started with small
class performing update and select from db. Update is working, select is
giving me error:
Exception in thread "main" java.lang.NoSuchMethodError:
org.odmg.Implementation.newOQLQuery
()Lorg/apache/ojb/odmg/oql/EnhancedOQLQuery;
at gts.ODMGTest.loadData(ODMGTest.java:56)
at gts.ODMGTest.main(ODMGTest.java:94)
I tried to read through Javadoc and I can see that this should be
implemented by class implementing Implementation interface. I do not
know how the OJB.getInstance(); code works. Do I need to have some
special implementation class to make it works? Am I missing something
obvious? I am just a mediocre Java coder interested in this tech. I am
quite desperate.
Here is source code of my test.
ODMGTest.java
package gts;
import org.apache.ojb.odmg.OJB;
import org.odmg.DList;
import org.odmg.Database;
import org.odmg.Implementation;
import org.odmg.ODMGException;
import org.odmg.OQLQuery;
import org.odmg.QueryException;
import org.odmg.Transaction;
/**
* @author rsmol
*
* TODO To change the template for this generated type comment go to
Window -
* Preferences - Java - Code Style - Code Templates
*/
public class ODMGTest {
Implementation odmg = null;
Database db = null;
public ODMGTest() {
super();
init();
}
/**
* init database and make envinment for transactions
*
* @throws DatastoreException
*/
private void init() {
//get odmg instance
odmg = OJB.getInstance();
db = odmg.newDatabase();
//open database
try {
db.open("default", Database.OPEN_READ_WRITE);
} catch (Exception e) {
e.printStackTrace();
}
}
public User loadData() throws QueryException{
User user = new User();
Transaction tx = odmg.newTransaction();
tx.begin();
OQLQuery query = odmg.newOQLQuery();
query.create("select users from "
+ User.class.getName()
+ " where userName = $1");
query.bind("robert");
DList results = (DList) query.execute();
user = (User) results.iterator().next();
tx.commit();
return user;
}
public void storeUser(User user){
Transaction tx = odmg.newTransaction();
tx.begin();
tx.lock(user, Transaction.WRITE);
tx.commit();
}
public void close() throws ODMGException{
db.close();
}
public static void main(String[] args) throws ODMGException {
ODMGTest test = new ODMGTest();
System.out.println("databaze inicializovana");
User user1 = new User();
user1.setEmail("robert.smol@post.cz");
user1.setPassword("hovno");
user1.setUserName("robert");
System.out.println(user1);
test.storeUser(user1);
System.out.println("ulozeno");
User user2 = test.loadData();
System.out.println("nacten \n"+user2);
test.close();
}
}