use of com.orientechnologies.orient.core.record.ORecordAbstract in project jnosql-diana-driver by eclipse.
the class DefaultOrientDBDocumentCollectionManagerAsync method delete.
@Override
public void delete(DocumentDeleteQuery query, Consumer<Void> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
requireNonNull(query, "query is required");
requireNonNull(callBack, "callBack is required");
ODatabaseDocumentTx tx = pool.acquire();
DocumentQuery selectQuery = new OrientDBDocumentQuery(query);
QueryOSQLFactory.QueryResult orientQuery = toAsync(selectQuery, l -> {
l.forEach(ORecordAbstract::delete);
callBack.accept(null);
});
tx.command(orientQuery.getQuery()).execute(orientQuery.getParams());
}
use of com.orientechnologies.orient.core.record.ORecordAbstract in project orientdb by orientechnologies.
the class OServerCommandGetFileDownload method execute.
@Override
public boolean execute(OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
String[] urlParts = checkSyntax(iRequest.url, 3, "Syntax error: fileDownload/<database>/rid/[/<fileName>][/<fileType>].");
final String fileName = urlParts.length > 3 ? encodeResponseText(urlParts[3]) : "unknown";
final String fileType = urlParts.length > 5 ? encodeResponseText(urlParts[4]) + '/' + encodeResponseText(urlParts[5]) : (urlParts.length > 4 ? encodeResponseText(urlParts[4]) : "");
final String rid = urlParts[2];
iRequest.data.commandInfo = "Download";
iRequest.data.commandDetail = rid;
final ORecordAbstract response;
ODatabaseDocument db = getProfiledDatabaseInstance(iRequest);
try {
response = db.load(new ORecordId(rid));
if (response != null) {
if (response instanceof OBlob) {
sendORecordBinaryFileContent(iRequest, iResponse, OHttpUtils.STATUS_OK_CODE, OHttpUtils.STATUS_OK_DESCRIPTION, fileType, (OBlob) response, fileName);
} else if (response instanceof ODocument) {
for (OProperty prop : ODocumentInternal.getImmutableSchemaClass(((ODocument) response)).properties()) {
if (prop.getType().equals(OType.BINARY))
sendBinaryFieldFileContent(iRequest, iResponse, OHttpUtils.STATUS_OK_CODE, OHttpUtils.STATUS_OK_DESCRIPTION, fileType, (byte[]) ((ODocument) response).field(prop.getName()), fileName);
}
} else {
iResponse.send(OHttpUtils.STATUS_INVALIDMETHOD_CODE, "Record requested is not a file nor has a readable schema", OHttpUtils.CONTENT_TEXT_PLAIN, "Record requested is not a file nor has a readable schema", null);
}
} else {
iResponse.send(OHttpUtils.STATUS_INVALIDMETHOD_CODE, "Record requested not exists", OHttpUtils.CONTENT_TEXT_PLAIN, "Record requestes not exists", null);
}
} catch (Exception e) {
iResponse.send(OHttpUtils.STATUS_INTERNALERROR_CODE, OHttpUtils.STATUS_INTERNALERROR_DESCRIPTION, OHttpUtils.CONTENT_TEXT_PLAIN, e.getMessage(), null);
} finally {
if (db != null)
db.close();
}
return false;
}
use of com.orientechnologies.orient.core.record.ORecordAbstract in project orientdb by orientechnologies.
the class OContentRecordConflictStrategy method onUpdate.
@Override
public byte[] onUpdate(OStorage storage, final byte iRecordType, final ORecordId rid, final int iRecordVersion, final byte[] iRecordContent, final AtomicInteger iDatabaseVersion) {
final boolean hasSameContent;
if (iRecordType == ODocument.RECORD_TYPE) {
// No need lock, is already inside a lock.
OStorageOperationResult<ORawBuffer> res = storage.readRecord(rid, null, false, false, null);
final ODocument storedRecord = new ODocument(rid).fromStream(res.getResult().getBuffer());
final ODocument newRecord = new ODocument().fromStream(iRecordContent);
final ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.INSTANCE.get();
hasSameContent = ODocumentHelper.hasSameContentOf(storedRecord, currentDb, newRecord, currentDb, null, false);
} else {
// CHECK BYTE PER BYTE
final ORecordAbstract storedRecord = rid.getRecord();
hasSameContent = Arrays.equals(storedRecord.toStream(), iRecordContent);
}
if (hasSameContent)
// OK
iDatabaseVersion.set(Math.max(iDatabaseVersion.get(), iRecordVersion));
else
// NO DOCUMENT, CANNOT MERGE SO RELY TO THE VERSION CHECK
checkVersions(rid, iRecordVersion, iDatabaseVersion.get());
return null;
}
use of com.orientechnologies.orient.core.record.ORecordAbstract in project hale by halestudio.
the class OGroup method configureDocument.
private void configureDocument(ORecordAbstract<?> document, ODatabaseRecord db, DefinitionGroup definition) {
// document.setDatabase(db);
if (document instanceof ODocument) {
// reset class name
ODocument doc = (ODocument) document;
/*
* Attention: Two long class names cause problems as file names will
* be based on them.
*/
String className = null;
if (definition != null) {
className = ONamespaceMap.encode(determineName(definition));
} else if (doc.containsField(OSerializationHelper.BINARY_WRAPPER_FIELD) || doc.containsField(OSerializationHelper.FIELD_SERIALIZATION_TYPE)) {
className = OSerializationHelper.BINARY_WRAPPER_CLASSNAME;
}
if (className != null) {
OSchema schema = db.getMetadata().getSchema();
if (!schema.existsClass(className)) {
// if the class doesn't exist yet, create a physical cluster
// manually for it
int cluster = db.addCluster(className, CLUSTER_TYPE.PHYSICAL);
schema.createClass(className, cluster);
}
doc.setClassName(className);
}
// configure children
for (Entry<String, Object> field : doc) {
List<ODocument> docs = new ArrayList<ODocument>();
List<ORecordAbstract<?>> recs = new ArrayList<ORecordAbstract<?>>();
if (field.getValue() instanceof Collection<?>) {
for (Object value : (Collection<?>) field.getValue()) {
if (value instanceof ODocument && !getSpecialFieldNames().contains(field.getKey())) {
docs.add((ODocument) value);
} else if (value instanceof ORecordAbstract<?>) {
recs.add((ORecordAbstract<?>) value);
}
}
} else if (field.getValue() instanceof ODocument && !getSpecialFieldNames().contains(field.getKey())) {
docs.add((ODocument) field.getValue());
} else if (field.getValue() instanceof ORecordAbstract<?>) {
recs.add((ORecordAbstract<?>) field.getValue());
}
if (definition != null) {
for (ODocument valueDoc : docs) {
ChildDefinition<?> child = definition.getChild(decodeProperty(field.getKey()));
DefinitionGroup childGroup;
if (child.asProperty() != null) {
childGroup = child.asProperty().getPropertyType();
} else if (child.asGroup() != null) {
childGroup = child.asGroup();
} else {
throw new IllegalStateException("Document is associated neither with a property nor a property group.");
}
configureDocument(valueDoc, db, childGroup);
}
}
for (ORecordAbstract<?> fieldRec : recs) {
configureDocument(fieldRec, db, null);
}
}
}
}
use of com.orientechnologies.orient.core.record.ORecordAbstract in project orientdb by orientechnologies.
the class OObjectProxyMethodHandler method lazyLoadField.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object lazyLoadField(final Object self, final String fieldName, Object docValue, final Object currentValue) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
boolean customSerialization = false;
final Field f = OObjectEntitySerializer.getField(fieldName, self.getClass());
if (f == null)
return currentValue;
if (OObjectEntitySerializer.isSerializedType(f)) {
customSerialization = true;
}
if (docValue instanceof OIdentifiable) {
if (OIdentifiable.class.isAssignableFrom(f.getType())) {
if (ORecordAbstract.class.isAssignableFrom(f.getType())) {
ORecordAbstract record = ((OIdentifiable) docValue).getRecord();
OObjectEntitySerializer.setFieldValue(f, self, record);
return record;
} else {
OObjectEntitySerializer.setFieldValue(f, self, docValue);
return docValue;
}
} else {
docValue = convertDocumentToObject((ODocument) ((OIdentifiable) docValue).getRecord(), self);
}
} else if (docValue instanceof Collection<?>) {
docValue = manageCollectionLoad(f, self, docValue, customSerialization);
} else if (docValue instanceof Map<?, ?>) {
docValue = manageMapLoad(f, self, docValue, customSerialization);
} else if (docValue.getClass().isArray() && !docValue.getClass().getComponentType().isPrimitive()) {
docValue = manageArrayLoad(docValue, f);
} else if (customSerialization) {
docValue = OObjectEntitySerializer.deserializeFieldValue(OObjectEntitySerializer.getField(fieldName, self.getClass()).getType(), docValue);
} else {
if (f.getType().isEnum()) {
if (docValue instanceof Number)
docValue = ((Class<Enum>) f.getType()).getEnumConstants()[((Number) docValue).intValue()];
else
docValue = Enum.valueOf((Class<Enum>) f.getType(), docValue.toString());
}
}
OObjectEntitySerializer.setFieldValue(f, self, docValue);
return docValue;
}
Aggregations