/** * 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(); }
@Override public Set<String> getFunctionNames() { final ODatabaseDocument db = ODatabaseRecordThreadLocal.instance().get(); return db.getMetadata().getFunctionLibrary().getFunctionNames(); }
@Override public boolean hasFunction(final String iName) { final ODatabaseDocument db = ODatabaseRecordThreadLocal.instance().get(); return db.getMetadata().getFunctionLibrary().getFunction(iName) != null; }
ret = getDatabase().getMetadata().getFunctionLibrary() .getFunction((String)getModelObject().field("name")).execute(values.toArray()); } catch (Exception e) {
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; }
@Override public OSQLFunction createFunction(final String name) throws OCommandExecutionException { final ODatabaseDocument db = ODatabaseRecordThreadLocal.instance().get(); final OFunction f = db.getMetadata().getFunctionLibrary().getFunction(name); return new ODatabaseFunction(f); } }
private OScheduledEvent createRestorePasswordSchedulerEvent(ODatabaseDocument db, OrienteerUser user, String eventName) { OProperty property = user.getDocument().getSchemaClass().getProperty(OrienteerUser.PROP_RESTORE_ID); OFunction fun = db.getMetadata().getFunctionLibrary().getFunction(OrienteerUsersModule.FUN_REMOVE_RESTORE_ID); long timeout = Long.parseLong(OrienteerUsersModule.REMOVE_SCHEDULE_START_TIMEOUT.getValue(property)); return new OScheduledEventBuilder() .setName(eventName) .setFunction(fun) .setArguments(createFunArguments(user, timeout, eventName)) .setRule(OrienteerUsersModule.REMOVE_CRON_RULE.getValue(property)) .setStartTime(new Date(System.currentTimeMillis() + timeout)).build(); }
@Override public OResultSet executeSimple(OCommandContext ctx) { ODatabase database = ctx.getDatabase(); final OFunction f = database.getMetadata().getFunctionLibrary().createFunction(name.getStringValue()); f.setCode(code); f.setIdempotent(Boolean.TRUE.equals(idempotent)); if (parameters != null) f.setParameters(parameters.stream().map(x -> x.getStringValue()).collect(Collectors.toList())); if (language != null) f.setLanguage(language.getStringValue()); f.save(); ORID functionId = f.getId(); OResultInternal result = new OResultInternal(); result.setProperty("operation", "create function"); result.setProperty("functionName", name.getStringValue()); result.setProperty("finalId", functionId); OInternalResultSet rs = new OInternalResultSet(); rs.add(result); return rs; }
/** * 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(); }
/** * Create function which will remove user restoreId by scheduler * @param helper {@link OSchemaHelper} Orienteer helper */ private void createRemoveRestoreIdFunction(OSchemaHelper helper) { OFunctionLibrary lib = helper.getDatabase().getMetadata().getFunctionLibrary(); if (lib.getFunction(FUN_REMOVE_RESTORE_ID) != null) { lib.dropFunction(FUN_REMOVE_RESTORE_ID); } OFunction function = lib.createFunction(FUN_REMOVE_RESTORE_ID); function.setName(FUN_REMOVE_RESTORE_ID); function.setLanguage("javascript"); function.setCode(createCodeForRemoveRestoreIdFunction()); function.setParameters(createParamsForRemoveRestoreIdFunction()); function.save(); }
public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException { database.activateOnCurrentThread(); OInternalResultSet resultSet = new OInternalResultSet(); for (String fName : database.getMetadata().getFunctionLibrary().getFunctionNames()) { final OResultInternal res = new OResultInternal(); res.setProperty("FUNCTION_CAT", (Object) null); res.setProperty("FUNCTION_SCHEM", (Object) null); res.setProperty("FUNCTION_NAME", fName); res.setProperty("REMARKS", ""); res.setProperty("FUNCTION_TYPE", procedureResultUnknown); res.setProperty("SPECIFIC_NAME", fName); resultSet.add(res); } return new OrientJdbcResultSet(new OrientJdbcStatement(connection), resultSet, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); }
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException { database.activateOnCurrentThread(); final OInternalResultSet resultSet = new OInternalResultSet(); OFunctionLibrary functionLibrary = database.getMetadata().getFunctionLibrary(); for (String functionName : functionLibrary.getFunctionNames()) { if (OrientJdbcUtils.like(functionName, procedureNamePattern)) { OResultInternal element = new OResultInternal(); element.setProperty("PROCEDURE_CAT", (Object) null); element.setProperty("PROCEDURE_SCHEM", (Object) null); element.setProperty("PROCEDURE_NAME", functionName); element.setProperty("REMARKS", ""); element.setProperty("PROCEDURE_TYPE", procedureResultUnknown); element.setProperty("SPECIFIC_NAME", functionName); resultSet.add(element); } } return new OrientJdbcResultSet(new OrientJdbcStatement(connection), resultSet, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); }
public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException { database.activateOnCurrentThread(); final OInternalResultSet resultSet = new OInternalResultSet(); final OFunction f = database.getMetadata().getFunctionLibrary().getFunction(functionNamePattern); for (String p : f.getParameters()) { final OResultInternal res = new OResultInternal(); res.setProperty("FUNCTION_CAT", (Object) null); res.setProperty("FUNCTION_SCHEM", (Object) null); res.setProperty("FUNCTION_NAME", f.getName()); res.setProperty("COLUMN_NAME", p); res.setProperty("COLUMN_TYPE", procedureColumnIn); res.setProperty("DATA_TYPE", java.sql.Types.OTHER); res.setProperty("SPECIFIC_NAME", f.getName()); resultSet.add(res); } final OResultInternal res = new OResultInternal(); res.setProperty("FUNCTION_CAT", (Object) null); res.setProperty("FUNCTION_SCHEM", (Object) null); res.setProperty("FUNCTION_NAME", f.getName()); res.setProperty("COLUMN_NAME", "return"); res.setProperty("COLUMN_TYPE", procedureColumnReturn); res.setProperty("DATA_TYPE", java.sql.Types.OTHER); res.setProperty("SPECIFIC_NAME", f.getName()); resultSet.add(res); return new OrientJdbcResultSet(new OrientJdbcStatement(connection), resultSet, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); }
OFunctionLibrary functionLibrary = database.getMetadata().getFunctionLibrary();