Search in sources :

Example 1 with LoadContext

use of com.beanexplorer.enterprise.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.

the class TestMain method testModule.

public static StatContext testModule(String name, Rdbms dbms, FailData parseFailQueries) throws ProjectLoadException, ReadException {
    LoadContext ctx = new LoadContext();
    Project project = ModuleUtils.loadModule(name, ctx);
    ModuleUtils.addModuleScripts(project);
    ctx.check();
    project.setDatabaseSystem(dbms);
    return testProject(project, parseFailQueries);
}
Also used : Project(com.beanexplorer.enterprise.metadata.model.Project) LoadContext(com.beanexplorer.enterprise.metadata.serialization.LoadContext)

Example 2 with LoadContext

use of com.beanexplorer.enterprise.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.

the class TestMain method testModule5DB.

public static StatContext testModule5DB(String name, List<String> okQueries) throws ProjectLoadException, ReadException {
    LoadContext ctx = new LoadContext();
    Project project = ModuleUtils.loadModule(name, ctx);
    ModuleUtils.addModuleScripts(project);
    ctx.check();
    SqlParser parser = new SqlParser();
    Formatter formatter = new Formatter();
    DefaultParserContext parserContext = new DefaultParserContext();
    parser.setContext(parserContext);
    Rdbms[] dbms = { Rdbms.MYSQL, Rdbms.DB2, Rdbms.ORACLE, Rdbms.SQLSERVER, Rdbms.POSTGRESQL };
    StatContext stat = new StatContext(name + "/5DB", StreamEx.of(dbms).map(Rdbms::name).prepend("Count", "PF").append("Success").toArray(String[]::new));
    for (String entityName : project.getEntityNames()) {
        Entity entity = project.getEntity(entityName);
        for (Query query : entity.getQueries()) {
            if (!allowedTypes.contains(query.getType()))
                continue;
            if (query.getName().equals("Table definition"))
                continue;
            if (query.getQuery().trim().isEmpty())
                continue;
            project.setDatabaseSystem(Rdbms.BESQL);
            String queryText;
            try {
                queryText = query.getQueryCompiled().validate();
            } catch (ProjectElementException e) {
                continue;
            }
            stat.inc("Count");
            parser.parse(queryText);
            if (!parser.getMessages().isEmpty()) {
                stat.inc("PF");
                continue;
            }
            try {
                formatter.format(parser.getStartNode(), new Context(Dbms.POSTGRESQL), parserContext);
            } catch (IllegalArgumentException e) {
                System.out.println(entityName + "." + query.getName() + ": " + e.getMessage());
                stat.inc("PF");
                continue;
            }
            boolean success = true;
            for (Rdbms db : dbms) {
                project.setDatabaseSystem(db);
                String expected;
                try {
                    expected = sanitizeValue(query.getQueryCompiled().validate());
                } catch (ProjectElementException e) {
                    continue;
                }
                String formatted;
                try {
                    formatted = formatter.format(parser.getStartNode(), new Context(Dbms.valueOf(db.name())), parserContext);
                } catch (IllegalArgumentException e) {
                    System.out.println(entityName + "." + query.getName() + ": " + e.getMessage());
                    stat.inc(db.name());
                    success = false;
                    continue;
                }
                String actual = sanitizeValue(formatted);
                if (!expected.equals(actual)) {
                    if (db == Rdbms.ORACLE) {
                        System.out.println(entityName + "." + query.getName());
                        System.out.println("BESQL: " + queryText);
                        System.out.println("Actual: " + actual);
                        System.out.println("Expected: " + expected);
                    }
                    stat.inc(db.name());
                    success = false;
                }
            }
            if (success) {
                stat.inc("Success");
            // okQueries.add( entityName+"."+query.getName() );
            }
        }
    }
    return stat;
}
Also used : DefaultParserContext(com.developmentontheedge.sql.model.DefaultParserContext) Context(com.developmentontheedge.sql.format.Context) LoadContext(com.beanexplorer.enterprise.metadata.serialization.LoadContext) Entity(com.beanexplorer.enterprise.metadata.model.Entity) ProjectElementException(com.beanexplorer.enterprise.metadata.exception.ProjectElementException) Rdbms(com.beanexplorer.enterprise.metadata.sql.Rdbms) Query(com.beanexplorer.enterprise.metadata.model.Query) Formatter(com.developmentontheedge.sql.format.Formatter) SqlParser(com.developmentontheedge.sql.model.SqlParser) Project(com.beanexplorer.enterprise.metadata.model.Project) DefaultParserContext(com.developmentontheedge.sql.model.DefaultParserContext) LoadContext(com.beanexplorer.enterprise.metadata.serialization.LoadContext)

Aggregations

Project (com.beanexplorer.enterprise.metadata.model.Project)2 LoadContext (com.beanexplorer.enterprise.metadata.serialization.LoadContext)2 ProjectElementException (com.beanexplorer.enterprise.metadata.exception.ProjectElementException)1 Entity (com.beanexplorer.enterprise.metadata.model.Entity)1 Query (com.beanexplorer.enterprise.metadata.model.Query)1 Rdbms (com.beanexplorer.enterprise.metadata.sql.Rdbms)1 Context (com.developmentontheedge.sql.format.Context)1 Formatter (com.developmentontheedge.sql.format.Formatter)1 DefaultParserContext (com.developmentontheedge.sql.model.DefaultParserContext)1 SqlParser (com.developmentontheedge.sql.model.SqlParser)1