private OLuceneFullTextIndex searchForIndex(OCommandContext ctx, String className) { OMetadata dbMetadata = ctx.getDatabase().activateOnCurrentThread().getMetadata(); List<OLuceneFullTextIndex> indices = dbMetadata.getSchema().getClass(className).getIndexes().stream() .filter(idx -> idx instanceof OLuceneFullTextIndex).map(idx -> (OLuceneFullTextIndex) idx).collect(Collectors.toList()); if (indices.size() > 1) { throw new IllegalArgumentException("too many full-text indices on given class: " + className); } return indices.size() == 0 ? null : indices.get(0); }
void createUser(final ODatabase<?> database) { database.getMetadata().getSecurity().createUser( userName, new String(password), database.getMetadata().getSecurity().getRole(ORole.ADMIN) ); } }
private OLuceneFullTextIndex searchForIndex(String className, OCommandContext ctx, List<String> fieldNames) { OMetadata dbMetadata = ctx.getDatabase().activateOnCurrentThread().getMetadata(); List<OLuceneFullTextIndex> indices = dbMetadata.getSchema().getClass(className).getIndexes().stream() .filter(idx -> idx instanceof OLuceneFullTextIndex).map(idx -> (OLuceneFullTextIndex) idx) .filter(idx -> intersect(idx.getDefinition().getFields(), fieldNames)).collect(Collectors.toList()); if (indices.size() > 1) { throw new IllegalArgumentException("too many indices matching given field name: " + String.join(",", fieldNames)); } return indices.size() == 0 ? null : indices.get(0); }
/** * retrieves a class from the schema * * @param className The class name * * @return The object representing the class in the schema. Null if the class does not exist. */ default OClass getClass(String className) { OSchema schema = getMetadata().getSchema(); return schema.getClass(className); }
public Object execute(Object iThis, final OIdentifiable iCurrentRecord, Object iCurrentResult, final Object[] iParams, OCommandContext iContext) { final Object value = iParams[0]; String indexName = String.valueOf(value); OIndex<?> index = iContext.getDatabase().getMetadata().getIndexManager().getIndex(indexName); if (index == null) { return null; } return index.getKeySize(); }
@Override public boolean existsClass(String className) { return dbf.db().getMetadata().getSchema().existsClass(className); }
protected static OLuceneFullTextIndex getLuceneFullTextIndex(OCommandContext ctx, String indexName) { OMetadata metadata = ctx.getDatabase().activateOnCurrentThread().getMetadata(); OLuceneFullTextIndex index = (OLuceneFullTextIndex) metadata.getIndexManager().getIndex(indexName); if (!(index instanceof OLuceneFullTextIndex)) { throw new IllegalArgumentException("Not a valid Lucene index:: " + indexName); } return index; }
@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"); }
private void loadDefaultClusters() { if (defaultClusters == null) { synchronized (this) { if (defaultClusters == null) { defaultClusters = new HashSet<>(); for (OClass oClass : dbf.db().getMetadata().getSchema().getClasses()) { String defaultCluster = getClusterNameById(oClass.getDefaultClusterId()); defaultClusters.add(defaultCluster); } } } } }
private void loadDefaultClusters() { if (defaultClusters == null) { synchronized (this) { if (defaultClusters == null) { defaultClusters = new HashSet<>(); for (OClass oClass : dbf.db().getMetadata().getSchema().getClasses()) { String defaultCluster = getClusterNameById(oClass.getDefaultClusterId()); defaultClusters.add(defaultCluster); } } } } }
@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; }
private List<OIndex<?>> relatedIndexes(final String fieldName, ODatabase database) { final List<OIndex<?>> result = new ArrayList<OIndex<?>>(); for (final OIndex<?> oIndex : database.getMetadata().getIndexManager().getClassIndexes(className.getStringValue())) { if (OCollections.indexOf(oIndex.getDefinition().getFields(), fieldName, new OCaseInsentiveComparator()) > -1) { result.add(oIndex); } } return result; }
private OLuceneFullTextIndex searchForIndex(OCommandContext ctx, String indexName) { OIndex<?> index = ctx.getDatabase().getMetadata().getIndexManager().getIndex(indexName); if (index != null && index.getInternal() instanceof OLuceneFullTextIndex) { return (OLuceneFullTextIndex) index; } return null; }
@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"); }
private OLuceneFullTextIndex searchForIndex(String className, OCommandContext ctx, OExpression... args) { String indexName = (String) args[0].execute((OIdentifiable) null, ctx); OIndex<?> index = ctx.getDatabase().getMetadata().getIndexManager().getClassIndex(className, indexName); if (index != null && index.getInternal() instanceof OLuceneFullTextIndex) { return (OLuceneFullTextIndex) index; } return null; }
protected double getCustomHeuristicCost(final String functionName, final String[] vertextAxisNames, final OVertex start, final OVertex goal, final OVertex current, final OVertex parent, final long depth, double dFactor, OCommandContext ctx) { double heuristic = 0.0; OFunction func = ctx.getDatabase().getMetadata().getFunctionLibrary().getFunction(functionName); Object fValue = func.executeInContext(context, vertextAxisNames, start, goal, current, parent, depth, dFactor); if (fValue != null && fValue instanceof Number) { heuristic = doubleOrDefault(fValue, heuristic); } return heuristic; }
private void executeInternal(OCommandContext ctx, OResultInternal result) { OSequence.CreateParams params = createParams(ctx, result); OSequence.SEQUENCE_TYPE seqType = type == TYPE_CACHED ? OSequence.SEQUENCE_TYPE.CACHED : OSequence.SEQUENCE_TYPE.ORDERED; result.setProperty("type", seqType.toString()); ctx.getDatabase().getMetadata().getSequenceLibrary().createSequence(this.name.getStringValue(), seqType, params); }
private String getLowerSubclass(ODatabase db, String className1, String className2) { OSchema schema = db.getMetadata().getSchema(); OClass class1 = schema.getClass(className1); OClass class2 = schema.getClass(className2); if (class1.isSubClassOf(class2)) { return class1.getName(); } if (class2.isSubClassOf(class1)) { return class2.getName(); } return null; }
private static void rewriteIndexChainsAsSubqueries(QueryPlanningInfo info, OCommandContext ctx) { if (ctx == null || ctx.getDatabase() == null) { return; } if (info.whereClause != null && info.target != null && info.target.getItem().getIdentifier() != null) { OClass clazz = ctx.getDatabase().getMetadata().getSchema().getClass(info.target.getItem().getIdentifier().getStringValue()); if (clazz != null) { info.whereClause.getBaseExpression().rewriteIndexChainsAsSubqueries(ctx, clazz); } } }