Examples of DBCommand


Examples of org.apache.empire.db.DBCommand

    public Options getDepartments()
    {
        if (departments==null)
        {
            SampleDB db = getDatabase();
            DBCommand cmd = db.createCommand();
            cmd.select(db.T_DEPARTMENTS.C_DEPARTMENT_ID);
            cmd.select(db.T_DEPARTMENTS.C_NAME);
            cmd.orderBy(db.T_DEPARTMENTS.C_NAME.asc());
            departments = db.queryOptionList(cmd, getConnection());
        }
        return departments;
    }
View Full Code Here

Examples of org.apache.empire.db.DBCommand

    {
        SampleDB db = getDatabase();
        SampleDB.Employees EMP = db.T_EMPLOYEES;
        SampleDB.Departments DEP = db.T_DEPARTMENTS;
       
        DBCommand cmd = db.createCommand();
        cmd.select(EMP.C_EMPLOYEE_ID);
        cmd.select(C_FULL_NAME, EMP.C_GENDER, EMP.C_DATE_OF_BIRTH);
        cmd.select(C_DEPARTMENT);
        cmd.join  (DEP.C_DEPARTMENT_ID, EMP.C_DEPARTMENT_ID);

        // Set filter constraints
        SearchInfo si = getSearchInfo();
        if (si.getDepartmentId()!=null)
            cmd.where(EMP.C_DEPARTMENT_ID.is(si.getDepartmentId()));
        if (StringUtils.isNotEmpty( si.getFirstName()) )
            cmd.where(EMP.C_FIRSTNAME.likeUpper( si.getFirstName()+"%" )
                  .or(EMP.C_FIRSTNAME.is(null)));
        if (StringUtils.isNotEmpty( si.getLastName()) )
            cmd.where(EMP.C_LASTNAME.likeUpper( si.getLastName()+"%" ));
       
        cmd.orderBy(EMP.C_LASTNAME);
        cmd.orderBy(EMP.C_FIRSTNAME);
       
        // Init BeanList
        if (!employeeBeanList.initBeanList(cmd))
        {   // Error
            return LIST;
View Full Code Here

Examples of org.apache.empire.db.DBCommand

    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

Examples of org.apache.empire.db.DBCommand

           
            SampleAdvDB db = (SampleAdvDB)getDatabase();
            SampleAdvDB.EmployeeDepartmentHistory T_EDH = db.T_EMP_DEP_HIST;
           
            // Define the sub query
            DBCommand cmd = db.createCommand();
            cmd.select (T_EDH.C_EMPLOYEE_ID, T_EDH.C_DATE_FROM.max());
            cmd.groupBy(T_EDH.C_EMPLOYEE_ID);
            return cmd;
        }
View Full Code Here

Examples of org.apache.empire.db.DBCommand

            SampleAdvDB.EmployeeDepartmentHistory T_EDH = db.T_EMP_DEP_HIST;
            SampleAdvDB.EmployeeDepSinceView V_EDS = db.V_EMP_DEP_SINCE_VIEW;
            SampleAdvDB.Departments T_DEP = db.T_DEPARTMENTS;

            // Define the query
            DBCommand cmd = db.createCommand();
            // Select required columns
            cmd.select(T_EMP.C_EMPLOYEE_ID);
            cmd.select(T_DEP.C_DEPARTMENT_ID);
            cmd.select(T_EMP.C_LASTNAME.append(", ")
                       .append(T_EMP.C_FIRSTNAME.coalesce(DBDatabase.EMPTY_STRING))
                       .append(" (").append(T_DEP.C_NAME).append(")"));
            // Set Joins
            cmd.join(T_EDH.C_EMPLOYEE_ID, V_EDS.C_EMPLOYEE_ID)
              .where(T_EDH.C_DATE_FROM.is(V_EDS.C_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);
            // done
            return cmd;
        }
View Full Code Here

Examples of org.apache.empire.db.DBCommand

        }
    }

  private void databaseExists(Connection conn) {
    // Check wether DB exists
    DBCommand cmd = db.createCommand();
    cmd.select(db.T_DEPARTMENTS.count());
    db.querySingleInt(cmd, -1, conn);
  }
View Full Code Here

Examples of org.apache.empire.db.DBCommand

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

Examples of org.apache.empire.db.DBCommand

            db.commit(conn);
           
            // STEP 7: read from Employee_Info_View
            System.out.println("--------------------------------------------------------");
            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: prepared Statement sample
            System.out.println("--------------------------------------------------------");
            System.out.println("*** commandParamsSample: shows how to use command parameters for the generation of prepared statements ***");
 
View Full Code Here

Examples of org.apache.empire.db.DBCommand

     * </PRE>
     */
    private static boolean databaseExists(Connection conn)
    {
        // Check whether 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, -1, conn) >= 0);
    }
View Full Code Here

Examples of org.apache.empire.db.DBCommand

     * Empties all Tables.
     * </PRE>
     */
    private static void clearDatabase(Connection conn)
    {
        DBCommand cmd = db.createCommand();
        // Delete all Employee Department History records
        db.executeDelete(T_EDH, cmd, conn);
        // Delete all Employees (no constraints)
        db.executeDelete(T_EMP, cmd, conn);
        // Delete all Departments (no constraints)
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.