@Override public byte[] toStream(ORecord iRecord, boolean iOnlyDelta) { final byte[] result = super.toStream(iRecord, iOnlyDelta); if (result == null || result.length > 0) return result; // Fix of nasty IBM JDK bug. In case of very depth recursive graph serialization // ODocument#_source property may be initialized incorrectly. final ODocument recordSchemaAware = (ODocument) iRecord; if (recordSchemaAware.fields() > 0) return null; return result; }
public ODocument save(final Map<String, Object> iObject) { return database.save(new ODocument().fields(iObject)); }
private Object copy(final Map map, final Object[] iFieldNames) { final ODocument doc = new ODocument().fields(map); for (Object iFieldName : iFieldNames) { if (iFieldName != null) { final String fieldName = iFieldName.toString(); if (fieldName.endsWith("*")) { final String fieldPart = fieldName.substring(0, fieldName.length() - 1); final List<String> toExclude = new ArrayList<String>(); for (String f : doc.fieldNames()) { if (f.startsWith(fieldPart)) toExclude.add(f); } for (String f : toExclude) doc.removeField(f); } else doc.removeField(fieldName); } } return doc; } }
@ConsoleCommand(description = "List all the active connections to the server", onlineHelp = "Console-Command-List-Connections") public void listConnections() throws IOException { checkForRemoteServer(); OrientDBRemote remote = (OrientDBRemote) OrientDBInternal.extract(orientDB); final ODocument serverInfo = remote.getServerInfo(currentDatabaseUserName, currentDatabaseUserPassword); final List<OIdentifiable> resultSet = new ArrayList<OIdentifiable>(); final List<Map<String, Object>> connections = serverInfo.field("connections"); for (Map<String, Object> conn : connections) { final ODocument row = new ODocument(); String commandDetail = (String) conn.get("commandInfo"); if (commandDetail != null && ((String) conn.get("commandDetail")).length() > 1) commandDetail += " (" + conn.get("commandDetail") + ")"; row.fields("ID", conn.get("connectionId"), "REMOTE_ADDRESS", conn.get("remoteAddress"), "PROTOC", conn.get("protocol"), "LAST_OPERATION_ON", conn.get("lastCommandOn"), "DATABASE", conn.get("db"), "USER", conn.get("user"), "COMMAND", commandDetail, "TOT_REQS", conn.get("totalRequests")); resultSet.add(row); } Collections.sort(resultSet, new Comparator<OIdentifiable>() { @Override public int compare(final OIdentifiable o1, final OIdentifiable o2) { final String o1s = ((ODocument) o1).field("LAST_OPERATION_ON"); final String o2s = ((ODocument) o2).field("LAST_OPERATION_ON"); return o2s.compareTo(o1s); } }); final OTableFormatter formatter = new OTableFormatter(this); formatter.writeRecords(resultSet, -1); out.println(); }
public OIndex build(final ODatabaseDocumentTx db) { checkState(!propertyNames.isEmpty(), "At least one property is required"); checkState(propertyTypes.size() == propertyNames.size(), "A type must be defined for each property"); List<OCollate> collates = null; if (caseInsensitive) { collates = Lists.transform(propertyNames, n -> new OCaseInsensitiveCollate()); } ODocument metadata = new ODocument(); if (ignoreNullValues) { metadata.field("ignoreNullValues", true); } OIndexDefinition indexDefinition = OIndexDefinitionFactory.createIndexDefinition(type, propertyNames, propertyTypes, collates, indexType.name(), null); return db.getMetadata().getIndexManager().createIndex(name, indexType.name(), indexDefinition, type.getPolymorphicClusterIds(), null, metadata.fields() > 0 ? metadata : null); } }
public void load(ODatabaseDocumentInternal db) { // 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 if (db.getMetadata().getImmutableSchemaSnapshot().existsClass("OFunction")) { try(OResultSet result = db.query("select from OFunction order by name")) { while (result.hasNext()) { OResult res = result.next(); ODocument d = (ODocument) res.getElement().get(); //skip the function records which do not contain real data if (d.fields() == 0) continue; final OFunction f = new OFunction(d); // RESTORE CALLBACK IF ANY f.setCallback(callbacks.get(f.getName())); functions.put(d.field("name").toString().toUpperCase(Locale.ENGLISH), f); } } } }
@SuppressWarnings("unchecked") public Object execute(Object iThis, final OIdentifiable iCurrentRecord, Object iCurrentResult, final Object[] iParams, OCommandContext iContext) { if (iParams.length > 2) // IN LINE MODE context = new ODocument(); if (iParams.length == 1) { if (iParams[0] instanceof ODocument) // INSERT EVERY DOCUMENT FIELD context.merge((ODocument) iParams[0], true, false); else if (iParams[0] instanceof Map<?, ?>) // INSERT EVERY SINGLE COLLECTION ITEM context.fields((Map<String, Object>) iParams[0]); else throw new IllegalArgumentException("Map function: expected a map or pairs of parameters as key, value"); } else if (iParams.length % 2 != 0) throw new IllegalArgumentException("Map function: expected a map or pairs of parameters as key, value"); else for (int i = 0; i < iParams.length; i += 2) { final String key = iParams[i].toString(); final Object value = iParams[i + 1]; if (value != null) { if (iParams.length <= 2 && context == null) // AGGREGATION MODE (STATEFULL) context = new ODocument(); context.field(key, value); } } return prepareResult(context); }
public void removeMetadata(String key) { ODocument metadata = getMetadataDocument(); metadata.removeField(key); if (metadata.fields() == 0) element.getRawElement().removeProperty(metadataKey()); }
@SuppressWarnings("unchecked") public void serialize(final ODocument document, final BytesContainer bytes, final boolean iClassOnly) { serializeClass(document, bytes); if (iClassOnly) { writeEmptyString(bytes); return; } final Set<Entry<String, ODocumentEntry>> fields = ODocumentInternal.rawEntries(document); OVarIntSerializer.write(bytes, document.fields()); for (Entry<String, ODocumentEntry> entry : fields) { ODocumentEntry docEntry = entry.getValue(); if (!docEntry.exist()) continue; writeString(bytes, entry.getKey()); final Object value = entry.getValue().value; if (value != null) { final OType type = getFieldType(entry.getValue()); if (type == null) { throw new OSerializationException( "Impossible serialize value of type " + value.getClass() + " with the Result binary serializer"); } writeOType(bytes, bytes.alloc(1), type); serializeValue(bytes, value, type, getLinkedType(document, type, entry.getKey())); } else { writeOType(bytes, bytes.alloc(1), null); } } }
OIndex<?> idx = e.createIndex(name, unique ? OClass.INDEX_TYPE.UNIQUE_HASH_INDEX.toString() : OClass.INDEX_TYPE.NOTUNIQUE_HASH_INDEX.toString(), null, new ODocument().fields("ignoreNullValues", true), fieldArray); if (idx == null) { new RuntimeException("Index for {" + label + "/" + indexPostfix + "} was not created.");
@Override public void addVertexIndex(String indexName, Class<?> clazzOfVertices, boolean unique, String fieldKey, FieldType fieldType) { if (log.isDebugEnabled()) { log.debug("Adding vertex index for class {" + clazzOfVertices.getName() + "}"); } OrientGraphNoTx noTx = rawNoTx(); try { String name = clazzOfVertices.getSimpleName(); OrientVertexType v = noTx.getVertexType(name); if (v == null) { throw new RuntimeException("Vertex type {" + name + "} is unknown. Can't create index {" + indexName + "}"); } if (v.getProperty(fieldKey) == null) { OType type = toType(fieldType); OType subType = toSubType(fieldType); if (subType != null) { v.createProperty(fieldKey, type, subType); } else { v.createProperty(fieldKey, type); } } if (v.getClassIndex(indexName) == null) { v.createIndex(indexName, unique ? OClass.INDEX_TYPE.UNIQUE_HASH_INDEX.toString() : OClass.INDEX_TYPE.NOTUNIQUE_HASH_INDEX.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { fieldKey }); } } finally { noTx.shutdown(); } }
@SuppressWarnings("unchecked") public OIdentifiable process() { while (target.hasNext()) { record = target.next(); index++; final ORecord rec = record.getRecord(); if (rec instanceof ODocument) { ODocument doc = (ODocument) rec; if (!doc.getIdentity().isPersistent() && doc.fields() == 1) { // EXTRACT THE FIELD CONTEXT Object fieldvalue = doc.field(doc.fieldNames()[0]); if (fieldvalue instanceof Collection<?>) { command.getContext().push( new OTraverseRecordSetProcess(command, ((Collection<OIdentifiable>) fieldvalue).iterator(), getPath())); } else if (fieldvalue instanceof ODocument) { command.getContext().push(new OTraverseRecordProcess(command, (ODocument) rec, getPath())); } } else { command.getContext().push(new OTraverseRecordProcess(command, (ODocument) rec, getPath())); } return null; } } return pop(); }
@Override public RESULT onRecordBeforeDelete(final ODocument iDocument) { final ORecordVersion version = iDocument.getRecordVersion(); // Cache the transaction-provided value if (iDocument.fields() == 0) { // FORCE LOADING OF CLASS+FIELDS TO USE IT AFTER ON onRecordAfterDelete METHOD iDocument.reload(); if (version.getCounter() > -1 && iDocument.getRecordVersion().compareTo(version) != 0) // check for record version errors if (OFastConcurrentModificationException.enabled()) throw OFastConcurrentModificationException.instance(); else throw new OConcurrentModificationException(iDocument.getIdentity(), iDocument.getRecordVersion(), version, ORecordOperation.DELETED); } return RESULT.RECORD_NOT_CHANGED; }
if (doc.fields() == 2) { final ORID edgeIdentity = doc.getIdentity();
if (doc.fields() == 2) { final ORID edgeIdentity = doc.getIdentity();
if (doc.fields() == 1) { singleFieldName = doc.fieldNames()[0]; tempColl.add(doc.field(singleFieldName));
.fields(OrientBaseGraph.CONNECTION_OUT, currentVertex.rawElement.getIdentity(), OrientBaseGraph.CONNECTION_IN, inDocument.getIdentity()); else edgeRecord .fields(OrientBaseGraph.CONNECTION_OUT, currentVertex.rawElement, OrientBaseGraph.CONNECTION_IN, inDocument); } else edgeRecord = edge.getRecord();