Search in sources :

Example 11 with ProcessInterruptedException

use of com.developmentontheedge.be5.metadata.exception.ProcessInterruptedException in project be5 by DevelopmentOnTheEdge.

the class AppSync method execute.

// /////////////////////////////////////////////////////////////////
@Override
public void execute() throws MojoFailureException {
    init();
    PrintStream ps = null;
    try {
        if (logPath != null) {
            logPath.mkdirs();
            ps = new PrintStream(new File(logPath, be5Project.getName() + "_sync_ddl.sql"), "UTF-8");
        }
        sqlExecutor = new BeSqlExecutor(connector, ps);
        if (be5Project.getDebugStream() != null) {
            be5Project.getDebugStream().println("Modules and extras for " + be5Project.getName() + ":");
            be5Project.allModules().map(m -> "- " + m.getName() + ": " + (m.getExtras() == null ? "" : String.join(", ", m.getExtras()))).forEach(be5Project.getDebugStream()::println);
        }
        readSchema();
        createEntities();
        String ddlString = getDdlStatements(false);
        ddlString = MultiSqlParser.normalize(be5Project.getDatabaseSystem().getType(), ddlString);
        if (ddlString.isEmpty()) {
            getLog().info("Database scheme is up-to-date");
            return;
        }
        if (forceUpdate) {
            sqlExecutor.startSection("Sync schema");
            logger.setOperationName("[>] Schema");
            sqlExecutor.executeMultiple(ddlString);
            sqlExecutor.startSection(null);
        } else {
            System.err.println("The following statements should be executed to update database scheme:");
            System.err.println(ddlString);
            System.err.println("Use -DBE5_FORCE_UPDATE=true, for apply");
        }
        checkSynchronizationStatus();
        logger.setOperationName("Finished");
    } catch (// ReadException | ProjectLoadException | SQLException e )
    FreemarkerSqlException | ExtendedSqlException | SQLException e) {
        if (debug)
            throw new MojoFailureException("Synchronisation error: " + e.getMessage(), e);
        throw new MojoFailureException("Synchronisation error: " + e.getMessage());
    } catch (IOException | ProcessInterruptedException e) {
        throw new MojoFailureException("Synchronisation error: " + e.getMessage(), e);
    } catch (Throwable t) {
        t.printStackTrace();
        throw new MojoFailureException("Synchronisation error: " + t.getMessage(), t);
    } finally {
        if (ps != null) {
            ps.close();
        }
    }
}
Also used : FreemarkerSqlException(com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException) Arrays(java.util.Arrays) ViewDef(com.developmentontheedge.be5.metadata.model.ViewDef) NullLogger(com.developmentontheedge.be5.metadata.util.NullLogger) HashMap(java.util.HashMap) BeSqlExecutor(com.developmentontheedge.be5.metadata.sql.BeSqlExecutor) Parameter(org.apache.maven.plugins.annotations.Parameter) MultiSqlParser(com.developmentontheedge.dbms.MultiSqlParser) Rdbms(com.developmentontheedge.be5.metadata.sql.Rdbms) ArrayList(java.util.ArrayList) Entity(com.developmentontheedge.be5.metadata.model.Entity) DefaultTypeManager(com.developmentontheedge.be5.metadata.sql.type.DefaultTypeManager) Mojo(org.apache.maven.plugins.annotations.Mojo) SQLException(java.sql.SQLException) IndexDef(com.developmentontheedge.be5.metadata.model.IndexDef) DatabaseUtils(com.developmentontheedge.be5.metadata.sql.DatabaseUtils) ResultSet(java.sql.ResultSet) Locale(java.util.Locale) Map(java.util.Map) ExtendedSqlException(com.developmentontheedge.dbms.ExtendedSqlException) DdlElement(com.developmentontheedge.be5.metadata.model.DdlElement) Module(com.developmentontheedge.be5.metadata.model.Module) TableDef(com.developmentontheedge.be5.metadata.model.TableDef) DataElementUtils(com.developmentontheedge.be5.metadata.model.DataElementUtils) ProcessController(com.developmentontheedge.be5.metadata.util.ProcessController) PrintStream(java.io.PrintStream) DbmsTypeManager(com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager) ProcessInterruptedException(com.developmentontheedge.be5.metadata.exception.ProcessInterruptedException) IndexColumnDef(com.developmentontheedge.be5.metadata.model.IndexColumnDef) IOException(java.io.IOException) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) SqlColumnInfo(com.developmentontheedge.be5.metadata.sql.pojo.SqlColumnInfo) List(java.util.List) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) IndexInfo(com.developmentontheedge.be5.metadata.sql.pojo.IndexInfo) SqlColumnType(com.developmentontheedge.be5.metadata.model.SqlColumnType) DbmsType(com.developmentontheedge.dbms.DbmsType) IntStreamEx(one.util.streamex.IntStreamEx) Pattern(java.util.regex.Pattern) Project(com.developmentontheedge.be5.metadata.model.Project) Collections(java.util.Collections) EntityType(com.developmentontheedge.be5.metadata.model.EntityType) DbmsSchemaReader(com.developmentontheedge.be5.metadata.sql.schema.DbmsSchemaReader) FreemarkerSqlException(com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException) PrintStream(java.io.PrintStream) SQLException(java.sql.SQLException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) ExtendedSqlException(com.developmentontheedge.dbms.ExtendedSqlException) BeSqlExecutor(com.developmentontheedge.be5.metadata.sql.BeSqlExecutor) File(java.io.File) ProcessInterruptedException(com.developmentontheedge.be5.metadata.exception.ProcessInterruptedException)

Aggregations

ResultSet (java.sql.ResultSet)10 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 List (java.util.List)10 DbmsConnector (com.developmentontheedge.dbms.DbmsConnector)9 SqlColumnInfo (com.developmentontheedge.be5.metadata.sql.pojo.SqlColumnInfo)6 IndexInfo (com.developmentontheedge.be5.metadata.sql.pojo.IndexInfo)5 Matcher (java.util.regex.Matcher)3 ColumnFunction (com.developmentontheedge.be5.metadata.model.ColumnFunction)2 Rdbms (com.developmentontheedge.be5.metadata.sql.Rdbms)2 DbmsSchemaReader (com.developmentontheedge.be5.metadata.sql.schema.DbmsSchemaReader)2 NullLogger (com.developmentontheedge.be5.metadata.util.NullLogger)2 ProcessController (com.developmentontheedge.be5.metadata.util.ProcessController)2 FreemarkerSqlException (com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException)1 ProcessInterruptedException (com.developmentontheedge.be5.metadata.exception.ProcessInterruptedException)1 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)1 DataElementUtils (com.developmentontheedge.be5.metadata.model.DataElementUtils)1 DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)1 Entity (com.developmentontheedge.be5.metadata.model.Entity)1 EntityType (com.developmentontheedge.be5.metadata.model.EntityType)1