private static Set<String> findClustersByIds(int[] clusterIdsToIndex, ODatabase database) { Set<String> clustersToIndex = new HashSet<>(); if (clusterIdsToIndex != null) { for (int clusterId : clusterIdsToIndex) { final String clusterNameToIndex = database.getClusterNameById(clusterId); if (clusterNameToIndex == null) throw new OIndexException("Cluster with id " + clusterId + " does not exist."); clustersToIndex.add(clusterNameToIndex); } } return clustersToIndex; }
@Override public OIndexInternal<?> create(OIndexDefinition indexDefinition, String clusterIndexName, Set<String> clustersToIndex, boolean rebuild, OProgressListener progressListener, OBinarySerializer valueSerializer) { if (indexDefinition.getFields().size() > 1) { throw new OIndexException(type + " indexes cannot be used as composite ones."); } return super.create(indexDefinition, clusterIndexName, clustersToIndex, rebuild, progressListener, valueSerializer); }
@Override public void create(OBinarySerializer valueSerializer, boolean isAutomatic, OType[] keyTypes, boolean nullPointerSupport, OBinarySerializer keySerializer, int keySize, Set<String> clustersToIndex, Map<String, String> engineProperties, ODocument metadata, OEncryption encryption) { try { //noinspection unchecked sbTree.create(keySerializer, valueSerializer, keyTypes, keySize, nullPointerSupport, encryption); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during creation of index " + name), e); } }
@Override public boolean remove(Object key) { try { return sbTree.remove(key) != null; } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during removal of key " + key + " from index " + name), e); } }
@Override public void put(Object key, ORID value) { try { sbTree.put(key, value); } catch (IOException e) { throw OException .wrapException(new OIndexException("Error during insertion of key " + key + " and RID " + value + " to index " + name), e); } }
@Override public void clear() { try { sbTree.clear(); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during clear index " + name), e); } }
@Override public void update(Object key, OIndexKeyUpdater<Object> updater) { try { sbTree.update(key, updater, null); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during update of key " + key + " in index " + name), e); } }
@Override public void clear() { try { sbTree.clear(); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during clearing of index " + name), e); } }
@Override public void delete() { try { sbTree.delete(); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during deletion of index " + name), e); } }
@Override public void clear() { try { sbTree.clear(); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during clear of index " + name), e); } }
@Override public boolean validatedPut(Object key, ORID value, Validator<Object, ORID> validator) { try { return sbTree.validatedPut(key, value, validator); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during insertion of key " + key + " into index " + name), e); } }
@Override public void delete() { try { sbTree.delete(); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during deletion of index " + name), e); } }
@Override public void deleteWithoutLoad(String indexName) { try { sbTree.deleteWithoutLoad(); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during deletion of index " + name), e); } }
private static OIndexFactory findFactoryByAlgorithmAndType(String algorithm, String indexType) { for (OIndexFactory factory : getFactories()) { if (indexType == null || indexType.isEmpty() || (factory.getTypes().contains(indexType)) && factory.getAlgorithms() .contains(algorithm)) { return factory; } } throw new OIndexException( "Index type " + indexType + " with engine " + algorithm + " is not supported. Types are " + OCollections .toString(getIndexTypes())); }
@Override public void put(final Object key, final Object value) { try { getPartition(key).put(key, value); } catch (IOException e) { throw OException .wrapException(new OIndexException("Error during insertion of key " + key + " of index with name " + name), e); } }
public Object createSingleValue(final Object... param) { try { return OType.convert(param[0], keyType.getDefaultJavaType()); } catch (Exception e) { OException ex = OException .wrapException(new OIndexException("Invalid key for index: " + param[0] + " cannot be converted to " + keyType), e); throw ex; } }
@Override public boolean remove(final Object key) { try { return getPartition(key).remove(key) != null; } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during deletion of key " + key + " of index with name " + name), e); } }
private static ODocument checkForLoading(final ODocument iRecord) { if (iRecord.getInternalStatus() == ORecordElement.STATUS.NOT_LOADED) { try { return (ODocument) iRecord.load(); } catch (final ORecordNotFoundException e) { throw OException.wrapException(new OIndexException("Error during loading of record with id " + iRecord.getIdentity()), e); } } return iRecord; }
private Set<OIdentifiable> getResults(Query query, OCommandContext context, Object key) { try { IndexSearcher searcher = getSearcher(); QueryContext queryContext = new QueryContext(context, searcher, query); if (facetManager.supportsFacets()) { facetManager.addFacetContext(queryContext, key); } return new LuceneResultSet(this, queryContext); } catch (IOException e) { throw new OIndexException("Error reading from Lucene index", e); } }
private OIndexInternal<?> createIndex(ODocument idx) { final String indexName = idx.field(OIndexInternal.CONFIG_NAME); final String indexType = idx.field(OIndexInternal.CONFIG_TYPE); String algorithm = idx.field(OIndexInternal.ALGORITHM); String valueContainerAlgorithm = idx.field(OIndexInternal.VALUE_CONTAINER_ALGORITHM); ODocument metadata = idx.field(OIndexInternal.METADATA); if (indexType == null) { OLogManager.instance().error(this, "Index type is null, will process other record", null); throw new OIndexException("Index type is null, will process other record. Index configuration: " + idx.toString()); } return OIndexes.createIndex(storage, indexName, indexType, algorithm, valueContainerAlgorithm, metadata, -1); } }