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

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


        statement.close();
        return table;
    }

    private Database findDatabase(int id) throws SQLException, InaccessibleConfigurationFileException, DriverNotFoundException {
        Database db = null;
        Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery("SELECT `database`.`ID`, `database`.`NAME` FROM `database` WHERE `database`.`ID` = " + id + "");
        if (rs.next()) {
            db = new Database(rs.getInt("ID"), rs.getString("NAME"));
        }
        rs.close();
        statement.close();
        return db;
    }
View Full Code Here


        } 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();
View Full Code Here

public class SourceSchemaMiner extends DatabaseConnector {

    private DatabaseMetaData databaseMetaData;

    public Database mine() throws InaccessibleConfigurationFileException, DriverNotFoundException, SQLException {
        Database db = null;
        try {
            connectToSource();
            databaseMetaData = connection.getMetaData();
            db = new Database(database);
            populateTableList(db);
        } finally {
            disconnectFromSource();
        }
        return db;
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));
View Full Code Here

    public void synchronize() throws InaccessibleConfigurationFileException, DriverNotFoundException, SQLException {
        SourceDataMiner sourceDataMiner = new SourceDataMiner();
        ShadowDataMiner shadowDataMiner = new ShadowDataMiner();
        sourceDataMiner.start();
        shadowDataMiner.start();
        Database shadowDb = new ShadowSchemaMiner().mine(true);

        for (Table table : shadowDb.getTableList()) {
            SourceResultSet sourceRs = sourceDataMiner.mine(table);
            ShadowResultSet shadowRs = shadowDataMiner.mine(table);

            sourceRsHasRecords = sourceRs.next();
            shadowRsHasRecords = shadowRs.next();
View Full Code Here

* @author Gitahi Ng'ang'a
*/
public class ShadowSchemaMiner extends DatabaseConnector {

    public Database mine(boolean replicable) throws InaccessibleConfigurationFileException, DriverNotFoundException, SQLException {
        Database db = null;
        try {
            connectToShadow();
            db = extractDatabase();
            if (db == null) {
                return null;
View Full Code Here

    public Database mine() throws InaccessibleConfigurationFileException, DriverNotFoundException, SQLException {
        return mine(false);
    }

    private Database extractDatabase() throws SQLException {
        Database db = null;
        Statement statement = connection.createStatement();
        String sql = "SELECT `database`.`ID`, `database`.`NAME` FROM `database` WHERE `database`.`NAME` = '" + database + "'";
        Mediator.getLogger(ShadowSchemaMiner.class.getName()).log(Level.FINEST, sql);
        ResultSet rs = statement.executeQuery(sql);
        if (rs.next()) {
            db = new Database(rs.getInt("ID"), rs.getString("NAME"));
        }
        rs.close();
        statement.close();
        return db;
    }
View Full Code Here

TOP

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

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.