Hi all,
I'm using OrientDB, the Object API version, and I'm trying to execute a
simple select query. I'm managing, but I have such much code, I think I'm
doing something wrong, so, I was wondering, can you help me?
This is the method I'm trying to implement:
public Author findByName(String name)
The code I have for this is:
public Author findByName(String name) {
try (OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
db.getEntityManager().registerEntityClass(Book.class);
List<Author> results = db.query(new OSQLSynchQuery<Author>("select from
Author where name=?"), name);
if (!results.isEmpty()) {
return db.detach(results.get(0));
} else {
return null;
}
}
}
I first need a connection from the pool, then I need to register the
EntityClass (luckily only one here, but often many). Then I execute the query,
and, while I only want 1 object, I get a list. So I have to check if the list
is empty, and if it's not, I have to detach the object, else I get nullpointer
exception. This code does so many things, it's horrible. So, I'm sure I'm doing
something wrong, but I cannot find an example which does it right.
So, my question is: what's the right way of executing code like this?
thanks,
Erik
--
---
You received this message because you are subscribed to the Google Groups
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.