Search in sources :

Example 1 with SourceCompiler

use of org.h2.util.SourceCompiler in project h2database by h2database.

the class FunctionAlias method loadFromSource.

private void loadFromSource() {
    SourceCompiler compiler = database.getCompiler();
    synchronized (compiler) {
        String fullClassName = Constants.USER_PACKAGE + "." + getName();
        compiler.setSource(fullClassName, source);
        try {
            Method m = compiler.getMethod(fullClassName);
            JavaMethod method = new JavaMethod(m, 0);
            javaMethods = new JavaMethod[] { method };
        } catch (DbException e) {
            throw e;
        } catch (Exception e) {
            throw DbException.get(ErrorCode.SYNTAX_ERROR_1, e, source);
        }
    }
}
Also used : Method(java.lang.reflect.Method) DbException(org.h2.message.DbException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SourceCompiler(org.h2.util.SourceCompiler) DbException(org.h2.message.DbException)

Example 2 with SourceCompiler

use of org.h2.util.SourceCompiler in project h2database by h2database.

the class TriggerObject method loadFromSource.

private Trigger loadFromSource() {
    SourceCompiler compiler = database.getCompiler();
    synchronized (compiler) {
        String fullClassName = Constants.USER_PACKAGE + ".trigger." + getName();
        compiler.setSource(fullClassName, triggerSource);
        try {
            if (SourceCompiler.isJavaxScriptSource(triggerSource)) {
                return (Trigger) compiler.getCompiledScript(fullClassName).eval();
            } else {
                final Method m = compiler.getMethod(fullClassName);
                if (m.getParameterTypes().length > 0) {
                    throw new IllegalStateException("No parameters are allowed for a trigger");
                }
                return (Trigger) m.invoke(null);
            }
        } catch (DbException e) {
            throw e;
        } catch (Exception e) {
            throw DbException.get(ErrorCode.SYNTAX_ERROR_1, e, triggerSource);
        }
    }
}
Also used : Trigger(org.h2.api.Trigger) Method(java.lang.reflect.Method) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException) SourceCompiler(org.h2.util.SourceCompiler) DbException(org.h2.message.DbException)

Aggregations

Method (java.lang.reflect.Method)2 DbException (org.h2.message.DbException)2 SourceCompiler (org.h2.util.SourceCompiler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SQLException (java.sql.SQLException)1 Trigger (org.h2.api.Trigger)1