Package org.apache.empire.db

Examples of org.apache.empire.db.DBCommand


            db.commit(conn);

            // STEP 7: read from Employee_Info_View
            if (true) {
                System.out.println("*** read from EMPLOYEE_INFO_VIEW ***");
                DBCommand cmd = db.createCommand();
                cmd.select (db.V_EMPLOYEE_INFO.getColumns());
                cmd.orderBy(db.V_EMPLOYEE_INFO.C_NAME_AND_DEP);
                printQueryResults(cmd, conn);
            }
            // STEP 8: bulkReadRecords
            if (true) {
                System.out.println("*** bulkReadRecords: reads employee records into a hashmap, reads employee from hashmap and updates employee ***");
 
View Full Code Here


     * </PRE>
     */
    private static boolean databaseExists(Connection conn)
    {
        // Check wether DB exists
        DBCommand cmd = db.createCommand();
        cmd.select(T_DEP.count());
        // Check using "select count(*) from DEPARTMENTS"
        System.out.println("Checking whether table DEPARTMENTS exists (SQLException will be logged if not - please ignore) ...");
        return (db.querySingleInt(cmd.getSelect(), -1, conn) >= 0);
    }
View Full Code Here

     * Empties all Tables.
     * </PRE>
     */
    private static void clearDatabase(Connection conn)
    {
        DBCommand cmd = db.createCommand();
        // Delete all Employee Department History records
        db.executeSQL(cmd.getDelete(T_EDH), conn);
        // Delete all Employees (no constraints)
        db.executeSQL(cmd.getDelete(T_EMP), conn);
        // Delete all Departments (no constraints)
        db.executeSQL(cmd.getDelete(T_DEP), conn);
    }
View Full Code Here

     * @param conn a connection to the database
     */
    private static void bulkProcessRecords(Connection conn)
    {
        // Define the query
        DBCommand cmd = db.createCommand();
        // Define shortcuts for tables used - not necessary but convenient
        SampleAdvDB.Employees EMP = T_EMP;
        // Select requried columns
        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());
            if (reader.open(cmd, conn) == false)
                throw new RuntimeException(reader.getErrorMessage());
            // Print output
            DBRecord record = new DBRecord();
            while (reader.moveNext())
View Full Code Here

    }
   
    private static HashMap<Integer, DBRecord> bulkReadRecords(Connection conn)
    {
        // Define the query
        DBCommand cmd = db.createCommand();
        // Select requried columns
        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());
            if (reader.open(cmd, conn) == false)
                throw new RuntimeException(reader.getErrorMessage());
            // Print output
            HashMap<Integer, DBRecord> employeeMap = new HashMap<Integer, DBRecord>();
            while (reader.moveNext())
View Full Code Here

     * @param employeeId
     */
    private static void querySample(Connection conn, int employeeId)
    {
        // Define the sub query
        DBCommand subCmd = db.createCommand();
        DBColumnExpr MAX_DATE_FROM = T_EDH.C_DATE_FROM.max().as(T_EDH.C_DATE_FROM);
        subCmd.select(T_EDH.C_EMPLOYEE_ID, MAX_DATE_FROM);
        subCmd.groupBy(T_EDH.C_EMPLOYEE_ID);
        DBQuery Q_MAX_DATE = new DBQuery(subCmd);

        // Define the query
        DBCommand cmd = db.createCommand();
        // Select requried columns
        cmd.select(T_EMP.C_EMPLOYEE_ID, T_EMP.C_FULLNAME);
        cmd.select(T_EMP.C_GENDER, T_EMP.C_PHONE_NUMBER);
        cmd.select(T_DEP.C_DEPARTMENT_ID, T_DEP.C_NAME, T_DEP.C_BUSINESS_UNIT);
        cmd.select(T_EMP.C_UPDATE_TIMESTAMP, T_DEP.C_UPDATE_TIMESTAMP);
        // Set Joins
        cmd.join(T_EDH.C_EMPLOYEE_ID, Q_MAX_DATE.findQueryColumn(T_EDH.C_EMPLOYEE_ID))
          .where(T_EDH.C_DATE_FROM.is(Q_MAX_DATE.findQueryColumn(MAX_DATE_FROM)));
        cmd.join(T_EMP.C_EMPLOYEE_ID, T_EDH.C_EMPLOYEE_ID);
        cmd.join(T_DEP.C_DEPARTMENT_ID, T_EDH.C_DEPARTMENT_ID);
        // Set Constraints
        cmd.where(T_EMP.C_RETIRED.is(false));
        // Set Order
        cmd.orderBy(T_EMP.C_LASTNAME);
        cmd.orderBy(T_EMP.C_FIRSTNAME);

        // Query Records and print output
        printQueryResults(cmd, conn);
       
        // Define an updateable query
View Full Code Here

    public Options getFieldOptions(DBColumn column)
    {
        if (column.equals(T.DEPARTMENT_ID))
        {
            SampleDB db = (SampleDB) getDatabase();
            DBCommand cmd = db.createCommand();
            cmd.select(db.T_DEPARTMENTS.DEPARTMENT_ID);
            cmd.select(db.T_DEPARTMENTS.NAME);
            cmd.orderBy(db.T_DEPARTMENTS.NAME);
            return db.queryOptionList(cmd, SampleUtils.getConnection());
        }
        // base class implementation
        return super.getFieldOptions(column);
    }
View Full Code Here

    return sampleDB;
  }

  private boolean databaseExists(Connection conn) {
    // Check wether DB exists
    DBCommand cmd = sampleDB.createCommand();
    cmd.select(sampleDB.T_DEPARTMENTS.count());
    try {
      return (sampleDB.querySingleInt(cmd, -1, conn) >= 0);
    } catch (QueryFailedException e) {
      return false;
    }
View Full Code Here

        TEmployees EMP = getDatabase().T_EMPLOYEES;

        DBColumnExpr FULL_NAME = EMP.LAST_NAME.append(", ").append(EMP.FIRST_NAME).as("NAME");
        DBColumnExpr DEPARTMENT = DEP.NAME.as("DEPARTMENT");

        DBCommand queryCmd = createQueryCommand();

        queryCmd.select(EMP.EMPLOYEE_ID, FULL_NAME);
        queryCmd.select(EMP.GENDER, EMP.DATE_OF_BIRTH);
        queryCmd.select(DEPARTMENT);

        queryCmd.join(DEP.DEPARTMENT_ID, EMP.DEPARTMENT_ID);
        queryCmd.orderBy(EMP.FIRST_NAME);
       
        addAllConstraints(queryCmd);

        employees.initItems(queryCmd);
    }
View Full Code Here

     *
     * @param queryCmd
     */
    public final void initItems(DBCommand queryCmd, int pageSize)
    {
        DBCommand countCmd = queryCmd.clone();
        initItems(queryCmd, countCmd, 0);
    }
View Full Code Here

TOP

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

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.