empire-db-examples/empire-db-example-jakarta-faces/src/main/java/org/apache/empire/jakarta/websample/web/pages/EmployeeListPage.java [42:245]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class EmployeeListPage extends SamplePage
{

	private static final Logger log = LoggerFactory.getLogger(EmployeeListPage.class);

    private BeanListPageElement<EmployeeListEntry> employees;
    
    public static class EmployeeListEntry extends ListPageElement.SelectableItem implements ParameterizedItem
    {
        // *Deprecated* private static final long serialVersionUID = 1L;

        private int               id; // employeeId;
        private String            name;
        private Gender            gender;
        private Date              dateOfBirth;
        private String            department;
        private boolean	 	      retired;
        private String            idParam;

        /**
         * Implements ParameterizedItem.
         * Used to uniquely identify this entry for selection and navigation 
         */
        @Override
        public String getIdParam()
        {
            return this.idParam;
        }

        /**
         * Implements ParameterizedItem.
         * This will automatically set the item idParam for navigation 
         */
        @Override
        public void setIdParam(String idParam)
        {
            this.idParam = idParam;
        }

        public int getId()
        {
            return id;
        }

        public void setId(int id)
        {
            this.id = id;
        }

        public String getName()
        {
            return name;
        }

        public void setName(String name)
        {
            this.name = name;
        }

        public Gender getGender()
        {
            return gender;
        }

        public void setGender(Gender gender)
        {
            this.gender = gender;
        }

        public Date getDateOfBirth()
        {
            return dateOfBirth;
        }

        public void setDateOfBirth(Date dateOfBirth)
        {
            this.dateOfBirth = dateOfBirth;
        }

        public String getDepartment()
        {
            return department;
        }

        public void setDepartment(String department)
        {
            this.department = department;
        }

		public boolean isRetired() {
			return retired;
		}

		public void setRetired(boolean retired) {
			this.retired = retired;
		}

    }

    public EmployeeListPage()
    {
        EmployeeListPage.log.trace("EmployeeListPage created");
        TEmployees EMP = getDatabase().EMPLOYEES;

        // create the Employees List page element
        employees = new BeanListPageElement<EmployeeListEntry>(this, EmployeeListEntry.class, getSampleContext(), EMP.ID);
    }

    
    public EmployeeSearchFilter getSearchFilter()
    {
        return SampleUtils.getManagedBean(EmployeeSearchFilter.class);
    }
    
    public ListPageElement<EmployeeListEntry> getEmployees()
    {
        return employees;
    }

    /*** Action Section ***/

    @Override
    public void doInit()
    { // Notify Elements
        super.doInit();
    }
    
    public void doResetSearch()
    {
        getSearchFilter().resetFilter();
        this.employees.clearItems();
    }
    
    public void doSearch()
    {
        TDepartments DEP = getDatabase().DEPARTMENTS;
        TEmployees EMP = getDatabase().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.ID, FULL_NAME);
        queryCmd.select(EMP.GENDER, EMP.DATE_OF_BIRTH, EMP.RETIRED);
        // queryCmd.select(EMP.RETIRED.decode(true, "X", "-"));
        queryCmd.select(DEPARTMENT);

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

        employees.initItems(queryCmd);
    }


    public Options getDepartmentOptions()
    {
    	TDepartments DEP = getDatabase().DEPARTMENTS;

    	DBCommand queryCmd = createQueryCommand();
    	queryCmd.select(DEP.ID, DEP.NAME);
    	
        return getSampleContext().getUtils().queryOptionList(queryCmd);
    }
    
    
    protected void addAllConstraints(DBCommand queryCmd)
    {
        TEmployees EMP = getDatabase().EMPLOYEES;
        EmployeeSearchFilter filter = getSearchFilter();
        
        addSearchConstraint(queryCmd, EMP.ID, filter);
        addSearchConstraint(queryCmd, EMP.FIRST_NAME, filter);
        addSearchConstraint(queryCmd, EMP.LAST_NAME, filter);
        addSearchConstraint(queryCmd, EMP.GENDER, filter);
        addSearchConstraint(queryCmd, EMP.DEPARTMENT_ID, filter);
    }
    
    private void addSearchConstraint(DBCommand cmd, DBColumn col, Object bean)
    {
        Object value = BeanPropertyUtils.getProperty(bean, col.getBeanPropertyName());
        if (ObjectUtils.isEmpty(value))
            return;
        // is it an array
        if (value instanceof Collection<?> || value.getClass().isArray())
        {
            cmd.where(col.in(value));
            return;
        }
        // text
        if (col.getOptions() == null && col.getDataType().isText())
        {
            StringBuilder b = new StringBuilder();
            b.append("%");
            b.append(((String) value).toUpperCase());
            b.append("%");
            cmd.where(col.upper().like(b.toString()));
            return;
        }
        // value
        cmd.where(col.is(value));
        return;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeListPage.java [44:247]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class EmployeeListPage extends SamplePage
{

	private static final Logger log = LoggerFactory.getLogger(EmployeeListPage.class);

    private BeanListPageElement<EmployeeListEntry> employees;
    
    public static class EmployeeListEntry extends ListPageElement.SelectableItem implements ParameterizedItem
    {
        // *Deprecated* private static final long serialVersionUID = 1L;

        private int               id; // employeeId;
        private String            name;
        private Gender            gender;
        private Date              dateOfBirth;
        private String            department;
        private boolean	 	      retired;
        private String            idParam;

        /**
         * Implements ParameterizedItem.
         * Used to uniquely identify this entry for selection and navigation 
         */
        @Override
        public String getIdParam()
        {
            return this.idParam;
        }

        /**
         * Implements ParameterizedItem.
         * This will automatically set the item idParam for navigation 
         */
        @Override
        public void setIdParam(String idParam)
        {
            this.idParam = idParam;
        }

        public int getId()
        {
            return id;
        }

        public void setId(int id)
        {
            this.id = id;
        }

        public String getName()
        {
            return name;
        }

        public void setName(String name)
        {
            this.name = name;
        }

        public Gender getGender()
        {
            return gender;
        }

        public void setGender(Gender gender)
        {
            this.gender = gender;
        }

        public Date getDateOfBirth()
        {
            return dateOfBirth;
        }

        public void setDateOfBirth(Date dateOfBirth)
        {
            this.dateOfBirth = dateOfBirth;
        }

        public String getDepartment()
        {
            return department;
        }

        public void setDepartment(String department)
        {
            this.department = department;
        }

		public boolean isRetired() {
			return retired;
		}

		public void setRetired(boolean retired) {
			this.retired = retired;
		}

    }

    public EmployeeListPage()
    {
        EmployeeListPage.log.trace("EmployeeListPage created");
        TEmployees EMP = getDatabase().EMPLOYEES;

        // create the Employees List page element
        employees = new BeanListPageElement<EmployeeListEntry>(this, EmployeeListEntry.class, getSampleContext(), EMP.ID);
    }

    
    public EmployeeSearchFilter getSearchFilter()
    {
        return SampleUtils.getManagedBean(EmployeeSearchFilter.class);
    }
    
    public ListPageElement<EmployeeListEntry> getEmployees()
    {
        return employees;
    }

    /*** Action Section ***/

    @Override
    public void doInit()
    { // Notify Elements
        super.doInit();
    }
    
    public void doResetSearch()
    {
        getSearchFilter().resetFilter();
        this.employees.clearItems();
    }
    
    public void doSearch()
    {
        TDepartments DEP = getDatabase().DEPARTMENTS;
        TEmployees EMP = getDatabase().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.ID, FULL_NAME);
        queryCmd.select(EMP.GENDER, EMP.DATE_OF_BIRTH, EMP.RETIRED);
        // queryCmd.select(EMP.RETIRED.decode(true, "X", "-"));
        queryCmd.select(DEPARTMENT);

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

        employees.initItems(queryCmd);
    }


    public Options getDepartmentOptions()
    {
    	TDepartments DEP = getDatabase().DEPARTMENTS;

    	DBCommand queryCmd = createQueryCommand();
    	queryCmd.select(DEP.ID, DEP.NAME);
    	
        return getSampleContext().getUtils().queryOptionList(queryCmd);
    }
    
    
    protected void addAllConstraints(DBCommand queryCmd)
    {
        TEmployees EMP = getDatabase().EMPLOYEES;
        EmployeeSearchFilter filter = getSearchFilter();
        
        addSearchConstraint(queryCmd, EMP.ID, filter);
        addSearchConstraint(queryCmd, EMP.FIRST_NAME, filter);
        addSearchConstraint(queryCmd, EMP.LAST_NAME, filter);
        addSearchConstraint(queryCmd, EMP.GENDER, filter);
        addSearchConstraint(queryCmd, EMP.DEPARTMENT_ID, filter);
    }
    
    private void addSearchConstraint(DBCommand cmd, DBColumn col, Object bean)
    {
        Object value = BeanPropertyUtils.getProperty(bean, col.getBeanPropertyName());
        if (ObjectUtils.isEmpty(value))
            return;
        // is it an array
        if (value instanceof Collection<?> || value.getClass().isArray())
        {
            cmd.where(col.in(value));
            return;
        }
        // text
        if (col.getOptions() == null && col.getDataType().isText())
        {
            StringBuilder b = new StringBuilder();
            b.append("%");
            b.append(((String) value).toUpperCase());
            b.append("%");
            cmd.where(col.upper().like(b.toString()));
            return;
        }
        // value
        cmd.where(col.is(value));
        return;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



