use of org.apache.ignite.cache.query.annotations.QuerySqlFunction in project ignite by apache.
the class SchemaManager method createSqlFunctions.
/**
* Registers SQL functions.
*
* @param schema Schema.
* @param clss Classes.
* @throws IgniteCheckedException If failed.
*/
private void createSqlFunctions(String schema, Class<?>[] clss) throws IgniteCheckedException {
if (F.isEmpty(clss))
return;
for (Class<?> cls : clss) {
for (Method m : cls.getDeclaredMethods()) {
QuerySqlFunction ann = m.getAnnotation(QuerySqlFunction.class);
if (ann != null) {
int modifiers = m.getModifiers();
if (!Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers))
throw new IgniteCheckedException("Method " + m.getName() + " must be public static.");
String alias = ann.alias().isEmpty() ? m.getName() : ann.alias();
String clause = "CREATE ALIAS IF NOT EXISTS " + alias + (ann.deterministic() ? " DETERMINISTIC FOR \"" : " FOR \"") + cls.getName() + '.' + m.getName() + '"';
connMgr.executeStatement(schema, clause);
}
}
}
}
use of org.apache.ignite.cache.query.annotations.QuerySqlFunction in project ignite by apache.
the class IgniteH2Indexing method createSqlFunctions.
/**
* Registers SQL functions.
*
* @param schema Schema.
* @param clss Classes.
* @throws IgniteCheckedException If failed.
*/
private void createSqlFunctions(String schema, Class<?>[] clss) throws IgniteCheckedException {
if (F.isEmpty(clss))
return;
for (Class<?> cls : clss) {
for (Method m : cls.getDeclaredMethods()) {
QuerySqlFunction ann = m.getAnnotation(QuerySqlFunction.class);
if (ann != null) {
int modifiers = m.getModifiers();
if (!Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers))
throw new IgniteCheckedException("Method " + m.getName() + " must be public static.");
String alias = ann.alias().isEmpty() ? m.getName() : ann.alias();
String clause = "CREATE ALIAS IF NOT EXISTS " + alias + (ann.deterministic() ? " DETERMINISTIC FOR \"" : " FOR \"") + cls.getName() + '.' + m.getName() + '"';
executeStatement(schema, clause);
}
}
}
}
use of org.apache.ignite.cache.query.annotations.QuerySqlFunction in project ignite by apache.
the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method Modify.
/**
* SQL function that makes a concurrent modification.
*
* @param id Id.
* @param rate Rate.
* @return Result.
*/
@QuerySqlFunction
public static int Modify(final int id, final int rate) {
try {
GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() {
IgniteCache cache = client.cache(CACHE_ORG);
cache.put(id, new Organization("Acme Inc #" + id, rate + 1));
return null;
}
}).get();
} catch (Exception e) {
// No-op
}
return rate - 1;
}
Aggregations