public static String getDateTimeFormat() { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db != null && !db.isClosed()) return db.getStorage().getConfiguration().getDateTimeFormat(); else return DEF_DATETIME_FORMAT; }
protected List<OCluster> getClusters() { final ODatabaseDocumentInternal database = getDatabase(); final List<OCluster> result = new ArrayList<OCluster>(); if (clusterName.endsWith("*")) { final String toMatch = clusterName.substring(0, clusterName.length() - 1).toLowerCase(Locale.ENGLISH); for (String cl : database.getStorage().getClusterNames()) { if (cl.startsWith(toMatch)) result.add(database.getStorage().getClusterByName(cl)); } } else { if (clusterId > -1) { result.add(database.getStorage().getClusterById(clusterId)); } else { result.add(database.getStorage().getClusterById(database.getStorage().getClusterIdByName(clusterName))); } } return result; }
ODatabaseDocumentTx db = new ODatabaseDocumentTx(url); if (db.getStorage().isRemote()) { isRemote = true; if (!isRemote) { if (newdb) { if (db.exists()) { db.open(user, password); LOG.info("OrientDB drop and recreate fresh db"); if (!db.getMetadata().getSchema().existsClass(CLASS)) { db.getMetadata().getSchema().createClass(CLASS);
private void convertToSbTree() { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().get(); final OIndexRIDContainerSBTree tree = new OIndexRIDContainerSBTree(fileId, (OAbstractPaginatedStorage) db.getStorage().getUnderlying()); tree.addAll(underlying); underlying = tree; isEmbedded = false; } }
@Override public Object execute(Object iThis, OIdentifiable iCurrentRecord, OCommandContext iContext, Object ioResult, Object[] iParams) { if (iThis != null) { if (iThis instanceof Date) { return iThis; } else if (iThis instanceof Number) { return new Date(((Number) iThis).longValue()); } else { try { return ODatabaseRecordThreadLocal.instance().get().getStorage().getConfiguration().getDateTimeFormatInstance().parse(iThis.toString()); } catch (ParseException e) { OLogManager.instance().error(this, "Error during %s execution", e, NAME); // IGNORE IT: RETURN NULL } } } return null; } }
return new Date(Long.parseLong(iValue.toString())); try { return ODatabaseRecordThreadLocal.instance().get().getStorage().getConfiguration().getDateTimeFormatInstance() .parse((String) iValue); } catch (ParseException ignore) { return ODatabaseRecordThreadLocal.instance().get().getStorage().getConfiguration().getDateFormatInstance() .parse((String) iValue); } else if (o instanceof String) { try { result.add(new ORecordId(iValue.toString())); } catch (Exception e) { OLogManager.instance() .debug(OType.class, "Error in conversion of value '%s' to type '%s'", e, iValue, iTargetClass); } else if (iValue instanceof String) { try { return new ORecordId((String) iValue); } catch (Exception e) { OLogManager.instance().debug(OType.class, "Error in conversion of value '%s' to type '%s'", e, iValue, iTargetClass);
private Directory createDirectory(ODatabaseDocumentInternal database, String indexName, ODocument metadata, String luceneType) { String luceneBasePath = metadata.containsField(DIRECTORY_PATH) ? metadata.<String>field(DIRECTORY_PATH) : OLUCENE_BASE_DIR; Path luceneIndexPath = Paths.get(database.getStorage().getConfiguration().getDirectory(), luceneBasePath, indexName); try { if (DIRECTORY_NIO.equals(luceneType)) { return new NIOFSDirectory(luceneIndexPath); } if (DIRECTORY_MMAP.equals(luceneType)) { return new MMapDirectory(luceneIndexPath); } } catch (IOException e) { OLogManager.instance().error(this, "unable to create Lucene Directory with type " + luceneType, e); } OLogManager.instance().warn(this, "unable to create Lucene Directory, FALL BACK to ramDir"); return new RAMDirectory(); }
private static long resolveFileIdByName(String fileName) { final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) ODatabaseRecordThreadLocal.instance().get().getStorage() .getUnderlying(); boolean rollback = false; final OAtomicOperation atomicOperation; try { atomicOperation = storage.getAtomicOperationsManager().startAtomicOperation(fileName, true); } catch (IOException e) { throw OException.wrapException(new OIndexEngineException("Error creation of sbtree with name " + fileName, fileName), e); } try { long fileId; if (atomicOperation.isFileExists(fileName)) { fileId = atomicOperation.loadFile(fileName); } else { fileId = atomicOperation.addFile(fileName); } return fileId; } catch (IOException e) { rollback = true; throw OException.wrapException(new OIndexEngineException("Error creation of sbtree with name " + fileName, fileName), e); } finally { try { storage.getAtomicOperationsManager().endAtomicOperation(rollback); } catch (IOException ioe) { OLogManager.instance().error(OMixedIndexRIDContainer.class, "Error of rollback of atomic operation", ioe); } } }
((List<OIdentifiable>) targetRecords).add(new ORecordId(parserRequiredWord(true, "No valid RID"))); ((List<OIdentifiable>) targetRecords).add(new ORecordId(rid)); ((ArrayList<OIdentifiable>) targetRecords).add(new ORecordId(ODatabaseRecordThreadLocal.instance().get().getStorage() .getConfiguration().getSchemaRecordId())); } else if (metadataTarget.equals(OCommandExecutorSQLAbstract.METADATA_INDEXMGR)) { ((ArrayList<OIdentifiable>) targetRecords).add(new ORecordId(ODatabaseRecordThreadLocal.instance().get().getStorage() .getConfiguration().getIndexMgrRecordId())); } else throw new OQueryParsingException("Metadata element not supported: " + metadataTarget); targetRecords = new ArrayList<OIdentifiable>(); final OIdentifiable value = ODatabaseRecordThreadLocal.instance().get().getDictionary().get(key); if (value != null) ((List<OIdentifiable>) targetRecords).add(value);
private void distributedDropIndex(final String iName) { String dropIndexDDL = "DROP INDEX `" + iName + "`"; //noinspection deprecation getDatabase().command(new OCommandSQL(dropIndexDDL)).execute(); ORecordInternal .setIdentity(delegate.getDocument(), new ORecordId(getDatabase().getStorage().getConfiguration().getIndexMgrRecordId())); reload(); }
return (RET) iValue; } else if (iValue instanceof String) { return (RET) new ORecordId((String) iValue); } else if (iValue instanceof ORecord) { return (RET) ((ORecord) iValue).getIdentity(); return (RET) iValue; } else if (iValue instanceof String) { return (RET) new ORecordId((String) iValue); } else if (OMultiValue.isMultiValue(iValue) && OMultiValue.getSize(iValue) == 1) { Object val = OMultiValue.getFirstValue(iValue); "Property '" + iFieldName + "' of type '" + iFieldType + "' cannot accept value of type: " + iValue.getClass()); } else if (Date.class.isAssignableFrom(iFieldType)) { if (iValue instanceof String && ODatabaseRecordThreadLocal.instance().isDefined()) { final OStorageConfiguration config = ODatabaseRecordThreadLocal.instance().get().getStorage().getConfiguration();
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); InputStream is; } else { try { is = new ByteArrayInputStream(statement.getBytes(db.getStorage().getConfiguration().getCharset())); } catch (UnsupportedEncodingException e2) { OLogManager.instance() .warn(null, "Unsupported charset for database " + db + " " + db.getStorage().getConfiguration().getCharset()); is = new ByteArrayInputStream(statement.getBytes()); } else { try { osql = new OrientSql(is, db.getStorage().getConfiguration().getCharset()); } catch (UnsupportedEncodingException e2) { OLogManager.instance() .warn(null, "Unsupported charset for database " + db + " " + db.getStorage().getConfiguration().getCharset()); osql = new OrientSql(is);
rid = new ORecordId( jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"rid\"").readString(OJSONReader.NEXT_IN_OBJECT)); } else int clusterId = name != null ? database.getClusterIdByName(name) : -1; if (clusterId == -1) { clusterId = database.addCluster(name); else { clusterId = database.addCluster(name, id, null); assert clusterId == id; if (database.load(new ORecordId(database.getStorage().getConfiguration().getIndexMgrRecordId())) == null) { ODocument indexDocument = new ODocument(); indexDocument.save(OMetadataDefault.CLUSTER_INTERNAL_NAME); database.getStorage().setIndexMgrRecordId(indexDocument.getIdentity().toString());
/** * Closes the transaction and releases all the acquired locks. */ @Override public void close() { for (Map.Entry<ORID, LockedRecordMetadata> lock : locks.entrySet()) { try { final LockedRecordMetadata lockedRecordMetadata = lock.getValue(); if (lockedRecordMetadata.strategy.equals(OStorage.LOCKING_STRATEGY.EXCLUSIVE_LOCK)) { for (int i = 0; i < lockedRecordMetadata.locksCount; i++) { ((OAbstractPaginatedStorage) getDatabase().getStorage().getUnderlying()).releaseWriteLock(lock.getKey()); } } else if (lockedRecordMetadata.strategy.equals(OStorage.LOCKING_STRATEGY.SHARED_LOCK)) { for (int i = 0; i < lockedRecordMetadata.locksCount; i++) { ((OAbstractPaginatedStorage) getDatabase().getStorage().getUnderlying()).releaseReadLock(lock.getKey()); } } } catch (Exception e) { OLogManager.instance().debug(this, "Error on releasing lock against record " + lock.getKey(), e); } } locks.clear(); }
if (!isClosed()) { if (commitTx) { final OStorage storage = getDatabase().getStorage().getUnderlying(); if (storage instanceof OAbstractPaginatedStorage) { if (((OAbstractPaginatedStorage) storage).getWALInstance() != null) getDatabase().commit(); } else { getDatabase().commit(); throw e; } catch (RuntimeException e) { OLogManager.instance().error(this, "Error during context close for db " + url, e); throw e; } catch (Exception e) { OLogManager.instance().error(this, "Error during context close for db " + url, e); throw OException.wrapException(new ODatabaseException("Error during context close for db " + url), e); } finally {
@Override public void recreateIndexes(ODatabaseDocumentInternal database) { acquireExclusiveLock(); try { if (recreateIndexesThread != null && recreateIndexesThread.isAlive()) // BUILDING ALREADY IN PROGRESS return; document = database.load(new ORecordId(database.getStorage().getConfiguration().getIndexMgrRecordId())); Runnable recreateIndexesTask = new RecreateIndexesTask(database.getStorage()); recreateIndexesThread = new Thread(recreateIndexesTask, "OrientDB rebuild indexes"); recreateIndexesThread.setUncaughtExceptionHandler(new OUncaughtExceptionHandler()); recreateIndexesThread.start(); } finally { releaseExclusiveLock(); } if (database.getConfiguration().getValueAsBoolean(OGlobalConfiguration.INDEX_SYNCHRONOUS_AUTO_REBUILD)) { waitTillIndexRestore(); database.getMetadata().reload(); } }
protected void internalDelete(String indexName) { try { if (mgrWriter != null && mgrWriter.getIndexWriter() != null) { closeIndex(); } ODatabaseDocumentInternal database = getDatabase(); final OAbstractPaginatedStorage storageLocalAbstract = (OAbstractPaginatedStorage) database.getStorage().getUnderlying(); if (storageLocalAbstract instanceof OLocalPaginatedStorage) { OLocalPaginatedStorage localAbstract = (OLocalPaginatedStorage) storageLocalAbstract; File f = new File(getIndexPath(localAbstract, indexName)); OLuceneIndexUtils.deleteFolder(f); f = new File(getIndexBasePath(localAbstract)); OLuceneIndexUtils.deleteFolderIfEmpty(f); } } catch (IOException e) { OLogManager.instance().error(this, "Error on deleting Lucene index", e); } }
rid = new ORecordId(iRecordId); else { OIdentifiable rec = setCurrentRecord(Integer.parseInt(iRecordId)); ORecordId id = new ORecordId(rid); if (!(currentDatabase.getStorage() instanceof OLocalPaginatedStorage)) { record = currentDatabase.getStorage().readRecord(rid, null, false, false, null).getResult(); if (record != null) { String content; final OLocalPaginatedStorage storage = (OLocalPaginatedStorage) currentDatabase.getStorage(); final OPaginatedCluster cluster = (OPaginatedCluster) storage.getClusterById(id.getClusterId()); if (cluster == null) { message("\n cluster with id %i does not exist", id.getClusterId());
public OSchemaShared load(ODatabaseDocumentInternal database) { rwSpinLock.acquireWriteLock(); try { if (!new ORecordId(database.getStorage().getConfiguration().getSchemaRecordId()).isValid()) throw new OSchemaNotCreatedException("Schema is not created and cannot be loaded"); ((ORecordId) document.getIdentity()).fromString(database.getStorage().getConfiguration().getSchemaRecordId()); reload("*:-1 index:0"); return this; } finally { rwSpinLock.releaseWriteLock(); } }
return getDatabase().getMetadata().getSchema().getClassByClusterId(new ORecordId(iTarget).getClusterId()); return getDatabase().getMetadata().getSchema().getClass(iTarget); OClass candidateClass = null; for(String cName:clusterNames){ OCluster aCluster = db.getStorage().getClusterByName(cName.trim()); if(aCluster == null){ return null; OCluster cluster = db.getStorage().getClusterByName(clusterName); if (cluster != null) { return db.getMetadata().getSchema().getClassByClusterId(cluster.getId());