Examples of DBReader


Examples of org.apache.empire.db.DBReader

     * @param conn the connection
     */
    private static void printQueryResults(DBCommand cmd, Connection conn)
    {
        // Query Records and print output
        DBReader reader = new DBReader();
        try
        {   // Open Reader
            System.out.println("Running Query:");
            System.out.println(cmd.getSelect());
            if (reader.open(cmd, conn) == false)
                throw new RuntimeException(reader.getErrorMessage());
            // Print column titles
            System.out.println("---------------------------------");
            int count = reader.getFieldCount();
            for (int i=0; i<count; i++)
            {   // Print all column names
                DBColumnExpr c = reader.getColumnExpr(i);
                if (i>0)
                    System.out.print("\t");
                System.out.print(c.getName());
            }
            // Print output
            System.out.println("");
            // Text-Output by iterating through all records.
            while (reader.moveNext())
            {
                for (int i=0; i<count; i++)
                {   // Print all field values
                    if (i>0)
                        System.out.print("\t");
                    // Check if conversion is necessary
                    DBColumnExpr c = reader.getColumnExpr(i);
                    Options opt = c.getOptions();
                    if (opt!=null)
                    {   // Option Lookup
                        System.out.print(opt.get(reader.getValue(i)));
                    }
                    else
                    {   // Print String
                        System.out.print(reader.getString(i));
                    }
                }
                System.out.println("");
            }

        } finally
        {   // always close Reader
            reader.close();
        }
    }
View Full Code Here

Examples of org.apache.empire.db.DBReader

        cmd.where(EMP.LASTNAME.length().isGreaterThan(0));
        cmd.orderBy(EMP.LASTNAME);
        cmd.orderBy(EMP.FIRSTNAME);

    // Query Records and print output
    DBReader reader = new DBReader();
    try
        {
      // Open Reader
      System.out.println("Running Query:");
      System.out.println(cmd.getSelect());
      reader.open(cmd, conn);
      // Print output
      System.out.println("---------------------------------");
      switch(queryType)
      {
          case Reader:
              // Text-Output by iterating through all records.
                  while (reader.moveNext())
                    {
                      System.out.println(reader.getString(EMP.EMPLOYEE_ID)
                              + "\t" + reader.getString(EMPLOYEE_FULLNAME)
                              + "\t" + EMP.GENDER.getOptions().get(reader.getString(EMP.GENDER))
                                + "\t" + reader.getString(PHONE_EXT_NUMBER)
                              + "\t" + reader.getString(DEP.NAME));
                  }
              break;
                case BeanList:
                    // Text-Output using a list of Java Beans supplied by the DBReader
                    List<SampleBean> beanList = reader.getBeanList(SampleBean.class);
                    System.out.println(String.valueOf(beanList.size()) + " SampleBeans returned from Query.");
                    for (SampleBean b : beanList)
                    {
                        System.out.println(b.toString());
                    }
                    break;
                case XmlDocument:
                    // XML Output
                    Document doc = reader.getXmlDocument();
                    // Print XML Document to System.out
                    XMLWriter.debug(doc);
                    break;
      }

    } finally
        {
      // always close Reader
      reader.close();
    }
  }
View Full Code Here

