Examples of DBReader


Examples of org.apache.empire.db.DBReader

        cmd.where (T_EMP.C_GENDER.is(genderParam));
        cmd.where (db.V_EMPLOYEE_INFO.C_CURRENT_DEP_ID.is(curDepParam));

        System.out.println("Perfoming two queries using a the same command with different parameter values.");
       
        DBReader r = new DBReader();
        try {
            // Query all females currently working in the Production department
            System.out.println("1. Query all females currently working in the production department");
            // Set command parameter values
            genderParam.setValue('F'); // set gender to female
            curDepParam.setValue(idProdDep); // set department id to production department
            // Open reader using a prepared statement (due to command parameters!)
            r.open(cmd, conn);
            // print all results
            System.out.println("Females working in the production department are:");
            while (r.moveNext())
                System.out.println("    " + r.getString(T_EMP.C_FULLNAME));
            r.close();  

            // Second query
            // Now query all males currently working in the development department
            System.out.println("2. Query all males currently working in the development department");
            // Set command parameter values
            genderParam.setValue('M'); // set gender to female
            curDepParam.setValue(idDevDep); // set department id to production department
            // Open reader using a prepared statement (due to command parameters!)
            r.open(cmd, conn);
            // print all results
            System.out.println("Males currently working in the development department are:");
            while (r.moveNext())
                System.out.println("    " + r.getString(T_EMP.C_FULLNAME));

        } finally {
            r.close();
        }
       
    }
View Full Code Here

Examples of org.apache.empire.db.DBReader

        cmd.select(T_EMP.getColumns());
        // Set Constraints
        cmd.where(T_EMP.C_RETIRED.is(false));

        // 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
            DBRecord record = new DBRecord();
            while (reader.moveNext())
            {
                // Calculate sum
                int sum = 0;
                for (int i=0; i<reader.getFieldCount(); i++)
                    sum += calcCharSum(reader.getString(i));
                // Init updateable record
                reader.initRecord(EMP, record);
                // reader
                record.setValue(T_EMP.C_CHECKSUM, sum);
                record.update(conn);
            }
            // Done
            db.commit(conn);

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

Examples of org.apache.empire.db.DBReader

        cmd.select(T_EMP.getColumns());
        // Set Constraints
        cmd.where(T_EMP.C_RETIRED.is(false));

        // 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
            HashMap<Integer, DBRecord> employeeMap = new HashMap<Integer, DBRecord>();
            while (reader.moveNext())
            {
                DBRecord rec = new DBRecord();
                reader.initRecord(T_EMP, rec);
                employeeMap.put(reader.getInt(T_EMP.C_EMPLOYEE_ID), rec);
            }
            return employeeMap;

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

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());
            reader.open(cmd, conn);
            // 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

    }
   
    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

            comp = comp.and(T_EMP.DEPARTMENT_ID.is(department));
        }

        cmd.where(comp);

        DBReader reader = new DBReader();
        reader.open(cmd, conn);
        List<Employee> lst = reader.getBeanList(Employee.class);
        return lst;
    }
View Full Code Here

Examples of org.apache.empire.db.DBReader

    public List<Department> getDepartments()
    {
        DBCommand cmd = db.createCommand();
        cmd.select(T_DEP.getColumns());

        DBReader reader = new DBReader();
        reader.open(cmd, conn);
        return reader.getBeanList(Department.class);
    }
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

     */
    protected void loadItems(boolean initScrollbar)
    {
        // DBReader
        BeanListTableInfo lti = (BeanListTableInfo) getTableInfo();
        DBReader r = new DBReader();
        try
        { // Check command
            DBCommand queryCmd = lti.getQueryCmd();
            if (queryCmd == null)
                throw new ObjectNotValidException(this);

            boolean loadPageFromPosition = lti.isValid() && lti.isAllowPagination();
            lti.setValid(false);

            if (lti.isSortOrderChanged())
            { // Set Sort order
                setOrderBy(queryCmd);
                lti.setSortOrderChanged(false);
            }
           
            int position = 0;
            int skipRows = 0;
            int maxItems = maxItemCount;
            if (loadPageFromPosition)
            {   // detect position
                position = lti.getPosition();
                if (position > lti.getItemCount() - lti.getPageSize())
                { // position > count of entries is not possible, set to max
                    position = lti.getItemCount() - lti.getPageSize();
                }
                if (position < 0)
                { // position < 0 is not possible, set to 0
                    position = 0;
                }
                // maxItems
                maxItems = lti.getPageSize();
                skipRows = position;
                // constraint
                queryCmd.clearLimit();
                DBDatabaseDriver driver = queryCmd.getDatabase().getDriver();
                if (driver.isSupported(DBDriverFeature.QUERY_LIMIT_ROWS))
                {   // let the database limit the rows
                    if (driver.isSupported(DBDriverFeature.QUERY_SKIP_ROWS))
                    {   // let the database skip the rows
                        queryCmd.skipRows(skipRows);
                        skipRows = 0;
                    }
                    queryCmd.limitRows(skipRows+maxItems);
                }
            }

            // DBReader.open must always be surrounded with a try {} finally {} block!
            r.open(queryCmd, getConnection(queryCmd));

            // get position from the session
            if (skipRows>0)
            {   // we are not at position 0, "skipping" entries
                r.skipRows(skipRows);
            }

            // Read all Items
            items = r.getBeanList(beanClass, maxItems);
            if (items == null)
                throw new UnexpectedReturnValueException(items, "DBReader.getBeanList");
            generateIdParams(rowset, items);
            assignSelectionMap(items);

            // set position at session object
            if (loadPageFromPosition)
            { // set valid
                if (position + items.size() > lti.getItemCount())
                { // Oops: More items than expected.
                    log.warn("Item count of {} has changed. Adjusting item count.", getPropertyName());
                    lti.init(position + items.size(), lti.getPageSize());
                }
                lti.setPosition(position);
                lti.setModified(false);
                lti.setValid(true);
            }
            else
            { // Init the list
                lti.init(items.size(), 0);
            }
        }
        catch (RuntimeException e)
        {
            log.error("Error loading bean list " + e.getMessage(), e);
            throw e;
        }
        finally
        {
            r.close();
            // Pagination
            if (lti.isAllowPagination())
            { // Scrollbar  
                if (initScrollbar)
                    initScrollbar();
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.