Package org.apache.empire.db

Examples of org.apache.empire.db.DBTableColumn


        sql.append(" (");
        boolean addSeparator = false;
        Iterator<DBColumn> columns = t.getColumns().iterator();
        while (columns.hasNext())
        {
            DBTableColumn c = (DBTableColumn) columns.next();
            sql.append((addSeparator) ? ",\r\n   " : "\r\n   ");
            if (appendColumnDesc(c, sql)==false)
                continue; // Ignore and continue;
            addSeparator = true;
        }
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){
          log.error("Unable to add the relation \""+relName+"\"! One of the columns could not be found.");
          continue;
        }
       
        // add the relation
        DBRelation.DBReference reference = fkCol.referenceOn(pkCol);
        DBRelation.DBReference[] refs = null;
          DBRelation r = db.getRelation(relName);
            if (r!=null) {
              DBRelation.DBReference[] refsOld = r.getReferences();
              refs = new DBRelation.DBReference[refsOld.length+1];
View Full Code Here

    try {
      rs = dbMeta.getColumns(config.getDbCatalog(), config.getDbSchema(),
          t.getName(), null);
          int i=0;
      while (rs.next()) {
        DBTableColumn c = addColumn(t, rs);
        // check if it is a KeyColumn
        if (pkCols.contains(c.getName()))
          keys[i++] = c;
       
        // check if it is the Timestamp/Locking Column
        if (lockColName!=null && c.getName().equalsIgnoreCase(lockColName))
          t.setTimestampColumn(c);
      }
          // Check whether all key columns have been set
          for (i=0; i<keys.length; i++)
              if (keys[i]==null){
View Full Code Here

   
    // Move from the return statement below so we can add
    // some AUTOINC meta data to the column to be used by
    // the ParserUtil and ultimately the template.
    log.info("\tCOLUMN:\t" + name + " ("+empireType+")");
    DBTableColumn col = t.addColumn(name, empireType, colSize, required, defaultValue);
   
    // We still need to know the base data type for this AUTOINC
    // because the Record g/setters need to know this, right?
    // So, let's add it as meta data every time the column is AUTOINC
    // and reference it in the template.
    if(empireType.equals(DataType.AUTOINC))
      col.setAttribute("AutoIncDataType", originalType);
    return col;
   
  }
View Full Code Here

        sql.append(" (");
        boolean addSeparator = false;
        Iterator<DBColumn> columns = t.getColumns().iterator();
        while (columns.hasNext())
        {
            DBTableColumn c = (DBTableColumn) columns.next();
            sql.append((addSeparator) ? ",\r\n   " : "\r\n   ");
            if (appendColumnDesc(c, sql)==false)
                continue; // Ignore and continue;
            addSeparator = true;
        }
View Full Code Here

        sql.append(" (");
        boolean addSeparator = false;
        Iterator<DBColumn> columns = t.getColumns().iterator();
        while (columns.hasNext())
        {
            DBTableColumn c = (DBTableColumn) columns.next();
            sql.append((addSeparator) ? ",\r\n   " : "\r\n   ");
            if (appendColumnDesc(c, sql)==false)
                continue; // Ignore and continue;
            addSeparator = true;
        }
View Full Code Here

        sql.append(" (");
        boolean addSeparator = false;
        Iterator<DBColumn> columns = t.getColumns().iterator();
        while (columns.hasNext())
        {
            DBTableColumn c = (DBTableColumn) columns.next();
            sql.append((addSeparator) ? ",\r\n   " : "\r\n   ");
            if (appendColumnDesc(c, sql, false)==false)
                continue; // Ignore and continue;
            addSeparator = true;
        }
View Full Code Here

        {
            DBTable table = seqtabs.next();
            Iterator<DBColumn> cols = table.getColumns().iterator();
            while (cols.hasNext())
            {
                DBTableColumn c = (DBTableColumn) cols.next();
                if (c.getDataType() == DataType.AUTOINC)
                {
                    createSequence(db, c, script);
                }
            }
        }
View Full Code Here

        sql.append(" (");
        boolean addSeparator = false;
        Iterator<DBColumn> columns = t.getColumns().iterator();
        while (columns.hasNext())
        {
            DBTableColumn c = (DBTableColumn) columns.next();
            sql.append((addSeparator) ? ",\r\n   " : "\r\n   ");
            if (appendColumnDesc(c, sql)==false)
                continue; // Ignore and continue;
            addSeparator = true;
        }
        // Primary Key
        DBIndex pk = t.getPrimaryKey();
        if (pk != null)
        { // add the primary key
            sql.append(",\r\n CONSTRAINT ");
            appendElementName(sql, pk.getName());
            sql.append(" PRIMARY KEY (");
            addSeparator = false;
            // columns
            DBColumn[] keyColumns = pk.getColumns();
            for (int i = 0; i < keyColumns.length; i++)
            {
                sql.append((addSeparator) ? ", " : "");
                keyColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                addSeparator = true;
            }
            sql.append(")");
        }
        sql.append(")");
        // Create the table
        DBDatabase db = t.getDatabase();
        if (script.addStmt(sql) == false)
            return false;
        // Create other Indizes (except primary key)
        Iterator<DBIndex> indexes = t.getIndexes().iterator();
        while (indexes.hasNext())
        {
            DBIndex idx = indexes.next();
            if (idx == pk || idx.getType() == DBIndex.PRIMARYKEY)
                continue;

            // Cretae Index
            sql.setLength(0);
            sql.append((idx.getType() == DBIndex.UNIQUE) ? "CREATE UNIQUE INDEX " : "CREATE INDEX ");
            appendElementName(sql, idx.getName());
            sql.append(" ON ");
            t.addSQL(sql, DBExpr.CTX_FULLNAME);
            sql.append(" (");
            addSeparator = false;

            // columns
            DBColumn[] idxColumns = idx.getColumns();
            for (int i = 0; i < idxColumns.length; i++)
            {
                sql.append((addSeparator) ? ", " : "");
                idxColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                sql.append("");
                addSeparator = true;
            }
            sql.append(")");
            // Create Index
            if (script.addStmt(sql) == false)
                return false;
        }
        // add Comments
        createComment(db, "TABLE", t, t.getComment(), script);
        columns = t.getColumns().iterator();
        while (columns.hasNext())
        {
            DBColumn c = columns.next();
            String com = c.getComment();
            if (com != null)
                createComment(db, "COLUMN", c, com, script);
        }
        // done
        return success();
View Full Code Here

        sql.append(" (");
        boolean addSeparator = false;
        Iterator<DBColumn> columns = t.getColumns().iterator();
        while (columns.hasNext())
        {
            DBTableColumn c = (DBTableColumn) columns.next();
            sql.append((addSeparator) ? ",\r\n   " : "\r\n   ");
            if (appendColumnDesc(c, sql)==false)
                continue; // Ignore and continue;
            addSeparator = true;
        }
View Full Code Here

TOP

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

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.