Package ke.go.moh.oec.oecsm.data

Examples of ke.go.moh.oec.oecsm.data.SchemaTransaction


        String sql = "";
        if (transaction.getType() == TransactionType.INITIALIZE) {
            sql = "DELETE FROM `database`;";
        } else {
            if (transaction.getClass() == SchemaTransaction.class) {
                SchemaTransaction schemaTransaction = (SchemaTransaction) transaction;
                if (schemaTransaction.getType() == TransactionType.INSERT) {
                    if (schemaTransaction.getTarget().getClass() == Database.class) {
                        Database database = (Database) schemaTransaction.getTarget();
                        sql = "INSERT INTO `database` (`database`.`NAME`) VALUES ('" + TransactionConverter.escapeSQL(database.getName()) + "');";
                    } else if (schemaTransaction.getTarget().getClass() == Table.class) {
                        Table table = (Table) schemaTransaction.getTarget();
                        sql = "INSERT INTO `table` (`table`.`NAME`, `table`.`PRIMARY_KEYS`, `table`.`DATABASE_ID`) VALUES ('" + TransactionConverter.escapeSQL(table.getName()) + "', '" + TransactionConverter.escapeSQL(table.getPk()) + "', " + table.getDatabase().getId() + ");";
                    } else if (schemaTransaction.getTarget().getClass() == Column.class) {
                        Column cs = (Column) schemaTransaction.getTarget();
                        sql = "INSERT INTO `column` (`column`.`NAME`, `column`.`ORDINAL_POSITION`, `column`.`DATA_TYPE`, `column`.`SIZE`, `column`.`REPLICABLE`, `column`.`TABLE_ID`) VALUES('" + TransactionConverter.escapeSQL(cs.getName()) + "', " + cs.getOrdinalPosition() + ", '" + TransactionConverter.escapeSQL(cs.getDataType()) + "', " + cs.getSize() + ", " + cs.isReplicable() + ", " + cs.getTable().getId() + ");";
                    }
                } else if (schemaTransaction.getType() == TransactionType.UPDATE) {
                    if (schemaTransaction.getTarget().getClass() == Table.class) {
                        Table table = (Table) schemaTransaction.getTarget();
                        sql = "UPDATE `table` SET `table`.`PRIMARY_KEYS` = '" + table.getPk() + "' WHERE `table`.`ID` = " + table.getId() + ";";
                    } else if (schemaTransaction.getTarget().getClass() == Column.class) {
                        Column column = (Column) schemaTransaction.getTarget();
                        sql = "UPDATE `column` SET `column`.`ORDINAL_POSITION` = " + column.getOrdinalPosition() + ", `column`.`DATA_TYPE` = '" + column.getDataType() + "', `column`.`SIZE` = " + column.getSize() + " WHERE `column`.`ID` = " + column.getId() + ";";
                    }
                } else if (schemaTransaction.getType() == TransactionType.DELETE) {
                    if (schemaTransaction.getTarget().getClass() == Database.class) {
                        Database database = (Database) schemaTransaction.getTarget();
                        sql = "DELETE FROM `database` WHERE `database`.`ID` = " + database.getId() + ";";
                    } else if (schemaTransaction.getTarget().getClass() == Table.class) {
                        Table table = (Table) schemaTransaction.getTarget();
                        sql = "DELETE FROM `table` WHERE `table`.`ID` = " + table.getId() + ";";
                    } else if (schemaTransaction.getTarget().getClass() == Column.class) {
                        Column column = (Column) schemaTransaction.getTarget();
                        sql = "DELETE FROM `column` WHERE `column`.`ID` = " + column.getId() + ";";
                    }
                }
            } else if (transaction.getClass() == DataTransaction.class) {
                DataTransaction dataTransaction = (DataTransaction) transaction;
View Full Code Here


    private List<SchemaTransaction> generate() throws InaccessibleConfigurationFileException, DriverNotFoundException, SQLException {
        List<SchemaTransaction> schemaTransactionList = new ArrayList<SchemaTransaction>();
        Database sourceDatabase = new SourceSchemaMiner().mine();
        Database shadowDatabase = new ShadowSchemaMiner().mine();
        if (shadowDatabase == null) {
            schemaTransactionList.add(new SchemaTransaction(null, TransactionType.INITIALIZE));
            schemaTransactionList.add(new SchemaTransaction(sourceDatabase, TransactionType.INSERT));
        }
        schemaTransactionList.addAll(generateTableTransactions(sourceDatabase, shadowDatabase));
        return schemaTransactionList;
    }
View Full Code Here

    private List<SchemaTransaction> generateTableTransactions(Database sourceDatabase, Database shadowDatabase) {
        List<SchemaTransaction> schemaTransactionList = new ArrayList<SchemaTransaction>();
        if (shadowDatabase == null) {
            for (Table table : sourceDatabase.getTableList()) {
                schemaTransactionList.add(new SchemaTransaction(table, TransactionType.INSERT));
                schemaTransactionList.addAll(generateColumnTransactions(table, null));
            }
        } else {
            Collections.sort(sourceDatabase.getTableList());
            Collections.sort(shadowDatabase.getTableList());
            for (Table table : sourceDatabase.getTableList()) {
                if (!shadowDatabase.getTableList().contains(table)) {
                    table.setDatabase(shadowDatabase);
                    schemaTransactionList.add(new SchemaTransaction(table, TransactionType.INSERT));
                    schemaTransactionList.addAll(generateColumnTransactions(table, null));
                } else {
                    Table shadowTable = shadowDatabase.getTableList().get(shadowDatabase.getTableList().indexOf(table));
                    if (!table.getPk().equals(shadowTable.getPk())) {
                        table.setId(shadowTable.getId());
                        schemaTransactionList.add(new SchemaTransaction(table, TransactionType.UPDATE));
                    }
                    schemaTransactionList.addAll(generateColumnTransactions(table, shadowTable));
                }
            }
            for (Table table : shadowDatabase.getTableList()) {
                if (!sourceDatabase.getTableList().contains(table)) {
                    schemaTransactionList.add(new SchemaTransaction(table, TransactionType.DELETE));
                }
            }
        }
        return schemaTransactionList;
    }
View Full Code Here

    private List<SchemaTransaction> generateColumnTransactions(Table sourceTable, Table shadowTable) {
        List<SchemaTransaction> shemaTransactionList = new ArrayList<SchemaTransaction>();
        if (shadowTable == null) {
            for (Column column : sourceTable.getColumnList()) {
                shemaTransactionList.add(new SchemaTransaction(column, TransactionType.INSERT));
            }
        } else {
            Collections.sort(sourceTable.getColumnList());
            Collections.sort(shadowTable.getColumnList());
            for (Column column : sourceTable.getColumnList()) {
                if (!shadowTable.getColumnList().contains(column)) {
                    column.setTable(shadowTable);
                    shemaTransactionList.add(new SchemaTransaction(column, TransactionType.INSERT));
                } else {
                    Column shadowColumn = shadowTable.getColumnList().get(shadowTable.getColumnList().indexOf(column));
                    if (column.getOrdinalPosition() != (shadowColumn.getOrdinalPosition())
                            || !column.getDataType().equals(shadowColumn.getDataType())
                            || column.getSize() != shadowColumn.getSize()) {
                        column.setId(shadowColumn.getId());
                        shemaTransactionList.add(new SchemaTransaction(column, TransactionType.UPDATE));
                    }
                }
            }
            for (Column column : shadowTable.getColumnList()) {
                if (!sourceTable.getColumnList().contains(column)) {
                    shemaTransactionList.add(new SchemaTransaction(column, TransactionType.DELETE));
                }
            }
        }
        return shemaTransactionList;
    }
View Full Code Here

TOP

Related Classes of ke.go.moh.oec.oecsm.data.SchemaTransaction

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.