Search in sources :

Example 1 with ClassNameMatchStatus

use of org.voltdb.compiler.ClassMatcher.ClassNameMatchStatus in project voltdb by VoltDB.

the class ImportClass method processStatement.

@Override
protected boolean processStatement(DDLStatement ddlStatement, Database db, DdlProceduresToLoad whichProcs) throws VoltCompilerException {
    // match IMPORT CLASS statements
    Matcher statementMatcher = SQLParser.matchImportClass(ddlStatement.statement);
    if (!statementMatcher.matches()) {
        return false;
    }
    if (whichProcs == DdlProceduresToLoad.ALL_DDL_PROCEDURES) {
        // Command-line compilation will never have an InMemoryJarfile.
        if (!(m_classLoader instanceof InMemoryJarfile.JarLoader)) {
            // Only process the statement if this is not for the StatementPlanner
            String classNameStr = statementMatcher.group(1);
            // check that the match pattern is a valid match pattern
            checkIdentifierWithWildcard(classNameStr, ddlStatement.statement);
            ClassNameMatchStatus matchStatus = m_classMatcher.addPattern(classNameStr);
            if (matchStatus == ClassNameMatchStatus.NO_EXACT_MATCH) {
                throw m_compiler.new VoltCompilerException(String.format("IMPORT CLASS not found: '%s'", // remove trailing semicolon
                classNameStr));
            } else if (matchStatus == ClassNameMatchStatus.NO_WILDCARD_MATCH) {
                m_compiler.addWarn(String.format("IMPORT CLASS no match for wildcarded class: '%s'", classNameStr), ddlStatement.lineNo);
            }
        } else {
            m_compiler.addInfo("Internal cluster recompilation ignoring IMPORT CLASS line: " + ddlStatement.statement);
        }
        // Need to track the IMPORT CLASS lines even on internal compiles so that
        // we don't lose them from the DDL source.  When the @UAC path goes away,
        // we could change this.
        m_tracker.addImportLine(ddlStatement.statement);
    }
    return true;
}
Also used : Matcher(java.util.regex.Matcher) VoltCompilerException(org.voltdb.compiler.VoltCompiler.VoltCompilerException) ClassNameMatchStatus(org.voltdb.compiler.ClassMatcher.ClassNameMatchStatus)

Example 2 with ClassNameMatchStatus

use of org.voltdb.compiler.ClassMatcher.ClassNameMatchStatus in project voltdb by VoltDB.

the class UpdateApplicationBase method modifyCatalogClasses.

/**
     * @return NUll if no classes changed, otherwise return the update jar file.
     * @throws ClassNotFoundException
     * @throws IOException
     */
private static InMemoryJarfile modifyCatalogClasses(Catalog catalog, InMemoryJarfile jarfile, String deletePatterns, InMemoryJarfile newJarfile, boolean isXDCR) throws ClassNotFoundException, IOException {
    // modify the old jar in place based on the @UpdateClasses inputs, and then
    // recompile it if necessary
    boolean deletedClasses = false;
    if (deletePatterns != null) {
        String[] patterns = deletePatterns.split(",");
        ClassMatcher matcher = new ClassMatcher();
        // Need to concatenate all the classnames together for ClassMatcher
        String currentClasses = "";
        for (String classname : jarfile.getLoader().getClassNames()) {
            currentClasses = currentClasses.concat(classname + "\n");
        }
        matcher.m_classList = currentClasses;
        for (String pattern : patterns) {
            ClassNameMatchStatus status = matcher.addPattern(pattern.trim());
            if (status == ClassNameMatchStatus.MATCH_FOUND) {
                deletedClasses = true;
            }
        }
        for (String classname : matcher.getMatchedClassList()) {
            jarfile.removeClassFromJar(classname);
        }
    }
    boolean foundClasses = false;
    if (newJarfile != null) {
        for (Entry<String, byte[]> e : newJarfile.entrySet()) {
            String filename = e.getKey();
            if (!filename.endsWith(".class")) {
                continue;
            }
            foundClasses = true;
            jarfile.put(e.getKey(), e.getValue());
        }
    }
    if (!deletedClasses && !foundClasses) {
        return null;
    }
    compilerLog.info("Updating java classes available to stored procedures");
    VoltCompiler compiler = new VoltCompiler(isXDCR);
    compiler.compileInMemoryJarfile(jarfile);
    return jarfile;
}
Also used : ClassMatcher(org.voltdb.compiler.ClassMatcher) VoltCompiler(org.voltdb.compiler.VoltCompiler) ClassNameMatchStatus(org.voltdb.compiler.ClassMatcher.ClassNameMatchStatus)

Aggregations

ClassNameMatchStatus (org.voltdb.compiler.ClassMatcher.ClassNameMatchStatus)2 Matcher (java.util.regex.Matcher)1 ClassMatcher (org.voltdb.compiler.ClassMatcher)1 VoltCompiler (org.voltdb.compiler.VoltCompiler)1 VoltCompilerException (org.voltdb.compiler.VoltCompiler.VoltCompilerException)1