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);
}
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;
}
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;
}
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);
}
}
}
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();
}
Aggregations