/** * Convenient method to run the function with a single int argument. * @param parameter single int parameter * @return the value of the function */ public int run(int parameter) { return run(new Object[] {parameter}); }
/** * Convenient method to run the function with a single int argument. * @param parameter single int parameter * @return the value of the function as an Object */ @Nullable public Object runGeneric(int parameter) { return findObject(parameter); }
/** * Create a new SqlFunction object with SQL, parameters and a result type. * @param ds the DataSource to obtain connections from * @param sql the SQL to execute * @param types the SQL types of the parameters, as defined in the * {@code java.sql.Types} class * @param resultType the type that the result object is required to match * @see #setResultType(Class) * @see java.sql.Types */ public SqlFunction(DataSource ds, String sql, int[] types, Class<T> resultType) { setRowsExpected(1); setDataSource(ds); setSql(sql); setTypes(types); setResultType(resultType); }
/** * Create a new SqlFunction object with SQL, but without parameters. * Must add parameters or settle with none. * @param ds the DataSource to obtain connections from * @param sql the SQL to execute */ public SqlFunction(DataSource ds, String sql) { setRowsExpected(1); setDataSource(ds); setSql(sql); }
/** * Create a new SqlFunction object with SQL and parameters. * @param ds the DataSource to obtain connections from * @param sql the SQL to execute * @param types the SQL types of the parameters, as defined in the * {@code java.sql.Types} class * @see java.sql.Types */ public SqlFunction(DataSource ds, String sql, int[] types) { setRowsExpected(1); setDataSource(ds); setSql(sql); setTypes(types); }
getNumberOfLogEntries = new SqlFunction<Integer>(dataSource, "SELECT count(*) AS entry_count FROM plugin_log"); getNumberOfLogEntries.compile(); getNumberOfLogEntriesForTenant = new SqlFunction<Integer>(dataSource, "SELECT count(*) AS entry_count FROM plugin_log WHERE tenantId = ?"); getNumberOfLogEntriesForTenant.setResultType(Integer.class); getNumberOfLogEntriesForTenant.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); getNumberOfLogEntriesForTenant.compile(); getComputationDurationForDate = new SqlFunction<Integer>(dataSource, "SELECT sum(timestampdiff(second, startDate, endDate)) AS sum_seconds FROM plugin_log WHERE DATE(endDate) = ?"); getComputationDurationForDate.setResultType(Integer.class); getComputationDurationForDate.declareParameter(new SqlParameter("endDate", Types.DATE)); getComputationDurationForDate.compile();
/** * Constructor to allow use as a JavaBean. * A DataSource, SQL and any parameters must be supplied before * invoking the {@code compile} method and using this object. * @see #setDataSource * @see #setSql * @see #compile */ public SqlFunction() { setRowsExpected(1); }
QUERY_GET_CACHE_SIZE = new SqlFunction(getDataSource(), "SELECT count(*) AS count FROM so_deviation_cache", NO_TYPES);
/** * Create a new SqlFunction object with SQL, but without parameters. * Must add parameters or settle with none. * @param ds the DataSource to obtain connections from * @param sql the SQL to execute */ public SqlFunction(DataSource ds, String sql) { setRowsExpected(1); setDataSource(ds); setSql(sql); }
/** * Constructor to allow use as a JavaBean. * A DataSource, SQL and any parameters must be supplied before * invoking the {@code compile} method and using this object. * @see #setDataSource * @see #setSql * @see #compile */ public SqlFunction() { setRowsExpected(1); }
/** * Create a new SqlFunction object with SQL, but without parameters. * Must add parameters or settle with none. * @param ds DataSource to obtain connections from * @param sql SQL to execute */ public SqlFunction(DataSource ds, String sql) { setRowsExpected(1); setDataSource(ds); setSql(sql); }
/** * Convenient method to run the function without arguments. * @return the value of the function */ public int run() { return run(new Object[0]); }
/** * Analogous to the {@code SqlQuery.findObject(Object[])} method. * This is a generic method to execute a query, taken a number of arguments. * @param parameters array of parameters. These will be objects or * object wrapper types for primitives. * @return the value of the function, as an Object * @see #execute(Object[]) */ @Nullable public Object runGeneric(Object[] parameters) { return findObject(parameters); }
/** * Constructor to allow use as a JavaBean. * A DataSource, SQL and any parameters must be supplied before * invoking the {@code compile} method and using this object. * @see #setDataSource * @see #setSql * @see #compile */ public SqlFunction() { setRowsExpected(1); }
/** * Create a new SqlFunction object with SQL and parameters. * @param ds the DataSource to obtain connections from * @param sql the SQL to execute * @param types the SQL types of the parameters, as defined in the * {@code java.sql.Types} class * @see java.sql.Types */ public SqlFunction(DataSource ds, String sql, int[] types) { setRowsExpected(1); setDataSource(ds); setSql(sql); setTypes(types); }
/** * Convenient method to run the function with a single int argument. * @param parameter single int parameter * @return the value of the function */ public int run(int parameter) { return run(new Object[] {parameter}); }
/** * Convenient method to run the function without arguments, * returning the value as an object. * @return the value of the function */ @Nullable public Object runGeneric() { return findObject((Object[]) null, null); }
/** * Create a new SqlFunction object with SQL and parameters. * @param ds DataSource to obtain connections from * @param sql SQL to execute * @param types SQL types of the parameters, as defined in the * {@code java.sql.Types} class * @see java.sql.Types */ public SqlFunction(DataSource ds, String sql, int[] types) { setRowsExpected(1); setDataSource(ds); setSql(sql); setTypes(types); }
/** * Convenient method to run the function without arguments. * @return the value of the function */ public int run() { return run(new Object[0]); }
/** * Convenient method to run the function without arguments, * returning the value as an object. * @return the value of the function */ public Object runGeneric() { return findObject((Object[]) null); }