Package de.huepattl.playground.batch

Examples of de.huepattl.playground.batch.Employee


     * @return Modified item, same class in this example ({@link de.huepattl.playground.batch.Employee}).
     * @throws Exception BAM!
     */
    @Override
    public Object processItem(Object item) throws Exception {
        Employee e = (Employee) item;
        e.setFirstName("Darth " + e.getFirstName());
        return e;
    }
View Full Code Here


    @Override
    public void writeItems(List<Object> objects) throws Exception {
        LOG.debug("Bunched WRITE:");

        for (final Object current : objects) {
            final Employee e = (Employee) current;
            if (LOG.isDebugEnabled()) {
                LOG.debug("-> Write XML: " + e);
            }

            JAXBElement<Employee> ele = new JAXBElement<>(
View Full Code Here

    public Object readItem() throws Exception {
        cursor++;
        final String line = reader.readLine();

        if (line != null && line.contains(",")) {
            Employee e = new Employee();
            String[] elements = line.split(",");
            try {
                e.setId(Long.parseLong(elements[0]));
                e.setLastName(elements[1]);
                e.setFirstName(elements[2]);
                // FIXME
                //e.setBirthDate(DateTime.parse(elements[3]).toDate());
                e.setExternal(Boolean.parseBoolean(elements[4]));
            } catch (Exception ex) {
                LOG.error("Ooops! I had issues parsing a CSV record!", ex);
            }
            LOG.debug("-> Single CSV READ: " + e);
            return e;
View Full Code Here

        for (Object current : items) {
            /**
             * Throw exception for testing purposes?
             */
            if (!exceptions.isEmpty()) {
                Employee emp = (Employee) current;
                Class<Exception> ex = exceptions.get(emp.getId());
                if (ex != null) {
                    LOG.warn("We reached item with employee ID " + emp.getId()
                            + ", throwing emulated exception as requested: "
                            + ex.getCanonicalName());
                    LOG.warn("Affected item: " + current);

                    emp.setRemark("This item caused an exception!");
                    failedItems.add(emp);
                    throw ex.getConstructor(String.class).newInstance(
                            "Emulated exception thrown by request (configured in job XML!.)");
                }
            }
        }

        /*
         Remember! This is JPA. Since we are still in the transaction as opened
         in the reader, our entities are still attached to the persistence context.
         There is no need to call for persistence explicitly ;)
         However, before the transaction is finished, we ensure writing by calling
         EntityManager.flush() via our service.
         */
        employeeService.flush();

        // Debugging? OK, log our each written employee...
        if (LOG.isDebugEnabled()) {
            for (Object current : items) {
                Employee e = (Employee) current;
                LOG.debug("WRITE: " + e);
            }
        }
    }
View Full Code Here

     *
     * @throws Exception BAM!
     */
    @Override
    public Object processItem(Object item) throws Exception {
        Employee e = (Employee) item;
        e.setRemark(changeRemarkTo);
        return e;
    }
View Full Code Here

TOP

Related Classes of de.huepattl.playground.batch.Employee

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.