Package org.apache.empire.db

Examples of org.apache.empire.db.DBCommand


        if (owner==null || owner.length()==0)
            return error(Errors.InvalidArg, owner, "owner");
        // Datebase definition
        OracleSYSDatabase sysDB = new OracleSYSDatabase(this);
        // Check Columns
        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
        {
View Full Code Here


   * Empties all Tables.
     * </PRE>
   */
  private static void clearDatabase(Connection conn, CompanyDB db)
    {
    DBCommand cmd = db.createCommand();
    // Delete all Employees (no constraints)
    db.executeSQL(cmd.getDelete(db.DEPARTMENT), conn);
  }
View Full Code Here

     * </PRE>
   */
  private static boolean databaseExists(Connection conn, CompanyDB db)
    {
    // Check whether DB exists
    DBCommand cmd = db.createCommand();
    cmd.select(db.DEPARTMENT.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

           
            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

            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

            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

     * </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.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

    /* This procedure demonstrates the use of command parameter for prepared statements */
    private static void commandParamsSample(Connection conn, int idProdDep, int idDevDep)
    {
        // create a command
        DBCommand cmd = db.createCommand();
        // Create cmd parameters
        DBCommandParam curDepParam = cmd.addParam(); // Current Department
        DBCommandParam genderParam = cmd.addParam(); // Gender ('M' or 'F')
        // Define the query
        cmd.select(T_EMP.C_FULLNAME);
        cmd.join  (T_EMP.C_EMPLOYEE_ID, db.V_EMPLOYEE_INFO.C_EMPLOYEE_ID);
        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 {
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 required 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

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.