public OCommandCacheHook(final ODatabaseDocumentInternal iDatabase) { database = iDatabase; cmdCache = iDatabase.getMetadata().getCommandCache().isEnabled() ? iDatabase.getMetadata().getCommandCache() : null; }
/** * Execute the ALTER CLASS. */ public Object execute(final Map<Object, Object> iArgs) { if (attribute == null) throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet"); final List<OCluster> clusters = getClusters(); if (clusters.isEmpty()) throw new OCommandExecutionException("Cluster '" + clusterName + "' not found"); Object result = null; for (OCluster cluster : getClusters()) { if (clusterId > -1 && clusterName.equals(String.valueOf(clusterId))) { clusterName = cluster.getName(); } else { clusterId = cluster.getId(); } try { if (attribute == ATTRIBUTES.STATUS && OStorageClusterConfiguration.STATUS.OFFLINE.toString().equalsIgnoreCase(value)) // REMOVE CACHE OF COMMAND RESULTS IF ACTIVE getDatabase().getMetadata().getCommandCache().invalidateResultsOfCluster(clusterName); if (attribute == ATTRIBUTES.NAME) // REMOVE CACHE OF COMMAND RESULTS IF ACTIVE getDatabase().getMetadata().getCommandCache().invalidateResultsOfCluster(clusterName); result = cluster.set(attribute, value); } catch (IOException ioe) { throw OException.wrapException(new OCommandExecutionException("Error altering cluster '" + clusterName + "'"), ioe); } } return result; }
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); } } } } }
@Override public OResultSet executeDDL(OCommandContext ctx) { OInternalResultSet result = new OInternalResultSet(); List<com.orientechnologies.orient.core.storage.OCluster> clustersToUpdate = getClusters(ctx); Object finalValue = attributeValue.execute((OIdentifiable) null, ctx); com.orientechnologies.orient.core.storage.OCluster.ATTRIBUTES attribute; try { attribute = OCluster.ATTRIBUTES.valueOf(attributeName.getStringValue()); } catch (IllegalArgumentException e) { throw OException.wrapException(new OCommandExecutionException( "Unknown class attribute '" + attributeName + "'. Supported attributes are: " + Arrays .toString(OCluster.ATTRIBUTES.values())), e); } for (com.orientechnologies.orient.core.storage.OCluster cluster : clustersToUpdate) { if (attributeName.getStringValue().equalsIgnoreCase("status") || attributeName.getStringValue().equalsIgnoreCase("name")) // REMOVE CACHE OF COMMAND RESULTS IF ACTIVE getDatabase().getMetadata().getCommandCache().invalidateResultsOfCluster(cluster.getName()); try { cluster.set(attribute, finalValue); } catch (IOException e) { OException.wrapException(new OCommandExecutionException("Cannot execute alter cluster"), e); } OResultInternal resultItem = new OResultInternal(); resultItem.setProperty("cluster", cluster.getName()); result.add(resultItem); } return result; }
getDatabase().getMetadata().getCommandCache().invalidateResultsOfCluster(getDatabase().getClusterNameById(clId));
/** * 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; }
if (iCommand.isCacheableResult() && executor.isCacheable() && iCommand.getParameters() == null) { result = db.getMetadata().getCommandCache().get(db.getUser(), iCommand.getText(), iCommand.getLimit()); db.getMetadata().getCommandCache() .put(db.getUser(), iCommand.getText(), result, iCommand.getLimit(), executor.getInvolvedClusters(), System.currentTimeMillis() - beginTime);
((OMetadataInternal) database.getMetadata()).getCommandCache().invalidateResultsOfCluster(clusterName);