use of com.orientechnologies.orient.core.metadata.function.OFunction in project orientdb by orientechnologies.
the class OSQLFunctionHeuristicPathFinderAbstract method getCustomHeuristicCost.
protected double getCustomHeuristicCost(final String functionName, final String[] vertextAxisNames, final OrientVertex start, final OrientVertex goal, final OrientVertex current, final OrientVertex parent, final long depth, double dFactor) {
double heuristic = 0.0;
OrientGraph ff;
OFunction func = OrientGraph.getActiveGraph().getRawGraph().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;
}
use of com.orientechnologies.orient.core.metadata.function.OFunction in project orientdb by orientechnologies.
the class OScriptManager method getLibrary.
/**
* Formats the library of functions for a language.
*
* @param db
* Current database instance
* @param iLanguage
* Language as filter
* @return String containing all the functions
*/
public String getLibrary(final ODatabase<?> db, final String iLanguage) {
if (db == null)
// NO DB = NO LIBRARY
return null;
final StringBuilder code = new StringBuilder();
final Set<String> functions = db.getMetadata().getFunctionLibrary().getFunctionNames();
for (String fName : functions) {
final OFunction f = db.getMetadata().getFunctionLibrary().getFunction(fName);
if (f.getLanguage() == null)
throw new OConfigurationException("Database function '" + fName + "' has no language");
if (f.getLanguage().equalsIgnoreCase(iLanguage)) {
final String def = getFunctionDefinition(f);
if (def != null) {
code.append(def);
code.append("\n");
}
}
}
return code.length() == 0 ? null : code.toString();
}
use of com.orientechnologies.orient.core.metadata.function.OFunction in project orientdb by orientechnologies.
the class OClassTrigger method checkClzAttribute.
private Object checkClzAttribute(final ODocument iDocument, String attr) {
final OImmutableClass clz = ODocumentInternal.getImmutableSchemaClass(iDocument);
if (clz != null && clz.isTriggered()) {
OFunction func = null;
String fieldName = clz.getCustom(attr);
OClass superClz = clz.getSuperClass();
while (fieldName == null || fieldName.length() == 0) {
if (superClz == null || superClz.getName().equals(CLASSNAME))
break;
fieldName = superClz.getCustom(attr);
superClz = superClz.getSuperClass();
}
if (fieldName != null && fieldName.length() > 0) {
// check if it is reflection or not
final Object[] clzMethod = this.checkMethod(fieldName);
if (clzMethod != null)
return clzMethod;
func = database.getMetadata().getFunctionLibrary().getFunction(fieldName);
if (func == null) {
// check if it is rid
if (OStringSerializerHelper.contains(fieldName, ORID.SEPARATOR)) {
try {
ODocument funcDoc = database.load(new ORecordId(fieldName));
if (funcDoc != null) {
func = database.getMetadata().getFunctionLibrary().getFunction((String) funcDoc.field("name"));
}
} catch (Exception ex) {
OLogManager.instance().error(this, "illegal record id : ", ex.getMessage());
}
}
}
} else {
final Object funcProp = iDocument.field(attr);
if (funcProp != null) {
final String funcName = funcProp instanceof ODocument ? (String) ((ODocument) funcProp).field("name") : funcProp.toString();
func = database.getMetadata().getFunctionLibrary().getFunction(funcName);
}
}
return func;
}
return null;
}
use of com.orientechnologies.orient.core.metadata.function.OFunction in project orientdb by orientechnologies.
the class OScheduledEvent method getFunctionSafe.
private OFunction getFunctionSafe() {
if (function == null) {
final Object funcDoc = document.field(PROP_FUNC);
if (funcDoc != null) {
if (funcDoc instanceof OFunction) {
function = (OFunction) funcDoc;
// OVERWRITE FUNCTION ID
document.field(PROP_FUNC, function.getId());
} else if (funcDoc instanceof ODocument)
function = new OFunction((ODocument) funcDoc);
else if (funcDoc instanceof ORecordId)
function = new OFunction((ORecordId) funcDoc);
}
}
return function;
}
use of com.orientechnologies.orient.core.metadata.function.OFunction in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateFunction method execute.
/**
* Execute the command and return the ODocument object created.
*/
public Object execute(final Map<Object, Object> iArgs) {
if (name == null)
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
if (name.isEmpty())
throw new OCommandExecutionException("Syntax Error. You must specify a function name: " + getSyntax());
if (code == null || code.isEmpty())
throw new OCommandExecutionException("Syntax Error. You must specify the function code: " + getSyntax());
ODatabaseDocument database = getDatabase();
final OFunction f = database.getMetadata().getFunctionLibrary().createFunction(name);
f.setCode(code);
f.setIdempotent(idempotent);
if (parameters != null)
f.setParameters(parameters);
if (language != null)
f.setLanguage(language);
f.save();
return f.getId();
}
Aggregations