Example usage for javax.resource.cci RecordFactory createIndexedRecord

List of usage examples for javax.resource.cci RecordFactory createIndexedRecord

Introduction

In this page you can find the example usage for javax.resource.cci RecordFactory createIndexedRecord.

Prototype

public IndexedRecord createIndexedRecord(String recordName) throws ResourceException;

Source Link

Document

Creates a IndexedRecord.

Usage

From source file:org.hibersap.execution.jca.JCAMapper.java

@SuppressWarnings("unchecked")
private void mapToMappedRecord(final RecordFactory recordFactory, final Record record,
        final Map<String, Object> map) throws ResourceException {
    for (final String fieldName : map.keySet()) {
        final Object value = map.get(fieldName);

        if (Map.class.isAssignableFrom(value.getClass())) {
            final Map<String, Object> structureMap = UnsafeCastHelper.castToMap(value);
            final Record structure = recordFactory.createMappedRecord(fieldName);

            appendToRecord(record, fieldName, structure);

            mapToMappedRecord(recordFactory, structure, structureMap);
        } else if (Collection.class.isAssignableFrom(value.getClass())) {
            final Collection<Map<String, Object>> tableMap = UnsafeCastHelper.castToCollectionOfMaps(value);
            final IndexedRecord table = recordFactory.createIndexedRecord(fieldName);

            appendToRecord(record, fieldName, table);

            int i = 0;
            for (final Map<String, Object> row : tableMap) {
                MappedRecord rowRecord = recordFactory.createMappedRecord(fieldName + ":row:" + i);
                mapToMappedRecord(recordFactory, rowRecord, row);
                table.add(rowRecord);/*from   ww w.  j a  v a2  s  .  c  o  m*/
                i++;
            }
        } else {
            appendToRecord(record, fieldName, value);
        }
    }
}

From source file:org.springframework.jca.cci.core.CciTemplate.java

/**
 * Create an indexed Record through the ConnectionFactory's RecordFactory.
 * @param name the name of the record//  w  w  w .j  av a  2 s.  c o m
 * @return the Record
 * @throws DataAccessException if creation of the Record failed
 * @see #getRecordFactory(javax.resource.cci.ConnectionFactory)
 * @see javax.resource.cci.RecordFactory#createIndexedRecord(String)
 */
public IndexedRecord createIndexedRecord(String name) throws DataAccessException {
    try {
        RecordFactory recordFactory = getRecordFactory(obtainConnectionFactory());
        return recordFactory.createIndexedRecord(name);
    } catch (NotSupportedException ex) {
        throw new RecordTypeNotSupportedException("Creation of indexed Record not supported by connector", ex);
    } catch (ResourceException ex) {
        throw new CannotCreateRecordException("Creation of indexed Record failed", ex);
    }
}

From source file:org.springframework.samples.jca.dao.PersonDaoImpl.java

/**
 * @see org.springframework.samples.jca.dao.PersonneDao#getPerson(int)
 *///from   w w  w. j a v a 2 s . com
public Person getPerson(final int id) throws PersonException {
    CciInteractionSpec interactionSpec = new CciInteractionSpec();
    /*interactionSpec.setUser("sa");
    interactionSpec.setPassword("");*/
    interactionSpec.setSql("select * from person where person_id=?");

    List people = (List) getCciTemplate().execute(interactionSpec, new RecordCreator() {
        public Record createRecord(RecordFactory recordFactory) throws ResourceException, DataAccessException {
            IndexedRecord input = recordFactory.createIndexedRecord("input");
            input.add(new Integer(id));
            return input;
        }
    }, new RecordExtractor() {
        public Object extractData(Record record) throws ResourceException, SQLException, DataAccessException {
            List people = new ArrayList();
            ResultSet rs = (ResultSet) record;
            while (rs.next()) {
                Person person = new Person();
                person.setId(rs.getInt("person_id"));
                person.setLastName(rs.getString("person_last_name"));
                person.setFirstName(rs.getString("person_first_name"));
                people.add(person);
            }
            return people;
        }
    });

    if (people.size() == 1) {
        return (Person) people.get(0);
    } else {
        throw new PersonException("Can't the person");
    }
}

From source file:org.springframework.samples.jca.dao.PersonDaoImpl.java

/**
 * @see org.springframework.samples.jca.dao.PersonDao#updatePerson(org.springframework.samples.jca.model.Person)
 *//*  ww w.ja  v  a2 s  .co  m*/
public void updatePerson(final Person person) {
    StringBuffer request = new StringBuffer();
    request.append("update person set ");
    request.append("person_last_name=?,");
    request.append("person_first_name=?");
    request.append(" where person_id=?");
    CciInteractionSpec interactionSpec = new CciInteractionSpec();
    interactionSpec.setSql(request.toString());

    getCciTemplate().execute(interactionSpec, new RecordCreator() {
        public Record createRecord(RecordFactory recordFactory) throws ResourceException, DataAccessException {
            IndexedRecord input = recordFactory.createIndexedRecord("input");
            input.add(person.getLastName());
            input.add(person.getFirstName());
            input.add(new Integer(person.getId()));
            return input;
        }
    }, new RecordExtractor() {
        public Object extractData(Record record) throws ResourceException, SQLException, DataAccessException {
            IndexedRecord output = (IndexedRecord) record;
            for (Iterator i = output.iterator(); i.hasNext();) {
                log.debug("Number of updated lines : " + i.next());
            }
            return null;
        }
    });

}