public OIndexInternal<?> createIndex(String name, OStorage storage, String indexType, String algorithm, String valueContainerAlgorithm, ODocument metadata, int version) throws OConfigurationException { if (valueContainerAlgorithm == null) { valueContainerAlgorithm = NONE_VALUE_CONTAINER; } if (version < 0) { version = getLastVersion(); } return createSBTreeIndex(name, indexType, valueContainerAlgorithm, metadata, (OAbstractPaginatedStorage) storage.getUnderlying(), version, algorithm); }
public OIndexInternal<?> createIndex(String name, OStorage storage, String indexType, String algorithm, String valueContainerAlgorithm, ODocument metadata, int version) throws OConfigurationException { if (valueContainerAlgorithm == null) valueContainerAlgorithm = NONE_VALUE_CONTAINER; if (version < 0) version = getLastVersion(); if (AUTOSHARDING_ALGORITHM.equals(algorithm)) return createShardedIndex(name, indexType, valueContainerAlgorithm, metadata, (OAbstractPaginatedStorage) storage.getUnderlying(), version); throw new OConfigurationException("Unsupported type: " + indexType); }
@Override public OBaseIndexEngine createIndexEngine(final String algorithm, final String name, final Boolean durableInNonTxMode, final OStorage storage, final int version, int apiVersion, boolean multivalue, final Map<String, String> engineProperties) { final OIndexEngine indexEngine; final String storageType = storage.getType(); if (storageType.equals("memory") || storageType.equals("plocal")) indexEngine = new OAutoShardingIndexEngine(name, (OAbstractPaginatedStorage) storage, version); else if (storageType.equals("distributed")) // DISTRIBUTED CASE: HANDLE IT AS FOR LOCAL indexEngine = new OAutoShardingIndexEngine(name, (OAbstractPaginatedStorage) storage.getUnderlying(), version); else if (storageType.equals("remote")) // MANAGE REMOTE SHARDED INDEX TO CALL THE INTERESTED SERVER indexEngine = new ORemoteIndexEngine(name); else throw new OIndexException("Unsupported storage type: " + storageType); return indexEngine; } }
@Override public OBaseIndexEngine createIndexEngine(final String algoritm, final String name, final Boolean durableInNonTxMode, final OStorage storage, final int version, int apiVersion, boolean multivalue, final Map<String, String> engineProperties) { OIndexEngine indexEngine; final String storageType = storage.getType(); if (storageType.equals("memory") || storageType.equals("plocal")) indexEngine = new OHashTableIndexEngine(name, (OAbstractPaginatedStorage) storage, version); else if (storageType.equals("distributed")) // DISTRIBUTED CASE: HANDLE IT AS FOR LOCAL indexEngine = new OHashTableIndexEngine(name, (OAbstractPaginatedStorage) storage.getUnderlying(), version); else if (storageType.equals("remote")) indexEngine = new ORemoteIndexEngine(name); else throw new OIndexException("Unsupported storage type: " + storageType); return indexEngine; } }
private void internalDelete() throws IOException { if (indexWriter != null && indexWriter.isOpen()) { close(); } final OAbstractPaginatedStorage storageLocalAbstract = (OAbstractPaginatedStorage) storage.getUnderlying(); if (storageLocalAbstract instanceof OLocalPaginatedStorage) { deleteIndexFolder(); } }
protected OMicroTransaction beginMicroTransaction() { final OAbstractPaginatedStorage abstractPaginatedStorage = (OAbstractPaginatedStorage) getStorage().getUnderlying(); if (microTransaction == null) microTransaction = new OMicroTransaction(abstractPaginatedStorage, this); microTransaction.begin(); return microTransaction; }
private Directory getTaxDirectory(ODatabaseDocumentInternal database) throws IOException { Directory dir = null; final OAbstractPaginatedStorage storageLocalAbstract = (OAbstractPaginatedStorage) database.getStorage().getUnderlying(); if (storageLocalAbstract instanceof OLocalPaginatedStorage) { String pathname = getIndexFacetPath((OLocalPaginatedStorage) storageLocalAbstract); dir = NIOFSDirectory.open(new File(pathname)); } else { dir = new RAMDirectory(); } return dir; }
public void checkEmbedded() { if (!(getDatabase().getStorage().getUnderlying() instanceof OAbstractPaginatedStorage)) throw new OSchemaException("'Internal' schema modification methods can be used only inside of embedded database"); }
public OIndexAbstract(String name, final String type, final String algorithm, final String valueContainerAlgorithm, final ODocument metadata, final int version, final OStorage storage, int binaryFormatVersion) { this.binaryFormatVersion = binaryFormatVersion; acquireExclusiveLock(); try { databaseName = storage.getName(); this.version = version; this.name = name; this.type = type; this.algorithm = algorithm; this.metadata = metadata; this.valueContainerAlgorithm = valueContainerAlgorithm; this.storage = (OAbstractPaginatedStorage) storage.getUnderlying(); } finally { releaseExclusiveLock(); } }
@Override public boolean add(OIdentifiable oIdentifiable) { if (embeddedSet.contains(oIdentifiable.getIdentity())) { return false; } if (embeddedSet.size() < topThreshold) { return embeddedSet.add(oIdentifiable.getIdentity()); } if (tree == null) { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().get(); tree = new OIndexRIDContainerSBTree(fileId, (OAbstractPaginatedStorage) db.getStorage().getUnderlying()); } return tree.add(oIdentifiable); }
public void delete() { ODatabaseDocumentInternal database = owner.getDatabase(); final OAbstractPaginatedStorage storageLocalAbstract = (OAbstractPaginatedStorage) database.getStorage().getUnderlying(); if (storageLocalAbstract instanceof OLocalPaginatedStorage) { File f = new File(getIndexFacetPath((OLocalPaginatedStorage) storageLocalAbstract)); OLuceneIndexUtils.deleteFolder(f); f = new File(owner.getIndexBasePath((OLocalPaginatedStorage) storageLocalAbstract)); OLuceneIndexUtils.deleteFolderIfEmpty(f); } }
public boolean addEntry(OIdentifiable identifiable) { if (embeddedSet.contains(identifiable.getIdentity())) { return false; } if (embeddedSet.size() < topThreshold) { return embeddedSet.add(identifiable.getIdentity()); } boolean treeWasCreated = false; if (tree == null) { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().get(); tree = new OIndexRIDContainerSBTree(fileId, (OAbstractPaginatedStorage) db.getStorage().getUnderlying()); treeWasCreated = true; } tree.add(identifiable); return treeWasCreated; }
@Override public OIndexInternal<?> createIndex(String name, OStorage storage, String indexType, String algorithm, String valueContainerAlgorithm, ODocument metadata, int version) throws OConfigurationException { OAbstractPaginatedStorage pagStorage = (OAbstractPaginatedStorage) storage.getUnderlying(); if (metadata == null) metadata = new ODocument().field("analyzer", StandardAnalyzer.class.getName()); if (FULLTEXT.toString().equalsIgnoreCase(indexType)) { final int binaryFormatVersion = pagStorage.getConfiguration().getBinaryFormatVersion(); OLuceneFullTextIndex index = new OLuceneFullTextIndex(name, indexType, algorithm, version, pagStorage, valueContainerAlgorithm, metadata, binaryFormatVersion); return index; } throw new OConfigurationException("Unsupported type : " + algorithm); }
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; } }
private OLocalPaginatedStorage storage() { if (storage == null || storage.isClosed()) { // use temp TX to get local storage; note we don't need a TX when reading write-ahead-log ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.instance().getIfDefined(); try (ODatabaseDocumentInternal db = databaseProvider.get().acquire()) { storage = (OLocalPaginatedStorage) db.getStorage().getUnderlying(); } finally { ODatabaseRecordThreadLocal.instance().set(currentDb); } } return storage; }
private void removeClusterFromIndexes(final int iId) { if (getDatabase().getStorage().getUnderlying() instanceof OAbstractPaginatedStorage) { final String clusterName = getDatabase().getClusterNameById(iId); final List<String> indexesToRemove = new ArrayList<String>(); for (final OIndex<?> index : getIndexes()) indexesToRemove.add(index.getName()); final OIndexManager indexManager = getDatabase().getMetadata().getIndexManager(); for (final String indexName : indexesToRemove) indexManager.removeClusterFromIndex(clusterName, indexName); } }
private void addClusterIdToIndexes(int iId) { ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (database != null && database.getStorage().getUnderlying() instanceof OAbstractPaginatedStorage) { final String clusterName = getDatabase().getClusterNameById(iId); final List<String> indexesToAdd = new ArrayList<String>(); for (OIndex<?> index : getIndexes()) indexesToAdd.add(index.getName()); final OIndexManager indexManager = getDatabase().getMetadata().getIndexManager(); for (String indexName : indexesToAdd) indexManager.addClusterToIndex(clusterName, indexName); } }
@Override public OIndexInternal<?> createIndex(String name, OStorage storage, String indexType, String algorithm, String valueContainerAlgorithm, ODocument metadata, int version) throws OConfigurationException { OAbstractPaginatedStorage pagStorage = (OAbstractPaginatedStorage) storage.getUnderlying(); OBinarySerializer<?> objectSerializer = storage.getComponentsFactory().binarySerializerFactory .getObjectSerializer(OLuceneMockSpatialSerializer.INSTANCE.getId()); if (objectSerializer == null) { storage.getComponentsFactory().binarySerializerFactory .registerSerializer(OLuceneMockSpatialSerializer.INSTANCE, OType.EMBEDDED); } if (metadata == null) metadata = new ODocument().field("analyzer", StandardAnalyzer.class.getName()); if (OClass.INDEX_TYPE.SPATIAL.toString().equals(indexType)) { final int binaryFormatVersion = pagStorage.getConfiguration().getBinaryFormatVersion(); return new OLuceneSpatialIndex(name, indexType, LUCENE_ALGORITHM, version, pagStorage, valueContainerAlgorithm, metadata, binaryFormatVersion); } throw new OConfigurationException("Unsupported type : " + algorithm); }
@Override public void delete() { try { updateLastAccess(); openIfClosed(); if (indexWriter != null && indexWriter.isOpen()) { doClose(true); } final OAbstractPaginatedStorage storageLocalAbstract = (OAbstractPaginatedStorage) storage.getUnderlying(); if (storageLocalAbstract instanceof OLocalPaginatedStorage) { deleteIndexFolder(); } } catch (IOException e) { throw OException.wrapException(new OStorageException("Error during deletion of Lucene index " + name), e); } }
public OAutoShardingClusterSelectionStrategy(final OClass clazz, final OIndex autoShardingIndex) { index = autoShardingIndex; if (index == null) throw new OConfigurationException( "Cannot use auto-sharding cluster strategy because class '" + clazz + "' has no auto-sharding index defined"); indexedFields = index.getDefinition().getFields(); if (indexedFields.size() != 1) throw new OConfigurationException("Cannot use auto-sharding cluster strategy because class '" + clazz + "' has an auto-sharding index defined with multiple fields"); final OStorage stg = ODatabaseRecordThreadLocal.instance().get().getStorage().getUnderlying(); if (!(stg instanceof OAbstractPaginatedStorage)) throw new OConfigurationException("Cannot use auto-sharding cluster strategy because storage is not embedded"); try { indexEngine = (OIndexEngine) ((OAbstractPaginatedStorage) stg).getIndexEngine(index.getIndexId()); } catch (OInvalidIndexEngineIdException e) { throw OException.wrapException( new OConfigurationException("Cannot use auto-sharding cluster strategy because the underlying index has not found"), e); } if (indexEngine == null) throw new OConfigurationException("Cannot use auto-sharding cluster strategy because the underlying index has not found"); clusters = clazz.getClusterIds(); }