Search in sources :

Example 1 with QuerySqlFunction

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);
            }
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) QuerySqlFunction(org.apache.ignite.cache.query.annotations.QuerySqlFunction) Method(java.lang.reflect.Method)

Example 2 with QuerySqlFunction

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);
            }
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) QuerySqlFunction(org.apache.ignite.cache.query.annotations.QuerySqlFunction) Method(java.lang.reflect.Method) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString)

Example 3 with QuerySqlFunction

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;
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) Callable(java.util.concurrent.Callable) CacheException(javax.cache.CacheException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) QuerySqlFunction(org.apache.ignite.cache.query.annotations.QuerySqlFunction)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 QuerySqlFunction (org.apache.ignite.cache.query.annotations.QuerySqlFunction)3 Method (java.lang.reflect.Method)2 Callable (java.util.concurrent.Callable)1 CacheException (javax.cache.CacheException)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)1