In OrientDB 1.7, it was possible to write code like this:

OrientGraph g = factory.getTx()
def vertex = g.getVertices( ... )
g.shutdown()

def record = vertex.getRecord()

def json = record.toJSON( fetchPlan )


This would get a JSON representation of the vertex (and other data,
depending on the fetch plan).

In Orient 2.0, that code compiles, and it runs, but it fails silently, with
a wide variety of failure modes:

   - If your database has a custom DATETIMEFORMAT, your datetime fields
   will be formatted with the default datetime format, instead of your custom
   format.
   - Any fields that depend upon your fetch plan will not be retrieved
   (with no error message).
   - Sometimes you'll get an ODatabaseException (see below).

The obvious solution to the problem is to rewrite your code like this:

OrientGraph g = factory.getTx()
def vertex = g.getVertices( ... )

def record = vertex.getRecord()

def json = record.toJSON( fetchPlan )
g.shutdown()


The hard part is discovering all of the mis-timed usages and correcting
them. One way to do that is to modify methods that take a bare ORecord and
add this code:

def db = record.getDatabase()

log.debug( "Database status: ${db.getStatus()}" )


This spits out a log message if your graph is active, and throws a
completely misleading ODatabaseException if the graph has been closed:

com.orientechnologies.orient.core.exception.ODatabaseException: Database
instance is not set in current thread. Assure to set it with:
ODatabaseRecordThreadLocal.INSTANCE.set(db);
at
com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal.get(ODatabaseRecordThreadLocal.java:54)
at
com.orientechnologies.orient.core.record.ORecordAbstract.getDatabase(ORecordAbstract.java:240)
at
com.orientechnologies.orient.core.record.ORecordAbstract.getDatabase(ORecordAbstract.java:48)
at com.mycompany.myprogram.mypackage.MyClass.myMethod().


You can then use that stack trace to track back to your problem methods.

- Craig -

-- 

--- 
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.

Reply via email to