Package org.apache.empire.db

Examples of org.apache.empire.db.DBTable


     *
     * @return true if the relation has been created successfully
     */
    private boolean createRelation(DBRelation r, DBSQLScript script)
    {
        DBTable sourceTable = (DBTable) r.getReferences()[0].getSourceColumn().getRowSet();
        DBTable targetTable = (DBTable) r.getReferences()[0].getTargetColumn().getRowSet();

        StringBuilder sql = new StringBuilder();
        sql.append("-- creating foreign key constraint ");
        sql.append(r.getName());
        sql.append(" --\r\n");
        sql.append("ALTER TABLE ");
        sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
        sql.append(" ADD CONSTRAINT ");
        appendElementName(sql, r.getName());
        sql.append(" FOREIGN KEY (");
        // Source Names
        boolean addSeparator = false;
        DBRelation.DBReference[] refs = r.getReferences();
        for (int i = 0; i < refs.length; i++)
        {
            sql.append((addSeparator) ? ", " : "");
            refs[i].getSourceColumn().addSQL(sql, DBExpr.CTX_NAME);
            addSeparator = true;
        }
        // References
        sql.append(") REFERENCES ");
        targetTable.addSQL(sql, DBExpr.CTX_FULLNAME);
        sql.append(" (");
        // Target Names
        addSeparator = false;
        for (int i = 0; i < refs.length; i++)
        {
View Full Code Here


    {
        // Create all Sequences
        Iterator<DBTable> seqtabs = db.getTables().iterator();
        while (seqtabs.hasNext())
        {
            DBTable table = seqtabs.next();
            Iterator<DBColumn> cols = table.getColumns().iterator();
            while (cols.hasNext())
            {
                DBTableColumn c = (DBTableColumn) cols.next();
                if (c.getDataType() == DataType.AUTOINC)
                {
View Full Code Here

     * Create a sql string for creating a relation and appends it to the supplied buffer
     * @return true if the relation has been created successfully
     */
    private boolean createRelation(DBRelation r, DBSQLScript script)
    {
        DBTable sourceTable = (DBTable) r.getReferences()[0].getSourceColumn().getRowSet();
        DBTable targetTable = (DBTable) r.getReferences()[0].getTargetColumn().getRowSet();

        StringBuilder sql = new StringBuilder();
        sql.append("-- creating foreign key constraint ");
        sql.append(r.getName());
        sql.append(" --\r\n");
        sql.append("ALTER TABLE ");
        sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
        sql.append(" ADD CONSTRAINT ");
        appendElementName(sql, r.getName());
        sql.append(" FOREIGN KEY (");
        // Source Names
        boolean addSeparator = false;
        DBRelation.DBReference[] refs = r.getReferences();
        for (int i = 0; i < refs.length; i++)
        {
            sql.append((addSeparator) ? ", " : "");
            refs[i].getSourceColumn().addSQL(sql, DBExpr.CTX_NAME);
            addSeparator = true;
        }
        // References
        sql.append(") REFERENCES ");
        targetTable.addSQL(sql, DBExpr.CTX_FULLNAME);
        sql.append(" (");
        // Target Names
        addSeparator = false;
        for (int i = 0; i < refs.length; i++)
        {
View Full Code Here

                    if (tableName.equals(skipTable))
                        continue;

                    // check if the found table exists in the DBDatabase object
                    String columnName = rd.getString(sysDB.CI.C_COLUMN_NAME);
                    DBTable dbTable = db.getTable(tableName);
                    DBView  dbView  = db.getView(tableName);
                   
                    String dataType = rd.getString(sysDB.CI.C_DATA_TYPE);
                    int charLength = rd.getInt(sysDB.CI.C_CHAR_LENGTH);
                    int dataLength = rd.getInt(sysDB.CI.C_DATA_LENGTH);
                    int dataPrecision = rd.getInt(sysDB.CI.C_DATA_PRECISION);
                    int dataScale = rd.getInt(sysDB.CI.C_DATA_SCALE);
                    String nullable = rd.getString(sysDB.CI.C_NULLABLE);
                   
                    dataDictionnary.fillDataDictionnary(tableName, columnName, dataType,
                                                        charLength, dataLength, dataPrecision, dataScale, nullable);
                   
                    if (dbTable != null)
                    {
                       
                        // check if the found column exists in the found DBTable
                        DBColumn col = dbTable.getColumn(columnName);
                        if (col == null)
                        {
                            log.warn("COLUMN NOT FOUND IN " + db.getClass().getName() + "\t: [" + tableName + "]["
                                           + columnName + "][" + dataType + "][" + dataLength + "]");
                            continue;
View Full Code Here

     * @see DBDatabaseDriver#getNextSequenceValue(DBDatabase, String, int, Connection)
     */
    @Override
    public Object getNextSequenceValue(DBDatabase db, String seqName, int minValue, Connection conn)
    {   //Use Oracle Sequences
        DBTable t = db.getTable(sequenceTableName);
        return ((DBSeqTable)t).getNextValue(seqName, minValue, conn);
    }
View Full Code Here

     *
     * @return true if the relation has been created successfully
     */
    private boolean createRelation(DBRelation r, DBSQLScript script)
    {
        DBTable sourceTable = (DBTable) r.getReferences()[0].getSourceColumn().getRowSet();
        DBTable targetTable = (DBTable) r.getReferences()[0].getTargetColumn().getRowSet();

        StringBuilder sql = new StringBuilder();
        sql.append("-- creating foreign key constraint ");
        sql.append(r.getName());
        sql.append(" --\r\n");
        sql.append("ALTER TABLE ");
        sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
        sql.append(" ADD CONSTRAINT ");
        appendElementName(sql, r.getName());
        sql.append(" FOREIGN KEY (");
        // Source Names
        boolean addSeparator = false;
        DBRelation.DBReference[] refs = r.getReferences();
        for (int i = 0; i < refs.length; i++)
        {
            sql.append((addSeparator) ? ", " : "");
            refs[i].getSourceColumn().addSQL(sql, DBExpr.CTX_NAME);
            addSeparator = true;
        }
        // References
        sql.append(") REFERENCES ");
        targetTable.addSQL(sql, DBExpr.CTX_FULLNAME);
        sql.append(" (");
        // Target Names
        addSeparator = false;
        for (int i = 0; i < refs.length; i++)
        {
View Full Code Here

    {
        // Create all Sequences
        Iterator<DBTable> seqtabs = db.getTables().iterator();
        while (seqtabs.hasNext())
        {
            DBTable table = seqtabs.next();
            Iterator<DBColumn> cols = table.getColumns().iterator();
            while (cols.hasNext())
            {
                DBTableColumn c = (DBTableColumn) cols.next();
                if (c.getDataType() == DataType.AUTOINC)
                {
View Full Code Here

    {
        switch(type)
        {
            case CREATE:
            {
                DBTable sourceTable = (DBTable) r.getReferences()[0].getSourceColumn().getRowSet();
                DBTable targetTable = (DBTable) r.getReferences()[0].getTargetColumn().getRowSet();

                StringBuilder sql = new StringBuilder();
                sql.append("-- creating foreign key constraint ");
                sql.append(r.getName());
                sql.append(" --\r\n");
                sql.append("ALTER TABLE ");
                sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
                sql.append(" ADD CONSTRAINT ");
                appendElementName(sql, r.getName());
                sql.append(" FOREIGN KEY (");
                // Source Names
                boolean addSeparator = false;
                DBRelation.DBReference[] refs = r.getReferences();
                for (int i = 0; i < refs.length; i++)
                {
                    sql.append((addSeparator) ? ", " : "");
                    refs[i].getSourceColumn().addSQL(sql, DBExpr.CTX_NAME);
                    addSeparator = true;
                }
                // References
                sql.append(") REFERENCES ");
                targetTable.addSQL(sql, DBExpr.CTX_FULLNAME);
                sql.append(" (");
                // Target Names
                addSeparator = false;
                for (int i = 0; i < refs.length; i++)
                {
                    sql.append((addSeparator) ? ", " : "");
                    refs[i].getTargetColumn().addSQL(sql, DBExpr.CTX_NAME);
                    addSeparator = true;
                }
                // done
                sql.append(")");
                if (script.addStmt(sql.toString()) == false)
                    return false;
                // done
                return success();
               
            }
            case DROP:
            {
                DBTable sourceTable = (DBTable) r.getReferences()[0].getSourceColumn().getRowSet();
                StringBuilder sql = new StringBuilder();
                sql.append("-- dropping constraint ");
                sql.append(r.getName());
                sql.append(" --\r\n");
                sql.append("ALTER TABLE ");
                sourceTable.addSQL(sql, DBExpr.CTX_FULLNAME);
                sql.append(" DROP CONSTRAINT ");
                appendElementName(sql, r.getName());
                // done
                return script.addStmt(sql.toString());
            }
View Full Code Here

          if(tableType.equalsIgnoreCase("VIEW")){
            InMemoryView view = new InMemoryView(tableName, db);
            populateView(view);
            viewCount++;
          } else {
            DBTable table = new DBTable(tableName, db);
            populateTable(table);
            populatedTables.add(tableName);
            tableCount++;
          }
        }
View Full Code Here

 
  private void gatherRelations(DBDatabase db, DatabaseMetaData dbMeta, ArrayList<String> tables) throws SQLException{
    ResultSet relations = null;
    String fkTableName, pkTableName, fkColName, pkColName, relName;
    DBTableColumn fkCol, pkCol;
    DBTable fkTable, pkTable;
    DBColumn col;
   
    // Add all Relations
    for (String tableName :tables) {
     
      // check for foreign-keys
      relations = dbMeta.getImportedKeys(config.getDbCatalog(), config .getDbSchema(), tableName);
      while (relations.next()) {
        pkCol=fkCol=null;
       
        fkTableName=relations.getString("FKTABLE_NAME");
        pkTableName=relations.getString("PKTABLE_NAME");
        fkColName=relations.getString("FKCOLUMN_NAME");
        pkColName=relations.getString("PKCOLUMN_NAME");

        // Detect relation name
        relName=relations.getString("FK_NAME");
        if (StringUtils.isEmpty(relName))
          relName=fkTableName+"."+fkColName+"-"+pkTableName+"."+pkColName;
       
        pkTable = db.getTable(pkTableName);
        fkTable = db.getTable(fkTableName);
       
        // check if both tables really exist in the model
        if(pkTable==null || fkTable==null){
          log.error("Unable to add the relation \""+relName+"\"! One of the tables could not be found.");
          continue;
        }
       
        col=pkTable.getColumn(pkColName);
        if(col instanceof DBTableColumn)
          pkCol = (DBTableColumn) col;
 
        col=fkTable.getColumn(fkColName);
        if(col instanceof DBTableColumn)
          fkCol = (DBTableColumn) col;
       
        // check if both columns really exist in the model
        if(fkCol==null || pkCol==null){
View Full Code Here

TOP

Related Classes of org.apache.empire.db.DBTable

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.