How to get OObjectDatabaseTx inside a Custom Command

52 views
Skip to first unread message

Ena

unread,
Feb 19, 2014, 12:04:25 PM2/19/14
to orient-...@googlegroups.com
Hi all,
I'm an OrientDb newbie. I'm using the 2.0 snapshot. I'm writing a custom command that will execute on an Object Database.
This command simply get a Person by name by an Object Database (Person class is registered in the database and the schema is automatically generated).

I don't understand how to get my OObjectDatabaseTx from the execute method.
The method getProfiledDatabaseInstance returns the underlying ODocumentDatabaseTx.
Code is below, with the question part highlighted.

Thanks!
Ena

public class GetPersonCommand extends OServerCommandAuthenticatedDbAbstract {

private final static Logger LOGGER = Logger.getLogger(GetPersonCommand.class.getName());

private static final String[] NAMES = { "GET|getPerson/*" };

public GetPersonCommand(final OServerCommandConfiguration iConfiguration) {
super();
}

@Override
public boolean execute(OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
LOGGER.log(Level.INFO, "GetPersonCommand, enter");
// CHECK THE SYNTAX. 3 IS THE NUMBER OF MANDATORY PARAMETERS
String[] urlParts = checkSyntax(iRequest.url, 3, "Syntax error: getPerson/<database>/<personName>");

// TELLS TO THE SERVER WHAT I'M DOING (IT'S FOR THE PROFILER)
iRequest.data.commandInfo = "getPerson";
iRequest.data.commandDetail = urlParts[2];

// GET THE PARAMETERS
String name = urlParts[2];

OObjectDatabaseTx db = null;
Person person = null;
try {
                        // COMPILE ERROR! HOW TO GET IT?
db = getProfiledDatabaseInstance(iRequest);

List<Person> persons = db.query(new OSQLSynchQuery<Person>("select * from Person where name = \"" + name
+ "\""));
if (persons.size() == 0) {
iResponse.send(OHttpUtils.STATUS_NOTFOUND_CODE, "Not Found", OHttpUtils.CONTENT_JSON, "Person with name '"
+ urlParts[2] + "' was not found.", null);
} else {
person = persons.get(0);
iResponse.writeResult(person);
}

} catch (Exception e) {
iResponse.send(OHttpUtils.STATUS_INTERNALERROR_CODE, "General Error", OHttpUtils.CONTENT_JSON, "Error: "
+ e.getClass().getName(), null);
LOGGER.log(Level.WARNING, "Error", e);
} finally {
if (db != null)
db.close();
}

return false;

}

@Override
public String[] getNames() {
return NAMES;
}

}

Ena

unread,
Feb 20, 2014, 3:36:51 AM2/20/14
to orient-...@googlegroups.com
Found the answer this morning on this other thread:


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/rEwptEkMqIQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ena

unread,
Feb 20, 2014, 4:31:21 AM2/20/14
to orient-...@googlegroups.com
Sorry, this is not the solution for my case.
Object Database doesn't have such a constructor.
Any help?

Reply all
Reply to author
Forward
0 new messages