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 2014 Orient Technologies LTD (info(at)orientechnologies.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://www.orientechnologies.com
*
*/
package com.orientechnologies.orient.core.sql;
import static com.orientechnologies.common.util.OClassLoaderHelper.lookupProviderWithOrientClassLoader;
import java.util.*;
import com.orientechnologies.common.collection.OMultiCollectionIterator;
import com.orientechnologies.common.collection.OMultiValue;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.util.OCallable;
import com.orientechnologies.common.util.OCollections;
import com.orientechnologies.orient.core.collate.OCollate;
import com.orientechnologies.orient.core.collate.OCollateFactory;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.serialization.serializer.OStringSerializerHelper;
import com.orientechnologies.orient.core.sql.filter.OSQLFilter;
import com.orientechnologies.orient.core.sql.filter.OSQLTarget;
import com.orientechnologies.orient.core.sql.functions.OSQLFunction;
import com.orientechnologies.orient.core.sql.functions.OSQLFunctionFactory;
import com.orientechnologies.orient.core.sql.method.OSQLMethod;
import com.orientechnologies.orient.core.sql.method.OSQLMethodFactory;
import com.orientechnologies.orient.core.sql.operator.OQueryOperator;
import com.orientechnologies.orient.core.sql.operator.OQueryOperatorFactory;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
public class OSQLEngine {
protected static final OSQLEngine INSTANCE = new OSQLEngine();
private static List FUNCTION_FACTORIES = null;
private static List METHOD_FACTORIES = null;
private static List EXECUTOR_FACTORIES = null;
private static List OPERATOR_FACTORIES = null;
private static List COLLATE_FACTORIES = null;
private static OQueryOperator[] SORTED_OPERATORS = null;
private static ClassLoader orientClassLoader = OSQLEngine.class.getClassLoader();
/**
* internal use only, to sort operators.
*/
private static final class Pair {
final OQueryOperator before;
final OQueryOperator after;
public Pair(final OQueryOperator before, final OQueryOperator after) {
this.before = before;
this.after = after;
}
@Override
public boolean equals(final Object obj) {
if (obj instanceof Pair) {
final Pair that = (Pair) obj;
return before == that.before && after == that.after;
}
return false;
}
@Override
public int hashCode() {
return System.identityHashCode(before) + 31 * System.identityHashCode(after);
}
@Override
public String toString() {
return before + " > " + after;
}
}
protected OSQLEngine() {
}
public static void registerOperator(final OQueryOperator iOperator) {
ODynamicSQLElementFactory.OPERATORS.add(iOperator);
SORTED_OPERATORS = null; // clear cache
}
/**
* @return Iterator of all function factories
*/
public static synchronized Iterator getFunctionFactories() {
if (FUNCTION_FACTORIES == null) {
final Iterator ite = lookupProviderWithOrientClassLoader(OSQLFunctionFactory.class, orientClassLoader);
final List factories = new ArrayList();
while (ite.hasNext()) {
factories.add(ite.next());
}
FUNCTION_FACTORIES = Collections.unmodifiableList(factories);
}
return FUNCTION_FACTORIES.iterator();
}
public static synchronized Iterator getMethodFactories() {
if (METHOD_FACTORIES == null) {
final Iterator ite = lookupProviderWithOrientClassLoader(OSQLMethodFactory.class, orientClassLoader);
final List factories = new ArrayList();
while (ite.hasNext()) {
factories.add(ite.next());
}
METHOD_FACTORIES = Collections.unmodifiableList(factories);
}
return METHOD_FACTORIES.iterator();
}
/**
* @return Iterator of all function factories
*/
public static synchronized Iterator getCollateFactories() {
if (COLLATE_FACTORIES == null) {
final Iterator ite = lookupProviderWithOrientClassLoader(OCollateFactory.class, orientClassLoader);
final List factories = new ArrayList();
while (ite.hasNext()) {
factories.add(ite.next());
}
COLLATE_FACTORIES = Collections.unmodifiableList(factories);
}
return COLLATE_FACTORIES.iterator();
}
/**
* @return Iterator of all operator factories
*/
public static synchronized Iterator getOperatorFactories() {
if (OPERATOR_FACTORIES == null) {
final Iterator ite = lookupProviderWithOrientClassLoader(OQueryOperatorFactory.class,
orientClassLoader);
final List factories = new ArrayList();
while (ite.hasNext()) {
factories.add(ite.next());
}
OPERATOR_FACTORIES = Collections.unmodifiableList(factories);
}
return OPERATOR_FACTORIES.iterator();
}
/**
* @return Iterator of all command factories
*/
public static synchronized Iterator getCommandFactories() {
if (EXECUTOR_FACTORIES == null) {
final Iterator ite = lookupProviderWithOrientClassLoader(OCommandExecutorSQLFactory.class,
orientClassLoader);
final List factories = new ArrayList();
while (ite.hasNext()) {
try {
factories.add(ite.next());
} catch (Exception e) {
OLogManager.instance().warn(null, "Cannot load OCommandExecutorSQLFactory instance from service registry", e);
}
}
EXECUTOR_FACTORIES = Collections.unmodifiableList(factories);
}
return EXECUTOR_FACTORIES.iterator();
}
/**
* Iterates on all factories and append all function names.
*
* @return Set of all function names.
*/
public static Set getFunctionNames() {
final Set types = new HashSet();
final Iterator ite = getFunctionFactories();
while (ite.hasNext()) {
types.addAll(ite.next().getFunctionNames());
}
return types;
}
public static Set getMethodNames() {
final Set types = new HashSet();
final Iterator ite = getMethodFactories();
while (ite.hasNext()) {
types.addAll(ite.next().getMethodNames());
}
return types;
}
/**
* Iterates on all factories and append all collate names.
*
* @return Set of all colate names.
*/
public static Set getCollateNames() {
final Set types = new HashSet();
final Iterator ite = getCollateFactories();
while (ite.hasNext()) {
types.addAll(ite.next().getNames());
}
return types;
}
/**
* Iterates on all factories and append all command names.
*
* @return Set of all command names.
*/
public static Set getCommandNames() {
final Set types = new HashSet();
final Iterator ite = getCommandFactories();
while (ite.hasNext()) {
types.addAll(ite.next().getCommandNames());
}
return types;
}
/**
* Scans for factory plug-ins on the application class path. This method is needed because the application class path can
* theoretically change, or additional plug-ins may become available. Rather than re-scanning the classpath on every invocation of
* the API, the class path is scanned automatically only on the first invocation. Clients can call this method to prompt a
* re-scan. Thus this method need only be invoked by sophisticated applications which dynamically make new plug-ins available at
* runtime.
*/
public static synchronized void scanForPlugins() {
// clear cache, will cause a rescan on next getFunctionFactories call
FUNCTION_FACTORIES = null;
}
public static Object foreachRecord(final OCallable