use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateCluster method parse.
public OCommandExecutorSQLCreateCluster parse(final OCommandRequest iRequest) {
final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
String queryText = textRequest.getText();
String originalQuery = queryText;
try {
queryText = preParse(queryText, iRequest);
textRequest.setText(queryText);
final ODatabaseDocumentInternal database = getDatabase();
init((OCommandRequestText) iRequest);
parserRequiredKeyword(KEYWORD_CREATE);
String nextWord = parserRequiredWord(true);
if (nextWord.equals("BLOB")) {
parserRequiredKeyword(KEYWORD_CLUSTER);
blob = true;
} else if (!nextWord.equals(KEYWORD_CLUSTER)) {
throw new OCommandSQLParsingException("Invalid Syntax: " + queryText);
}
clusterName = parserRequiredWord(false);
clusterName = decodeClassName(clusterName);
if (!clusterName.isEmpty() && Character.isDigit(clusterName.charAt(0)))
throw new IllegalArgumentException("Cluster name cannot begin with a digit");
String temp = parseOptionalWord(true);
while (temp != null) {
if (temp.equals(KEYWORD_ID)) {
requestedId = Integer.parseInt(parserRequiredWord(false));
}
temp = parseOptionalWord(true);
if (parserIsEnded())
break;
}
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropCluster method execute.
/**
* 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
getDatabase().getMetadata().getCommandCache().invalidateResultsOfCluster(clusterName);
database.dropCluster(clusterId, true);
return true;
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OCommandExecutorSQLAbstract method getInvolvedClustersOfIndex.
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;
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OCommandExecutorSQLAlterCluster method getClusters.
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;
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OCommandExecutorSQLResultsetAbstract method searchInClusters.
protected void searchInClusters() {
final ODatabaseDocumentInternal database = getDatabase();
final Set<Integer> clusterIds = new HashSet<Integer>();
for (String clusterName : parsedTarget.getTargetClusters().keySet()) {
if (clusterName == null || clusterName.length() == 0)
throw new OCommandExecutionException("No cluster or schema class selected in query");
database.checkSecurity(ORule.ResourceGeneric.CLUSTER, ORole.PERMISSION_READ, clusterName.toLowerCase(Locale.ENGLISH));
if (Character.isDigit(clusterName.charAt(0))) {
// GET THE CLUSTER NUMBER
for (int clusterId : OStringSerializerHelper.splitIntArray(clusterName)) {
if (clusterId == -1)
throw new OCommandExecutionException("Cluster '" + clusterName + "' not found");
clusterIds.add(clusterId);
}
} else {
// GET THE CLUSTER NUMBER BY THE CLASS NAME
final int clusterId = database.getClusterIdByName(clusterName.toLowerCase(Locale.ENGLISH));
if (clusterId == -1)
throw new OCommandExecutionException("Cluster '" + clusterName + "' not found");
clusterIds.add(clusterId);
}
}
// CREATE CLUSTER AS ARRAY OF INT
final int[] clIds = new int[clusterIds.size()];
int i = 0;
for (int c : clusterIds) clIds[i++] = c;
final ORID[] range = getRange();
target = new ORecordIteratorClusters<ORecord>(database, database, clIds).setRange(range[0], range[1]);
}
Aggregations