Package org.apache.empire.samples.spring.db

Examples of org.apache.empire.samples.spring.db.SampleDB


public class EmpireAppImpl extends EmpireDaoSupport implements EmpireApp {


    @Transactional
    public void clearDatabase() {
        SampleDB db = getDB();
        Connection conn = getConnection();

        DBCommand cmd = db.createCommand();
        // Delete all Employees (no constraints)
        db.executeSQL(cmd.getDelete(db.EMPLOYEES), conn);
        // Delete all Departments (no constraints)
        db.executeSQL(cmd.getDelete(db.DEPARTMENTS), conn);
    }
View Full Code Here


        db.executeSQL(cmd.getDelete(db.DEPARTMENTS), conn);
    }

    @Transactional
    public Integer insertDepartment(String departmentName, String businessUnit) {
        SampleDB db = getDB();
        Connection conn = getConnection();

        DBRecord rec = new DBRecord();
        rec.create(db.DEPARTMENTS);
        rec.setValue(db.DEPARTMENTS.NAME, departmentName);
View Full Code Here

        return rec.getInt(db.DEPARTMENTS.DEPARTMENT_ID);
    }

    @Transactional
    public Integer insertEmployee(String firstName, String lastName, String gender, int departmentId) {
        SampleDB db = getDB();
        Connection conn = getConnection();

        DBRecord rec = new DBRecord();
        rec.create(db.EMPLOYEES);
        rec.setValue(db.EMPLOYEES.FIRSTNAME, firstName);
View Full Code Here

        if (getEmployee(idPers) == null) {
            //if you like more verbose exceptions for the app
            throw new IllegalArgumentException("The specified employee does not exist.");
        }

        SampleDB db = getDB();
        Connection conn = getConnection();

        DBRecord rec = new DBRecord();
    rec.read(db.EMPLOYEES, idPers, conn);
    // Set
View Full Code Here

        initializeDatabase();
    }

    @Transactional(readOnly = true)
    public void doQuery(QueryType type) {
        SampleDB db = getDB();
        Connection conn = getConnection();

      // Define the query
      DBCommand cmd = db.createCommand();
      // Define shortcuts for tables used - not necessary but convenient
      SampleDB.Employees   EMP = db.EMPLOYEES;
      SampleDB.Departments DEP = db.DEPARTMENTS;

      // The following expression concats lastname + ', ' + firstname
        DBColumnExpr EMPLOYEE_FULLNAME = EMP.LASTNAME.append(", ").append(EMP.FIRSTNAME).as("FULL_NAME");

        // The following expression extracts the extension number from the phone field
        // e.g. substr(PHONE_NUMBER, length(PHONE_NUMBER)-instr(reverse(PHONE_NUMBER), '-')+2) AS PHONE_EXTENSION
        // Hint: Since the reverse() function is not supported by HSQLDB there is special treatment for HSQL
        DBColumnExpr PHONE_LAST_DASH;
        if ( db.getDriver() instanceof DBDatabaseDriverHSql
            || db.getDriver() instanceof DBDatabaseDriverDerby
            || db.getDriver() instanceof DBDatabaseDriverH2)
             PHONE_LAST_DASH = EMP.PHONE_NUMBER.indexOf("-", EMP.PHONE_NUMBER.indexOf("-").plus(1)).plus(1); // HSQLDB only
        else PHONE_LAST_DASH = EMP.PHONE_NUMBER.length().minus(EMP.PHONE_NUMBER.reverse().indexOf("-")).plus(2);
        DBColumnExpr PHONE_EXT_NUMBER = EMP.PHONE_NUMBER.substring(PHONE_LAST_DASH).as("PHONE_EXTENSION");

        // DBColumnExpr genderExpr = cmd.select(EMP.GENDER.decode(EMP.GENDER.getOptions()).as(EMP.GENDER.getName()));
    // Select required columns
    cmd.select(EMP.EMPLOYEE_ID, EMPLOYEE_FULLNAME);
    if(db.getDriver() instanceof DBDatabaseDriverPostgreSQL)
    {
      // postgres does not support the substring expression
      cmd.select(EMP.GENDER, EMP.PHONE_NUMBER);
    }else{
      cmd.select(EMP.GENDER, EMP.PHONE_NUMBER, PHONE_EXT_NUMBER);
View Full Code Here

    }
    }


    public Map<Object, Object> getDepartment(int id) {
        SampleDB db = getDB();
        return get(db.DEPARTMENTS, id);
    }
View Full Code Here

        SampleDB db = getDB();
        return get(db.DEPARTMENTS, id);
    }

    public Map<Object, Object> getEmployee(int id) {
        SampleDB db = getDB();
        return get(db.EMPLOYEES, id);
    }
View Full Code Here

TOP

Related Classes of org.apache.empire.samples.spring.db.SampleDB

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.