Search in sources :

Example 6 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class ODocument method getImmutableSchemaClass.

protected OImmutableClass getImmutableSchemaClass() {
    if (_immutableClazz == null) {
        if (_className == null)
            fetchClassName();
        final ODatabaseDocument databaseRecord = getDatabaseIfDefined();
        if (databaseRecord != null && !databaseRecord.isClosed()) {
            final OSchema immutableSchema = ((OMetadataInternal) databaseRecord.getMetadata()).getImmutableSchemaSnapshot();
            if (immutableSchema == null)
                return null;
            _immutableSchemaVersion = immutableSchema.getVersion();
            _immutableClazz = (OImmutableClass) immutableSchema.getClass(_className);
        }
    }
    return _immutableClazz;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal)

Example 7 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class ODocument method reset.

/**
   * <p>
   * Resets the record values and class type to being reused. It's like you create a ODocument from scratch. This method is handy
   * when you want to insert a bunch of documents and don't want to strain GC.
   * </p>
   * <p/>
   * <p>
   * The following code will create a new document in database.
   * </p>
   * <code>
   * doc.clear();
   * doc.save();
   * </code>
   * <p/>
   * <p>
   * IMPORTANT! This can be used only if no transactions are begun.
   * </p>
   *
   * @return this
   * @throws IllegalStateException if transaction is begun.
   * @see #clear()
   */
@Override
public ODocument reset() {
    ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (db != null && db.getTransaction().isActive())
        throw new IllegalStateException("Cannot reset documents during a transaction. Create a new one each time");
    super.reset();
    _className = null;
    _immutableClazz = null;
    _immutableSchemaVersion = -1;
    internalReset();
    _owners = null;
    return this;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument)

Example 8 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class ODocument method setClassName.

public void setClassName(final String className) {
    _immutableClazz = null;
    _immutableSchemaVersion = -1;
    _className = className;
    if (className == null) {
        return;
    }
    final ODatabaseDocument db = getDatabaseIfDefined();
    if (db != null) {
        OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
        this._immutableClazz = (OImmutableClass) metadata.getImmutableSchemaSnapshot().getClass(className);
        OClass clazz;
        if (this._immutableClazz != null) {
            clazz = this._immutableClazz;
        } else {
            clazz = metadata.getSchema().getOrCreateClass(className);
        }
        if (clazz != null) {
            _className = clazz.getName();
            convertFieldsToClass(clazz);
        }
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal)

Example 9 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class OFunctionLibraryImpl method init.

protected void init() {
    final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
    if (db.getMetadata().getSchema().existsClass("OFunction")) {
        final OClass f = db.getMetadata().getSchema().getClass("OFunction");
        OProperty prop = f.getProperty("name");
        if (prop.getAllIndexes().isEmpty())
            prop.createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX);
        return;
    }
    final OClass f = db.getMetadata().getSchema().createClass("OFunction");
    OProperty prop = f.createProperty("name", OType.STRING, (OType) null, true);
    prop.set(OProperty.ATTRIBUTES.NOTNULL, true);
    prop.set(OProperty.ATTRIBUTES.MANDATORY, true);
    prop.createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX);
    f.createProperty("code", OType.STRING, (OType) null, true);
    f.createProperty("language", OType.STRING, (OType) null, true);
    f.createProperty("idempotent", OType.BOOLEAN, (OType) null, true);
    f.createProperty("parameters", OType.EMBEDDEDLIST, OType.STRING, true);
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 10 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class OFunctionLibraryImpl method load.

public void load() {
    // COPY CALLBACK IN RAM
    final Map<String, OCallable<Object, Map<Object, Object>>> callbacks = new HashMap<String, OCallable<Object, Map<Object, Object>>>();
    for (Map.Entry<String, OFunction> entry : functions.entrySet()) {
        if (entry.getValue().getCallback() != null)
            callbacks.put(entry.getKey(), entry.getValue().getCallback());
    }
    functions.clear();
    // LOAD ALL THE FUNCTIONS IN MEMORY
    final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
    if (((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot().existsClass("OFunction")) {
        List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from OFunction order by name"));
        for (ODocument d : result) {
            d.reload();
            final OFunction f = new OFunction(d);
            // RESTORE CALLBACK IF ANY
            f.setCallback(callbacks.get(f.getName()));
            functions.put(d.field("name").toString().toUpperCase(), f);
        }
    }
}
Also used : OCallable(com.orientechnologies.common.util.OCallable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)187 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)81 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)68 Test (org.testng.annotations.Test)53 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)47 ORecordId (com.orientechnologies.orient.core.id.ORecordId)23 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)17 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)16 ORecord (com.orientechnologies.orient.core.record.ORecord)14 Test (org.junit.Test)14 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)12 ORID (com.orientechnologies.orient.core.id.ORID)11 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)10 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)9 OValidationException (com.orientechnologies.orient.core.exception.OValidationException)9 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)9 ArrayList (java.util.ArrayList)9 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)8 HashSet (java.util.HashSet)8