/** * Create an instance sink based on a {@link LocalOrientDB} * * @param database the sink database * @param lockNow if the database should be locked now */ public OrientInstanceSink(LocalOrientDB database, boolean lockNow) { super(); this.database = database; if (lockNow) { // ensure the lock is acquired now (in this thread) ref = database.openWrite(); ref.getDatabase(); } }
/** @see InstanceSink#addInstance(Instance) */ @Override public synchronized void addInstance(Instance instance) { if (ref == null) { ref = database.openWrite(); } ODatabaseDocumentTx db = ref.getDatabase(); // further processing before saving processInstance(instance); // get/create OInstance OInstance conv = ((instance instanceof OInstance) ? ((OInstance) instance) : (new OInstance(instance))); conv.setInserted(true); ODatabaseRecordThreadLocal.INSTANCE.set(db); // configure the document ODocument doc = conv.configureDocument(db); // and save it doc.save(); }