private int[] createClusters(String className) { className = className.toLowerCase(); final ODatabaseDocumentInternal database = getDatabase(); final OStorage storage = database.getStorage(); int[] clusterIds; // CREATE A NEW CLUSTER(S) final int minimumClusters = storage.getConfiguration().getMinimumClusters(); clusterIds = new int[minimumClusters]; if (minimumClusters <= 1) { clusterIds[0] = database.getClusterIdByName(className); if (clusterIds[0] == -1) clusterIds[0] = database.addCluster(className); } else for (int i = 0; i < minimumClusters; ++i) { clusterIds[i] = database.getClusterIdByName(className + "_" + i); if (clusterIds[i] == -1) clusterIds[i] = database.addCluster(className + "_" + i); } return clusterIds; }
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()); 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()); 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]); }