@Override public int[] getClusterIds() { return delegate.getClusterIds(); }
private void removeClusterClassMap(final OClass cls) { for (int clusterId : cls.getClusterIds()) { if (clusterId < 0) continue; clustersToClasses.remove(clusterId); } }
protected void addClusterClassMap(final OClass cls) { for (int clusterId : cls.getClusterIds()) { if (clusterId < 0) continue; clustersToClasses.put(clusterId, cls); } }
public AdapterIndex(final List<EntityAdapter> adapters) { adapters.forEach(adapter -> { for (int clusterId : adapter.getSchemaType().getClusterIds()) { index.put(clusterId, adapter); } }); }
public int getCluster(final OClass iClass, final ODocument doc) { return getCluster(iClass, iClass.getClusterIds(), doc); }
public int getCluster(final OClass iClass, final ODocument doc) { return getCluster(iClass, iClass.getClusterIds(), doc); }
/** * @see #doDecode(OClass, String) */ @Override public ORID decode(final OClass type, final String encoded) { checkNotNull(type); checkNotNull(encoded); log.trace("Decoding: {}->{}", type, encoded); ORID rid; try { rid = doDecode(type, encoded); } catch (Exception e) { log.error("Failed to decode: {}->{}", type, encoded); Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } // ensure rid points to the right type checkArgument(Ints.contains(type.getClusterIds(), rid.getClusterId()), "Invalid RID '%s' for class: %s", rid, type); return rid; }
@Override public int getClusterIdByName(String clusterName, Class<?> clazz) { OClass oClass = dbf.db().getMetadata().getSchema().getClass(clazz); for (int clusterId : oClass.getClusterIds()) { if (getClusterNameById(clusterId).equals(clusterName)) { return clusterId; } } throw new IllegalArgumentException("Cluster " + clusterName + " not found"); }
@Deprecated public ORecordIteratorClass(final ODatabaseDocumentInternal iDatabase, final String iClassName, final boolean iPolymorphic, final OStorage.LOCKING_STRATEGY iLockingStrategy) { super(iDatabase, iLockingStrategy); targetClass = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(iClassName); if (targetClass == null) throw new IllegalArgumentException("Class '" + iClassName + "' was not found in database schema"); polymorphic = iPolymorphic; clusterIds = polymorphic ? targetClass.getPolymorphicClusterIds() : targetClass.getClusterIds(); clusterIds = OClassImpl.readableClusters(iDatabase, clusterIds); checkForSystemClusters(iDatabase, clusterIds); Arrays.sort(clusterIds); config(); }
@Override public List<String> getClusterNamesByClass(Class<?> clazz, boolean showDefault) { int[] clusterIds = dbf.db().getMetadata().getSchema().getClass(clazz).getClusterIds(); int defaultCluster = getDefaultClusterId(clazz); List<String> clusters = new ArrayList<>(clusterIds.length); for (int clusterId : clusterIds) { if (showDefault || clusterId != defaultCluster) { clusters.add(getClusterNameById(clusterId)); } } return clusters; }
@Override public List<String> getClusterNamesByClass(Class<?> clazz, boolean showDefault) { int[] clusterIds = dbf.db().getMetadata().getSchema().getClass(clazz).getClusterIds(); int defaultCluster = getDefaultClusterId(clazz); List<String> clusters = new ArrayList<>(clusterIds.length); for (int clusterId : clusterIds) { if (showDefault || clusterId != defaultCluster) { clusters.add(getClusterNameById(clusterId)); } } return clusters; }
/** * Enables password-based-encryption for records of the given type. * * Can only be called when creating the schema. * * @since 3.1 */ protected void enableRecordEncryption(final ODatabaseDocumentTx db, final OClass type) { OStorage storage = db.getStorage(); for (int clusterId : type.getClusterIds()) { OCluster cluster = storage.getClusterById(clusterId); try { log.debug("Enabling PBE compression for cluster: {}", cluster.getName()); cluster.set(OCluster.ATTRIBUTES.COMPRESSION, PbeCompression.NAME); } catch (IOException e) { throw new RuntimeException(e); } catch (IllegalArgumentException | OStorageException | OSecurityException e) { log.warn("Cannot enable PBE compression for cluster: {}", cluster.getName(), e); } } }
protected boolean isClusterDeletable(int clusterId) { final ODatabaseDocument database = getDatabase(); for (OClass iClass : database.getMetadata().getSchema().getClasses()) { for (int i : iClass.getClusterIds()) { if (i == clusterId) return false; } } return true; }
@Override public int getClusterIdByName(String clusterName, Class<?> clazz) { OClass oClass = dbf.db().getMetadata().getSchema().getClass(clazz); for(int clusterId : oClass.getClusterIds()){ if(getClusterNameById(clusterId).equals(clusterName)){ return clusterId; } } throw new OException("Cluster " + clusterName + " not found"); }
protected Set<String> getInvolvedClustersOfIndex(final String iIndexName) { final ODatabaseDocumentInternal db = getDatabase(); final Set<String> clusters = new HashSet<String>(); final OMetadataInternal metadata = (OMetadataInternal) db.getMetadata(); final OIndex<?> idx = metadata.getIndexManager().getIndex(iIndexName); if (idx != null && idx.getDefinition() != null) { final String clazz = idx.getDefinition().getClassName(); if (clazz != null) { final OClass cls = metadata.getImmutableSchemaSnapshot().getClass(clazz); if (cls != null) for (int clId : cls.getClusterIds()) { final String clName = db.getClusterNameById(clId); if (clName != null) clusters.add(clName.toLowerCase(Locale.ENGLISH)); } } } return clusters; }
private static void browseClass(final ODatabaseDocument db, Set<ORID> iSourceRIDs, final Map<ORID, Set<ORID>> map, final String iClassName) { final OClass clazz = ((OMetadataInternal)db.getMetadata()).getImmutableSchemaSnapshot().getClass(iClassName); if (clazz == null) throw new OCommandExecutionException("Class '" + iClassName + "' was not found"); for (int i : clazz.getClusterIds()) { browseCluster(db, iSourceRIDs, map, db.getClusterNameById(i)); } }
private void invalidateCommandCache(OClass clazz, ODatabase db) { if (clazz == null) { return; } OCommandCache commandCache = ((OMetadataInternal)db.getMetadata()).getCommandCache(); if (commandCache != null && commandCache.isEnabled()) { int[] clusterIds = clazz.getClusterIds(); if (clusterIds != null) { for (int i : clusterIds) { String clusterName = getDatabase().getClusterNameById(i); if (clusterName != null) { commandCache.invalidateResultsOfCluster(clusterName); } } } } }
private void invalidateCommandCache(OClass clazz) { if (clazz == null) { return; } OCommandCache commandCache = getDatabase().getMetadata().getCommandCache(); if (commandCache != null && commandCache.isEnabled()) { int[] clusterIds = clazz.getClusterIds(); if (clusterIds != null) { for (int i : clusterIds) { String clusterName = getDatabase().getClusterNameById(i); if (clusterName != null) { commandCache.invalidateResultsOfCluster(clusterName); } } } } }
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(); }
/** * Execute the DROP CLUSTER. */ public Object execute(final Map<Object, Object> iArgs) { if (clusterName == null) throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet"); final ODatabaseDocumentInternal database = getDatabase(); // CHECK IF ANY CLASS IS USING IT final int clusterId = database.getStorage().getClusterIdByName(clusterName); for (OClass iClass : database.getMetadata().getSchema().getClasses()) { for (int i : iClass.getClusterIds()) { if (i == clusterId) // IN USE return false; } } // REMOVE CACHE OF COMMAND RESULTS IF ACTIVE database.getMetadata().getCommandCache().invalidateResultsOfCluster(clusterName); database.dropCluster(clusterId, true); return true; }