Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
*
* * Copyright 2010-2016 OrientDB LTD (http://orientdb.com)
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
* * For more information: http://orientdb.com
*
*/
package com.tinkerpop.blueprints.impls.orient;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.tx.OTransaction;
import com.tinkerpop.blueprints.Contains;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Query;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.DefaultGraphQuery;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
/**
* OrientDB implementation for Graph query.
*
* @author Luca Garulli (l.garulli--(at)--orientdb.com) (http://orientdb.com)
*/
public class OrientGraphQuery extends DefaultGraphQuery {
protected static final char SPACE = ' ';
protected static final String OPERATOR_DIFFERENT = "<>";
protected static final String OPERATOR_NOT = "not ";
protected static final String OPERATOR_IS_NOT = "is not";
protected static final String OPERATOR_LET = "<=";
protected static final char OPERATOR_LT = '<';
protected static final String OPERATOR_GTE = ">=";
protected static final char OPERATOR_GT = '>';
protected static final String OPERATOR_EQUALS = "=";
protected static final String OPERATOR_IS = "is";
protected static final String OPERATOR_IN = " in ";
protected static final String OPERATOR_LIKE = " like ";
protected static final String QUERY_FILTER_AND = " and ";
protected static final String QUERY_FILTER_OR = " or ";
protected static final char QUERY_STRING = '\'';
protected static final char QUERY_SEPARATOR = ',';
protected static final char COLLECTION_BEGIN = '[';
protected static final char COLLECTION_END = ']';
protected static final char PARENTHESIS_BEGIN = '(';
protected static final char PARENTHESIS_END = ')';
protected static final String QUERY_LABEL_BEGIN = " label in [";
protected static final String QUERY_LABEL_END = "]";
protected static final String QUERY_WHERE = " where ";
protected static final String QUERY_SELECT_FROM = "select from ";
protected static final String SKIP = " SKIP ";
protected static final String LIMIT = " LIMIT ";
protected static final String ORDERBY = " ORDER BY ";
public int skip = 0;
public String orderBy = "";
public String orderByDir = "desc";
protected String fetchPlan;
public class OrientGraphQueryIterable extends DefaultGraphQueryIterable {
public OrientGraphQueryIterable(final boolean forVertex, final String[] labels) {
super(forVertex);
if (labels != null && labels.length > 0)
// TREAT CLASS AS LABEL
has("_class", Contains.IN, Arrays.asList(labels));
}
protected Set getIndexedKeys(final Class extends Element> elementClass) {
return ((OrientBaseGraph) graph).getIndexedKeys(elementClass, true);
}
}
protected OrientGraphQuery(final Graph iGraph) {
super(iGraph);
}
/**
* (Blueprints Extension) Sets the labels to filter. Labels are bound to Class names by default.
*
* @param labels String vararg of labels
* @return Current Query Object to allow calls in chain.
*/
public Query labels(final String... labels) {
this.labels = labels;
return this;
}
/**
* Skips first iSkip items from the result set.
*
* @param iSkip Number of items to skip on result set
* @return Current Query Object to allow calls in chain.
*/
public Query skip(final int iSkip) {
this.skip = iSkip;
return this;
}
/**
* (Blueprints Extension) Sets the order of results by a field in ascending (asc) order. This is
* translated on ORDER BY in the underlying SQL query.
*
* @param props Field to order by
* @return Current Query Object to allow calls in chain.
*/
public Query order(final String props) {
this.order(props, orderByDir);
return this;
}
/**
* (Blueprints Extension) Sets the order of results by a field in ascending (asc) or descending
* (desc) order based on dir parameter. This is translated on ORDER BY in the underlying SQL
* query.
*
* @param props Field to order by
* @param dir Direction. Use "asc" for ascending and "desc" for descending
* @return Current Query Object to allow calls in chain.
*/
public Query order(final String props, final String dir) {
this.orderBy = props;
this.orderByDir = dir;
return this;
}
/** Returns the result set of the query as iterable vertices. */
@Override
public Iterable vertices() {
if (limit == 0) return Collections.emptyList();
OTransaction transaction = ((OrientBaseGraph) graph).getRawGraph().getTransaction();
if (hasCustomPredicate()) {
// INSIDE TRANSACTION QUERY DOESN'T SEE IN MEMORY CHANGES, UNTIL
// SUPPORTED USED THE BASIC IMPL
String[] classes = allSubClassesLabels();
return new OrientGraphQueryIterable(true, classes);
}
final StringBuilder text = new StringBuilder(512);
// GO DIRECTLY AGAINST E CLASS AND SUB-CLASSES
text.append(QUERY_SELECT_FROM);
if (((OrientBaseGraph) graph).isUseClassForVertexLabel()
&& labels != null
&& labels.length > 0) {
// FILTER PER CLASS SAVING CHECKING OF LABEL PROPERTY
if (labels.length == 1)
// USE THE CLASS NAME
text.append(OrientBaseGraph.encodeClassName(labels[0]));
else {
// MULTIPLE CLASSES NOT SUPPORTED DIRECTLY: CREATE A SUB-QUERY
String[] classes = allSubClassesLabels();
return new OrientGraphQueryIterable(true, classes);
}
} else text.append(OrientVertexType.CLASS_NAME);
final List