Search in sources :

Example 11 with ODatabaseDocumentInternal

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;
}
Also used : OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 12 with ODatabaseDocumentInternal

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;
}
Also used : OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 13 with ODatabaseDocumentInternal

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;
}
Also used : OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 14 with ODatabaseDocumentInternal

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;
}
Also used : OCluster(com.orientechnologies.orient.core.storage.OCluster) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 15 with ODatabaseDocumentInternal

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]);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ORecordIteratorClusters(com.orientechnologies.orient.core.iterator.ORecordIteratorClusters) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ORID(com.orientechnologies.orient.core.id.ORID) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Aggregations

ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)149 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)42 OStorage (com.orientechnologies.orient.core.storage.OStorage)31 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)26 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)20 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)18 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)16 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)16 ORID (com.orientechnologies.orient.core.id.ORID)14 OException (com.orientechnologies.common.exception.OException)13 IOException (java.io.IOException)13 ORecordId (com.orientechnologies.orient.core.id.ORecordId)12 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)10 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)10 ORecord (com.orientechnologies.orient.core.record.ORecord)8 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)7 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)6 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)5 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)5