Examples of org.apache.empire.db.DBReader

        DBCommand sysDBCommand = sysDB.createCommand();
        sysDBCommand.select(sysDB.CI.getColumns());
        sysDBCommand.where (sysDB.CI.C_OWNER.is(owner));
       
        OracleDataDictionnary dataDictionnary = new OracleDataDictionnary();
        DBReader rd = new DBReader();
        try
        {
            rd.open(sysDBCommand, conn);
            // read all
            log.info("---------------------------------------------------------------------------------");
            log.info("checkDatabase start: " + db.getClass().getName());
            String skipTable = "";
            while (rd.moveNext())
            {
                String tableName = rd.getString(sysDB.CI.C_TABLE_NAME);

                // if a table wasn't found before, skip it
                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;
                    }
                    /*
                    else
                    {   // check the DBTableColumn definition
                        int length = (charLength>0) ? charLength : dataLength;
                        dataDictionnary.checkColumnDefinition(col, dataType, length, dataPrecision, dataScale, nullable.equals("N"));
                    }
                    */
                }
                else if (dbView!=null)
                {
                    log.debug("Column check for view " + tableName + " not yet implemented.");
                }
                else
                {
                    log.debug("TABLE OR VIEW NOT FOUND IN " + db.getClass().getName() + "\t: [" + tableName + "]");
                    // skip this table
                    skipTable = tableName;
                    continue;
                }
            }
            // check Tables
            dataDictionnary.checkDBTableDefinition(db.getTables());
            // check Views
            dataDictionnary.checkDBViewDefinition (db.getViews());
            // done
            log.info("checkDatabase end: " + db.getClass().getName());
            log.info("---------------------------------------------------------------------------------");
        } finally {
            // close
            rd.close();
        }
    }
View Full Code Here

Examples of org.apache.empire.db.DBReader

    public RuntimeException translateEmpireException(EmpireException e) {
        return new EmpireDBException(e);
    }

    protected DBReader openReader(DBCommand cmd, Connection conn) {
        DBReader r = new DBReader();
        r.open(cmd, conn);
        return r;
    }
View Full Code Here

Examples of org.apache.empire.db.DBReader

    }
   
    public int fetch(Connection conn, int maxItems)
    {
        clear();
        DBReader reader = new DBReader();
        try {
            // Open and Read
            reader.open(cmd, conn);
            reader.getBeanList(this, clazz, maxItems);
            return size();
           
        } finally {
            reader.close();
        }
    }
View Full Code Here

Examples of org.apache.empire.db.DBReader

        emp.update(conn);
   
    // read a value
    DBCommand cmd = db.createCommand();
    cmd.select(db.DATA.DATA);
    DBReader reader = new DBReader();
    reader.open(cmd, conn);
    while(reader.moveNext()){
      byte[] value = (byte[]) reader.getValue(db.DATA.DATA);
      Assert.assertArrayEquals(new byte[]{1,2,3}, value);
    }
    conn.close();
  }
View Full Code Here

Examples of org.apache.empire.db.DBReader

        DBCommand sysDBCommand = sysDB.createCommand();
        sysDBCommand.select(sysDB.CI.getColumns());
        sysDBCommand.where (sysDB.CI.C_OWNER.is(owner));
       
        OracleDataDictionnary dataDictionnary = new OracleDataDictionnary();
        DBReader rd = new DBReader();
        try
        {
            rd.open(sysDBCommand, conn);
            // read all
            log.info("---------------------------------------------------------------------------------");
            log.info("checkDatabase start: " + db.getClass().getName());
            String skipTable = "";
            while (rd.moveNext())
            {
                String tableName = rd.getString(sysDB.CI.C_TABLE_NAME);

                // if a table wasn't found before, skip it
                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;
                    }
                    /*
                    else
                    {   // check the DBTableColumn definition
                        int length = (charLength>0) ? charLength : dataLength;
                        dataDictionnary.checkColumnDefinition(col, dataType, length, dataPrecision, dataScale, nullable.equals("N"));
                    }
                    */
                }
                else if (dbView!=null)
                {
                    log.debug("Column check for view " + tableName + " not yet implemented.");
                }
                else
                {
                    log.debug("TABLE OR VIEW NOT FOUND IN " + db.getClass().getName() + "\t: [" + tableName + "]");
                    // skip this table
                    skipTable = tableName;
                    continue;
                }
            }
            // check Tables
            dataDictionnary.checkDBTableDefinition(db.getTables());
            // check Views
            dataDictionnary.checkDBViewDefinition (db.getViews());
            // done
            log.info("checkDatabase end: " + db.getClass().getName());
            log.info("---------------------------------------------------------------------------------");
        } finally {
            // close
            rd.close();
        }
    }
View Full Code Here

