Package org.hsqldb_voltpatches

Examples of org.hsqldb_voltpatches.VoltXMLElement


            assert(e.attributes.get("name") != null);
            removedColumns.add(e.attributes.get("name"));
        }
        // go back and get our table name.  Use the uniquename ("table" + name) to get the element
        // from the schema
        VoltXMLElement tableElement = m_schema.findChild(tableEntry.getKey());
        assert(tableElement != null);
        String partitionCol = tableElement.attributes.get("partitioncolumn");
        // if we removed the partition column, then remove the attribute from the schema
        if (partitionCol != null && removedColumns.contains(partitionCol)) {
            m_compiler.addWarn(String.format("Partition column %s was dropped from table %s.  Attempting to change table to replicated.", partitionCol, tableElement.attributes.get("name")));
View Full Code Here


                            statement.substring(0,statement.length()-1))); // remove trailing semicolon
                }
                // group(1) -> table, group(2) -> column
                String tableName = checkIdentifierStart(statementMatcher.group(1), statement);
                String columnName = checkIdentifierStart(statementMatcher.group(2), statement);
                VoltXMLElement tableXML = m_schema.findChild("table", tableName.toUpperCase());
                if (tableXML != null) {
                    tableXML.attributes.put("partitioncolumn", columnName.toUpperCase());
                    // Column validity check done by VoltCompiler in post-processing
                }
                else {
                    throw m_compiler.new VoltCompilerException(String.format(
                                "Invalid PARTITION statement: table %s does not exist", tableName));
                }
                return true;
            }
            else if (PROCEDURE.equals(partitionee)) {
                if (whichProcs != DdlProceduresToLoad.ALL_DDL_PROCEDURES) {
                    return true;
                }
                // matches if it is
                //   PARTITION PROCEDURE <procedure>
                //      ON  TABLE <table> COLUMN <column> [PARAMETER <parameter-index-no>]
                statementMatcher = partitionProcedurePattern.matcher(statement);

                if ( ! statementMatcher.matches()) {
                    throw m_compiler.new VoltCompilerException(String.format(
                            "Invalid PARTITION statement: \"%s\", " +
                            "expected syntax: PARTITION PROCEDURE <procedure> ON "+
                            "TABLE <table> COLUMN <column> [PARAMETER <parameter-index-no>]",
                            statement.substring(0,statement.length()-1))); // remove trailing semicolon
                }

                // check the table portion of the partition info
                String tableName = checkIdentifierStart(statementMatcher.group(2), statement);

                // check the column portion of the partition info
                String columnName = checkIdentifierStart(statementMatcher.group(3), statement);

                // if not specified default parameter index to 0
                String parameterNo = statementMatcher.group(4);
                if (parameterNo == null) {
                    parameterNo = "0";
                }

                String partitionInfo = String.format("%s.%s: %s", tableName, columnName, parameterNo);

                // procedureName -> group(1), partitionInfo -> group(2)
                m_tracker.addProcedurePartitionInfoTo(
                        checkIdentifierStart(statementMatcher.group(1), statement),
                        partitionInfo
                        );

                return true;
            }
            // can't get here as regex only matches for PROCEDURE or TABLE
        }

        // matches if it is REPLICATE TABLE <table-name>
        statementMatcher = replicatePattern.matcher(statement);
        if (statementMatcher.matches()) {
            // group(1) -> table
            String tableName = checkIdentifierStart(statementMatcher.group(1), statement);
            VoltXMLElement tableXML = m_schema.findChild("table", tableName.toUpperCase());
            if (tableXML != null) {
                tableXML.attributes.remove("partitioncolumn");
            }
            else {
                throw m_compiler.new VoltCompilerException(String.format(
                            "Invalid REPLICATE statement: table %s does not exist", tableName));
            }
            return true;
        }

        // match IMPORT CLASS statements
        statementMatcher = importClassPattern.matcher(statement);
        if (statementMatcher.matches()) {
            if (whichProcs == DdlProceduresToLoad.ALL_DDL_PROCEDURES) {
                // Semi-hacky way of determining if we're doing a cluster-internal compilation.
                // 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, 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'",
                                    classNameStr)); // remove trailing semicolon
                    }
                    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: " +
                            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(statement);
            }

            return true;
        }

        // matches if it is CREATE ROLE [WITH <permission> [, <permission> ...]]
        // group 1 is role name
        // group 2 is comma-separated permission list or null if there is no WITH clause
        statementMatcher = createRolePattern.matcher(statement);
        if (statementMatcher.matches()) {
            String roleName = statementMatcher.group(1).toLowerCase();
            CatalogMap<Group> groupMap = db.getGroups();
            if (groupMap.get(roleName) != null) {
                throw m_compiler.new VoltCompilerException(String.format(
                        "Role name \"%s\" in CREATE ROLE statement already exists.",
                        roleName));
            }
            org.voltdb.catalog.Group catGroup = groupMap.add(roleName);
            if (statementMatcher.group(2) != null) {
                try {
                    EnumSet<Permission> permset =
                            Permission.getPermissionsFromAliases(Arrays.asList(StringUtils.split(statementMatcher.group(2), ',')));
                    Permission.setPermissionsInGroup(catGroup, permset);
                } catch (IllegalArgumentException iaex) {
                    throw m_compiler.new VoltCompilerException(String.format(
                            "Invalid permission \"%s\" in CREATE ROLE statement: \"%s\", " +
                                    "available permissions: %s", iaex.getMessage(),
                            statement.substring(0,statement.length()-1), // remove trailing semicolon
                            Permission.toListString()));
                }
            }
            return true;
        }

        statementMatcher = exportPattern.matcher(statement);
        if (statementMatcher.matches()) {

            // check the table portion
            String tableName = checkIdentifierStart(statementMatcher.group(1), statement);
            VoltXMLElement tableXML = m_schema.findChild("table", tableName.toUpperCase());
            if (tableXML != null) {
                tableXML.attributes.put("export", "true");
            }
            else {
                throw m_compiler.new VoltCompilerException(String.format(
View Full Code Here

        for (Entry<Table, String> entry : matViewMap.entrySet()) {
            Table destTable = entry.getKey();
            String query = entry.getValue();

            // get the xml for the query
            VoltXMLElement xmlquery = null;
            try {
                xmlquery = m_hsql.getXMLCompiledStatement(query);
            }
            catch (HSQLParseException e) {
                e.printStackTrace();
View Full Code Here

public class TestVoltXMLElement extends TestCase {

    VoltXMLElement makeNamedElement(String elementName, String attName)
    {
        VoltXMLElement e = new VoltXMLElement(elementName);
        e.attributes.put("name", attName);
        return e;
    }
View Full Code Here

        }
        return null;
    }

    public void testDiff() {
        VoltXMLElement first = makeNamedElement("element", "element");
        VoltXMLElement changedChild1 = makeNamedElement("child", "changedchild1");
        first.children.add(changedChild1);
        changedChild1.attributes.put("deleteme", "noreally");
        VoltXMLElement changedChild2 = makeNamedElement("child", "changedchild2");
        first.children.add(changedChild2);
        VoltXMLElement changedGrandchild = makeNamedElement("child", "changedgrandchild");
        changedChild2.children.add(changedGrandchild);
        changedGrandchild.children.add(makeNamedElement("child", "doomeddescendent"));
        first.attributes.put("deleted", "doesntmatter");
        first.attributes.put("remains", "doesntmatter");
        first.attributes.put("changes", "oldvalue");
        first.children.add(makeNamedElement("child", "deletedchild"));
        first.children.add(makeNamedElement("child", "unchangedchild"));

        VoltXMLElement second = first.duplicate();
        second.attributes.remove("deleted");
        second.attributes.put("added", "addedval");
        second.attributes.put("changes", "newvalue");
        second.children.add(makeNamedElement("child", "addedchild"));
        second.children.remove(second.findChild("child", "deletedchild"));
        second.findChild("child", "changedchild1").attributes.remove("deleteme");
        VoltXMLElement temp = second.findChild("child", "changedchild2").findChild("child", "changedgrandchild");
        temp.children.remove(temp.findChild("child", "doomeddescendent"));


        VoltXMLDiff diff = VoltXMLElement.computeDiff(first, second);

        Map<String, String> addedAtt = diff.getAddedAttributes();
        assertEquals(1, addedAtt.size());
        assertTrue(addedAtt.keySet().contains("added"));
        assertEquals("addedval", addedAtt.get("added"));

        Map<String, String> changedAtt = diff.getChangedAttributes();
        assertEquals(1, changedAtt.size());
        assertTrue(changedAtt.keySet().contains("changes"));
        assertEquals("newvalue", changedAtt.get("changes"));

        Set<String> removedAtt = diff.getRemovedAttributes();
        assertEquals(1, removedAtt.size());
        assertTrue(removedAtt.contains("deleted"));

        List<VoltXMLElement> added = diff.getAddedNodes();
        assertEquals(1, added.size());
        assertTrue(findNamedNode(added, "addedchild") != null);

        List<VoltXMLElement> removed = diff.getRemovedNodes();
        assertEquals(1, removed.size());
        assertTrue(findNamedNode(removed, "deletedchild") != null);

        Map<String, VoltXMLDiff> changed = diff.getChangedNodes();
        assertEquals(2, changed.size());
        assertTrue(changed.containsKey("childchangedchild1"));
        VoltXMLDiff child1 = changed.get("childchangedchild1");
        assertTrue(child1.getRemovedAttributes().contains("deleteme"));
        assertTrue(changed.containsKey("childchangedchild2"));
        VoltXMLDiff child2 = changed.get("childchangedchild2");
        assertTrue(child2.getChangedNodes().containsKey("childchangedgrandchild"));
        VoltXMLDiff grandchild = child2.getChangedNodes().get("childchangedgrandchild");
        assertTrue(findNamedNode(grandchild.getRemovedNodes(), "doomeddescendent") != null);

        VoltXMLElement third = first.duplicate();
        third.applyDiff(diff);
        System.out.println(first.toMinString());
        System.out.println(second.toMinString());
        System.out.println(third.toMinString());
        assertEquals(second.toMinString(), third.toMinString());
    }
View Full Code Here

        assertEquals(second.toMinString(), third.toMinString());
    }

    public void testDupeChild()
    {
        VoltXMLElement first = makeNamedElement("element", "element");
        VoltXMLElement child1 = new VoltXMLElement("child");
        child1.attributes.put("value", "3");
        first.children.add(child1);
        // Same element name, no attribute "name"
        VoltXMLElement child2 = new VoltXMLElement("child");
        child2.attributes.put("value", "4");
        first.children.add(child2);

        VoltXMLElement second = makeNamedElement("element", "element");
        VoltXMLElement child1s = new VoltXMLElement("child");
        child1s.attributes.put("value", "5");
        second.children.add(child1s);
        // Same element name, no attribute "name"
        VoltXMLElement child2s = new VoltXMLElement("child");
        child2s.attributes.put("value", "6");
        second.children.add(child2s);

        VoltXMLDiff diff = VoltXMLElement.computeDiff(first, second);
        System.out.println("diff: " + diff.toString());

        VoltXMLElement third = first.duplicate();
        third.applyDiff(diff);
        System.out.println(first.toMinString());
        System.out.println(second.toMinString());
        System.out.println(third.toMinString());
        assertEquals(second.toMinString(), third.toMinString());
    }
View Full Code Here

        assertEquals(second.toMinString(), third.toMinString());
    }

    public void testOrderFail()
    {
        VoltXMLElement first = makeNamedElement("element", "element");
        first.children.add(makeNamedElement("first", "first"));
        first.children.add(makeNamedElement("third", "third"));
        first.children.add(makeNamedElement("fourth", "fourth"));

        VoltXMLElement second = makeNamedElement("element", "element");
        second.children.add(makeNamedElement("first", "first"));
        second.children.add(makeNamedElement("second", "second"));
        second.children.add(makeNamedElement("third", "third"));
        second.children.add(makeNamedElement("fourth", "fourth"));

        VoltXMLDiff diff = VoltXMLElement.computeDiff(first, second);
        System.out.println("diff: " + diff.toString());

        VoltXMLElement third = first.duplicate();
        third.applyDiff(diff);
        System.out.println(first.toMinString());
        System.out.println(second.toMinString());
        System.out.println(third.toMinString());
        assertEquals(second.toMinString(), third.toMinString());
    }
View Full Code Here

        assertEquals(second.toMinString(), third.toMinString());
    }

    public void testNoDiff()
    {
        VoltXMLElement first = makeNamedElement("element", "element");
        VoltXMLElement changedChild1 = makeNamedElement("child", "changedchild1");
        first.children.add(changedChild1);
        changedChild1.attributes.put("deleteme", "noreally");
        VoltXMLElement changedChild2 = makeNamedElement("child", "changedchild2");
        first.children.add(changedChild2);
        VoltXMLElement changedGrandchild = makeNamedElement("child", "changedgrandchild");
        changedChild2.children.add(changedGrandchild);
        changedGrandchild.children.add(makeNamedElement("child", "doomeddescendent"));
        first.attributes.put("deleted", "doesntmatter");
        first.attributes.put("remains", "doesntmatter");
        first.attributes.put("changes", "oldvalue");
        first.children.add(makeNamedElement("child", "deletedchild"));
        first.children.add(makeNamedElement("child", "unchangedchild"));

        VoltXMLElement second = first.duplicate();

        VoltXMLDiff diff = VoltXMLElement.computeDiff(first, second);
        System.out.println("diff: " + diff.toString());

        VoltXMLElement third = first.duplicate();
        third.applyDiff(diff);
        System.out.println(first.toMinString());
        System.out.println(second.toMinString());
        System.out.println(third.toMinString());
        assertEquals(second.toMinString(), third.toMinString());
    }
View Full Code Here

        HSQLInterface hsql = HSQLInterface.loadHsqldb();

        hsql.runDDLCommand(ddl1);

        VoltXMLElement xml = hsql.getXMLFromCatalog();
        System.out.println(xml);
        assertTrue(xml != null);

    }
View Full Code Here

        br.close();
        HSQLInterface hsql = HSQLInterface.loadHsqldb();

        hsql.runDDLCommand(ddl1);

        VoltXMLElement xml = hsql.getXMLFromCatalog();
        System.out.println(xml);
        assertTrue(xml != null);

    }
View Full Code Here

TOP

Related Classes of org.hsqldb_voltpatches.VoltXMLElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.