Search in sources :

Example 96 with ODatabaseDocument

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

the class OSequenceLibraryImpl method init.

private void init() {
    final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
    if (db.getMetadata().getSchema().existsClass(OSequence.CLASS_NAME)) {
        return;
    }
    final OClassImpl sequenceClass = (OClassImpl) db.getMetadata().getSchema().createClass(OSequence.CLASS_NAME);
    OSequence.initClass(sequenceClass);
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClassImpl(com.orientechnologies.orient.core.metadata.schema.OClassImpl)

Example 97 with ODatabaseDocument

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

the class ORecordSerializerCSVAbstract method linkToStream.

/**
   * Serialize the link.
   * 
   * @param buffer
   * @param iParentRecord
   * @param iLinked
   *          Can be an instance of ORID or a Record<?>
   * @return
   */
private static OIdentifiable linkToStream(final StringBuilder buffer, final ODocument iParentRecord, Object iLinked) {
    if (iLinked == null)
        // NULL REFERENCE
        return null;
    OIdentifiable resultRid = null;
    ORID rid;
    if (iLinked instanceof ORID) {
        // JUST THE REFERENCE
        rid = (ORID) iLinked;
        assert rid.getIdentity().isValid() || (ODatabaseRecordThreadLocal.INSTANCE.get().getStorage() instanceof OStorageProxy) : "Impossible to serialize invalid link " + rid.getIdentity();
        resultRid = rid;
    } else {
        if (iLinked instanceof String)
            iLinked = new ORecordId((String) iLinked);
        else if (!(iLinked instanceof ORecord)) {
            // NOT RECORD: TRY TO EXTRACT THE DOCUMENT IF ANY
            final String boundDocumentField = OObjectSerializerHelperManager.getInstance().getDocumentBoundField(iLinked.getClass());
            if (boundDocumentField != null)
                iLinked = OObjectSerializerHelperManager.getInstance().getFieldValue(iLinked, boundDocumentField);
        }
        if (!(iLinked instanceof OIdentifiable))
            throw new IllegalArgumentException("Invalid object received. Expected a OIdentifiable but received type=" + iLinked.getClass().getName() + " and value=" + iLinked);
        // RECORD
        ORecord iLinkedRecord = ((OIdentifiable) iLinked).getRecord();
        rid = iLinkedRecord.getIdentity();
        assert rid.getIdentity().isValid() || (ODatabaseRecordThreadLocal.INSTANCE.get().getStorage() instanceof OStorageProxy) : "Impossible to serialize invalid link " + rid.getIdentity();
        final ODatabaseDocument database = ODatabaseRecordThreadLocal.INSTANCE.get();
        if (iParentRecord != null) {
            if (!database.isRetainRecords())
                // REPLACE CURRENT RECORD WITH ITS ID: THIS SAVES A LOT OF MEMORY
                resultRid = iLinkedRecord.getIdentity();
        }
    }
    if (rid.isValid())
        rid.toString(buffer);
    return resultRid;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) ORecord(com.orientechnologies.orient.core.record.ORecord) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 98 with ODatabaseDocument

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

the class ORecordSerializerJSON method getValueAsRecord.

private Object getValueAsRecord(ODocument iRecord, String iFieldValue, OType iType, String iOptions, String[] fields) {
    ORID rid = new ORecordId(OIOUtils.getStringContent(getFieldValue("@rid", fields)));
    boolean shouldReload = rid.isTemporary();
    final ODocument recordInternal = (ODocument) fromString(iFieldValue, new ODocument(), null, iOptions, shouldReload);
    if (shouldBeDeserializedAsEmbedded(recordInternal, iType))
        ODocumentInternal.addOwner(recordInternal, iRecord);
    else {
        ODatabaseDocument database = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
        if (rid.isPersistent() && database != null) {
            ODocument documentToMerge = database.load(rid);
            documentToMerge.merge(recordInternal, false, false);
            return documentToMerge;
        }
    }
    return recordInternal;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ORID(com.orientechnologies.orient.core.id.ORID) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 99 with ODatabaseDocument

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

the class OCommandExecutorSQLCreateCluster method execute.

/**
   * Execute the CREATE CLUSTER.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (clusterName == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    final ODatabaseDocument database = getDatabase();
    final int clusterId = database.getClusterIdByName(clusterName);
    if (clusterId > -1)
        throw new OCommandSQLParsingException("Cluster '" + clusterName + "' already exists");
    if (blob) {
        if (requestedId == -1) {
            return database.addBlobCluster(clusterName);
        } else {
            throw new OCommandExecutionException("Request id not supported by blob cluster creation.");
        }
    } else {
        if (requestedId == -1) {
            return database.addCluster(clusterName);
        } else {
            return database.addCluster(clusterName, requestedId, null);
        }
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 100 with ODatabaseDocument

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

the class OCommandExecutorSQLCreateFunction method execute.

/**
   * Execute the command and return the ODocument object created.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (name == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    if (name.isEmpty())
        throw new OCommandExecutionException("Syntax Error. You must specify a function name: " + getSyntax());
    if (code == null || code.isEmpty())
        throw new OCommandExecutionException("Syntax Error. You must specify the function code: " + getSyntax());
    ODatabaseDocument database = getDatabase();
    final OFunction f = database.getMetadata().getFunctionLibrary().createFunction(name);
    f.setCode(code);
    f.setIdempotent(idempotent);
    if (parameters != null)
        f.setParameters(parameters);
    if (language != null)
        f.setLanguage(language);
    f.save();
    return f.getId();
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OFunction(com.orientechnologies.orient.core.metadata.function.OFunction)

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