Search in sources :

Example 1 with NullLogger

use of com.developmentontheedge.be5.metadata.util.NullLogger in project be5 by DevelopmentOnTheEdge.

the class ModuleUtilsTest method testMergeAllModulesWithLoadRead.

@Test
public void testMergeAllModulesWithLoadRead() throws Exception {
    Path tpmProjectPath = tmp.newFolder().toPath();
    Path tpmModulePath = tmp.newFolder().toPath();
    Project module = getModule();
    Serialization.save(module, tpmModulePath);
    Project app = getProject();
    Serialization.save(app, tpmProjectPath);
    ArrayList<URL> urls = new ArrayList<>();
    urls.add(tpmModulePath.resolve("project.yaml").toUri().toURL());
    urls.add(tpmProjectPath.resolve("project.yaml").toUri().toURL());
    ModuleLoader2.loadAllProjects(urls);
    assertNotNull(ModuleLoader2.getModulePath("app").resolve("project.yaml"));
    app = ModuleLoader2.getModulesMap().get("app");
    ModuleLoader2.mergeModules(app, new NullLogger());
    assertEquals(Collections.singleton("mentity"), app.getEntityNames());
    assertEquals(EntityType.DICTIONARY, app.getEntity("mentity").getType());
    BeModelCollection<Query> queries = app.getEntity("mentity").getQueries();
    assertEquals("QUERY1 customized", queries.get("q1").getQuery());
    assertEquals("Query1 title", queries.get("q1").getTitleName());
    assertEquals("QUERY2", queries.get("q2").getQuery());
    assertEquals("Query2 title", queries.get("q2").getTitleName());
    assertEquals("QUERY3", queries.get("q3").getQuery());
    assertEquals("Query3 title", queries.get("q3").getTitleName());
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Query(com.developmentontheedge.be5.metadata.model.Query) ArrayList(java.util.ArrayList) URL(java.net.URL) Test(org.junit.Test)

Example 2 with NullLogger

use of com.developmentontheedge.be5.metadata.util.NullLogger in project be5 by DevelopmentOnTheEdge.

the class AppSync method readSchema.

private void readSchema() throws ExtendedSqlException, SQLException, ProcessInterruptedException {
    getLog().info("Read database scheme ...");
    long time = System.currentTimeMillis();
    ProcessController controller = new NullLogger();
    Rdbms rdbms = DatabaseUtils.getRdbms(connector);
    DbmsSchemaReader schemaReader = rdbms.getSchemaReader();
    defSchema = schemaReader.getDefaultSchema(sqlExecutor);
    tableTypes = schemaReader.readTableNames(sqlExecutor, defSchema, controller);
    columns = schemaReader.readColumns(sqlExecutor, defSchema, controller);
    indices = schemaReader.readIndices(sqlExecutor, defSchema, controller);
    if (debug) {
        if (!warnings.isEmpty()) {
            System.err.println(warnings.size() + " warning(s) during loading the project from " + sqlExecutor.getConnector().getConnectString());
            Collections.sort(warnings);
            for (String warning : warnings) {
                System.err.println(warning);
            }
        }
    }
    getLog().info("comleted, " + (System.currentTimeMillis() - time) + "ms.");
}
Also used : NullLogger(com.developmentontheedge.be5.metadata.util.NullLogger) Rdbms(com.developmentontheedge.be5.metadata.sql.Rdbms) ProcessController(com.developmentontheedge.be5.metadata.util.ProcessController) DbmsSchemaReader(com.developmentontheedge.be5.metadata.sql.schema.DbmsSchemaReader)

Example 3 with NullLogger

use of com.developmentontheedge.be5.metadata.util.NullLogger in project be5 by DevelopmentOnTheEdge.

the class AppTools method execute.

@Override
public void execute() throws MojoFailureException {
    init();
    BeConnectionProfile prof = be5Project.getConnectionProfile();
    if (prof == null) {
        throw new MojoFailureException("Connection profile is required for SQL console");
    }
    try {
        getLog().info("Welcome to FTL/SQL console!");
        BeSqlExecutor sql = new BeSqlExecutor(connector) {

            @Override
            public void executeSingle(String statement) throws ExtendedSqlException {
                ResultSet rs = null;
                try {
                    rs = connector.executeQuery(statement);
                    format(rs, System.err, 20);
                } catch (SQLException e) {
                    throw new ExtendedSqlException(connector, statement, e);
                } finally {
                    connector.close(rs);
                }
            }
        };
        FreemarkerScript fs = new FreemarkerScript("SQL", be5Project.getApplication().getFreemarkerScripts());
        DataElementUtils.save(fs);
        ProcessController log = new NullLogger();
        while (true) {
            getLog().info("Enter FTL/SQL (use 'quit' to exit):");
            String line = new BufferedReader(new InputStreamReader(inputStream)).readLine();
            if (line == null) {
                break;
            }
            line = line.trim();
            if (line.equals("quit")) {
                break;
            }
            fs.setSource(line);
            ParseResult result = fs.getResult();
            if (result.getResult() != null) {
                getLog().info("SQL> " + result.getResult());
            } else {
                getLog().info("ERROR> " + result.getError());
                continue;
            }
            try {
                sql.executeScript(fs, log);
            } catch (Exception e) {
                getLog().info("ERROR> " + e.getMessage());
            }
        }
    } catch (Exception e) {
        throw new MojoFailureException("Console error: " + e.getMessage(), e);
    }
}
Also used : ParseResult(com.developmentontheedge.be5.metadata.model.ParseResult) SQLException(java.sql.SQLException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ExtendedSqlException(com.developmentontheedge.dbms.ExtendedSqlException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) SQLException(java.sql.SQLException) ExtendedSqlException(com.developmentontheedge.dbms.ExtendedSqlException) BeSqlExecutor(com.developmentontheedge.be5.metadata.sql.BeSqlExecutor) NullLogger(com.developmentontheedge.be5.metadata.util.NullLogger) BeConnectionProfile(com.developmentontheedge.be5.metadata.model.BeConnectionProfile) ProcessController(com.developmentontheedge.be5.metadata.util.ProcessController) ResultSet(java.sql.ResultSet) FreemarkerScript(com.developmentontheedge.be5.metadata.model.FreemarkerScript)

Aggregations

NullLogger (com.developmentontheedge.be5.metadata.util.NullLogger)2 ProcessController (com.developmentontheedge.be5.metadata.util.ProcessController)2 BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)1 FreemarkerScript (com.developmentontheedge.be5.metadata.model.FreemarkerScript)1 ParseResult (com.developmentontheedge.be5.metadata.model.ParseResult)1 Project (com.developmentontheedge.be5.metadata.model.Project)1 Query (com.developmentontheedge.be5.metadata.model.Query)1 BeSqlExecutor (com.developmentontheedge.be5.metadata.sql.BeSqlExecutor)1 Rdbms (com.developmentontheedge.be5.metadata.sql.Rdbms)1 DbmsSchemaReader (com.developmentontheedge.be5.metadata.sql.schema.DbmsSchemaReader)1 ExtendedSqlException (com.developmentontheedge.dbms.ExtendedSqlException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 Test (org.junit.Test)1