Examples of org.apache.empire.db.DBReader

                    Object value = record.getValue(keyColumns[0]);
                    cmd.where(keyColumns[0].isNot(value));
                }
            }
            // Query now
            DBReader reader = new DBReader();
            try {
                reader.getRecordData(cmd, action.getConnection());
                // We have found a record
                Object[] key = new Object[keyColumns.length];
                for (int i=0; i<keyColumns.length; i++)
                {   // Check if column has changed
                    key[i] = reader.getValue(i);
                }
                return key;
            } catch(QueryNoResultException e) {
                // ignore
            } finally {
                reader.close();
            }
        }
        // No, no conflicts
        return null;
    }
View Full Code Here

Examples of org.apache.empire.db.DBReader

        cmd.where(EMP.LASTNAME.length().isGreaterThan(0));
        cmd.orderBy(EMP.LASTNAME);
        cmd.orderBy(EMP.FIRSTNAME);

    // Query Records and print output
    DBReader reader = new DBReader();
    try
        {
      // Open Reader
      System.out.println("Running Query:");
      System.out.println(cmd.getSelect());
      reader.open(cmd, conn);
      // Print output
      System.out.println("---------------------------------");
      switch(queryType)
      {
          case Reader:
              // Text-Output by iterating through all records.
                  while (reader.moveNext())
                    {
                      System.out.println(reader.getString(EMP.EMPLOYEE_ID)
                              + "\t" + reader.getString(EMPLOYEE_FULLNAME)
                              + "\t" + EMP.GENDER.getOptions().get(reader.getString(EMP.GENDER))
                                + "\t" + reader.getString(PHONE_EXT_NUMBER)
                              + "\t" + reader.getString(DEP.NAME));
                  }
              break;
                case BeanList:
                    // Text-Output using a list of Java Beans supplied by the DBReader
                    List<SampleBean> beanList = reader.getBeanList(SampleBean.class);
                    System.out.println(String.valueOf(beanList.size()) + " SampleBeans returned from Query.");
                    for (SampleBean b : beanList)
                    {
                        System.out.println(b.toString());
                    }
                    break;
                case XmlDocument:
                    // XML Output
                    Document doc = reader.getXmlDocument();
                    // Print XML Document to System.out
                    XMLWriter.debug(doc);
                    break;
      }

    } finally
        {
      // always close Reader
      reader.close();
    }
  }
View Full Code Here

Examples of org.apache.empire.db.DBReader

        DBCommand sysDBCommand = sysDB.createCommand();
        sysDBCommand.select(sysDB.CI.getColumns());
        sysDBCommand.where (sysDB.CI.C_OWNER.is(owner));
       
        OracleDataDictionnary dataDictionnary = new OracleDataDictionnary();
        DBReader rd = new DBReader();
        try
        {
            if (rd.open(sysDBCommand, conn))
            {
                log.info("---------------------------------------------------------------------------------");
                log.info("checkDatabase start: " + db.getClass().getName());
                String skipTable = "";
                while (rd.moveNext())
                {
                    String tableName = rd.getString(sysDB.CI.C_TABLE_NAME);

                    // if a table wasn't found before, skip it
                    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;
                        }
                        /*
                        else
                        {   // check the DBTableColumn definition
                            int length = (charLength>0) ? charLength : dataLength;
                            dataDictionnary.checkColumnDefinition(col, dataType, length, dataPrecision, dataScale, nullable.equals("N"));
                        }
                        */
                    }
                    else if (dbView!=null)
                    {
                        log.debug("Column check for view " + tableName + " not yet implemented.");
                    }
                    else
                    {
                        log.debug("TABLE OR VIEW NOT FOUND IN " + db.getClass().getName() + "\t: [" + tableName + "]");
                        // skip this table
                        skipTable = tableName;
                        continue;
                    }
                }
                // check Tables
                dataDictionnary.checkDBTableDefinition(db.getTables());
                // check Views
                dataDictionnary.checkDBViewDefinition (db.getViews());
            }
            else {
                return error(Errors.NotAuthorized);
            }
            log.info("checkDatabase end: " + db.getClass().getName());
            log.info("---------------------------------------------------------------------------------");
            return success();
        } finally
        {
            rd.close();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.