Example usage for java.sql ResultSet getBytes

List of usage examples for java.sql ResultSet getBytes

Introduction

In this page you can find the example usage for java.sql ResultSet getBytes.

Prototype

byte[] getBytes(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a byte array in the Java programming language.

Usage

From source file:eu.trentorise.smartcampus.permissionprovider.oauth.AutoJdbcTokenStore.java

public OAuth2AccessToken readAccessTokenForRefreshToken(String tokenValue) {
    OAuth2AccessToken accessToken = null;

    String key = extractTokenKey(tokenValue);

    try {//from   w  ww  .j  av a2  s. c om
        accessToken = jdbcTemplate.queryForObject(selectAccessTokenFromRefreshTokenSql,
                new RowMapper<OAuth2AccessToken>() {
                    public OAuth2AccessToken mapRow(ResultSet rs, int rowNum) throws SQLException {
                        return deserializeAccessToken(rs.getBytes(2));
                    }
                }, key);
    } catch (EmptyResultDataAccessException e) {
        if (logger.isInfoEnabled()) {
            logger.debug("Failed to find access token for refresh " + tokenValue);
        }
    } catch (IllegalArgumentException e) {
        logger.error("Could not extract access token for refresh " + tokenValue);
    }

    return accessToken;
}

From source file:org.seasar.s2sqlmap.spring.lob.port.DefaultLobHandler.java

public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException {
    logger.debug("Returning BLOB as bytes");
    return rs.getBytes(columnIndex);
}

From source file:com.ethlo.kfka.mysql.TestCfg.java

@Bean
public KfkaMapStore<CustomKfkaMessage> mapStore(DataSource ds) {
    final RowMapper<CustomKfkaMessage> ROW_MAPPER = new RowMapper<CustomKfkaMessage>() {
        @Override//  w  w w .j a v a2s. c  om
        public CustomKfkaMessage mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new CustomKfkaMessageBuilder().userId(rs.getInt("userId")).payload(rs.getBytes("payload"))
                    .timestamp(rs.getLong("timestamp")).topic(rs.getString("topic")).type(rs.getString("type"))
                    .id(rs.getLong("id")).build();
        }
    };

    return new MysqlKfkaMapStore<CustomKfkaMessage>(ds, ROW_MAPPER);
}

From source file:org.sakaiproject.util.DbSingleStorageReader.java

public Object readSqlResultRecord(ResultSet result) {
    try {//from   w ww  . j  a  va2 s.c o m
        if (storage instanceof BaseDbBinarySingleStorage) {
            return ((BaseDbBinarySingleStorage) storage).readResource(result.getBytes(1));
        } else if (storage instanceof BaseDbDualSingleStorage) {
            return ((BaseDbDualSingleStorage) storage).readResource(result.getString(1), result.getBytes(2));
        } else {
            return ((BaseDbSingleStorage) storage).readResource(result.getString(1));
        }
    } catch (Exception ex) {
        log.error("Failed to read entity Record ");
    }
    return null;
}

From source file:org.sleuthkit.autopsy.casemodule.SingleUserCaseConverter.java

/**
 * Place a NULL inside a prepared statement if needed, otherwise, place the
 * byte array that was in the ResultSet.
 *
 * @param pst     the prepared statement
 * @param rs      the ResultSet to work with
 * @param rsIndex index for the result set
 * @param psIndex index for the prepared statement
 *
 * @throws SQLException//from   ww w  . j ava 2s. c om
 */
private static void populateNullableByteArray(PreparedStatement pst, ResultSet rs, int rsIndex, int psIndex)
        throws SQLException {
    byte[] nullableBytes = rs.getBytes(rsIndex);
    if (rs.wasNull()) {
        pst.setNull(psIndex, java.sql.Types.NULL);
    } else {
        pst.setBytes(psIndex, nullableBytes);
    }
}

From source file:com.bt.aloha.collections.database.DatabaseInfoCollectionHousekeepingRowCallBackHandler.java

@SuppressWarnings("unchecked")
public void processRow(ResultSet resultSet) throws SQLException {

    String objectId = null;//from  w  w  w  .ja v  a2 s  .  c  o  m
    try {
        objectId = resultSet.getString("object_id");
        byte[] bytes = resultSet.getBytes("object_value");
        Object deserialised = new ObjectSerialiser().deserialise(bytes);
        String beanName = ((StateInfoBase) deserialised).getSimpleSipBeanId();
        log.info(String.format("Housekeeping: preparing an dialogInfo %s for being housekept by %s", objectId,
                beanName));
        HousekeeperAware creatorBean = (HousekeeperAware) applicationContext.getBean(beanName);
        creatorBean.killHousekeeperCandidate(objectId);
    } catch (Throwable t) {
        log.error(String.format(
                "Unable to kill housekeeper candidate %s...will still remove from collection next housekeep",
                objectId), t);
    }
}

From source file:org.springframework.batch.sample.common.StagingItemReader.java

@Override
public ProcessIndicatorItemWrapper<T> read() {
    if (!initialized) {
        throw new ReaderNotOpenException("Reader must be open before it can be used.");
    }//from w w  w  . j a v  a 2  s.c  o  m

    Long id = null;
    synchronized (lock) {
        if (keys.hasNext()) {
            id = keys.next();
        }
    }
    logger.debug("Retrieved key from list: " + id);

    if (id == null) {
        return null;
    }
    @SuppressWarnings("unchecked")
    T result = (T) jdbcTemplate.queryForObject("SELECT VALUE FROM BATCH_STAGING WHERE ID=?",
            new RowMapper<Object>() {
                @Override
                public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                    byte[] blob = rs.getBytes(1);
                    return SerializationUtils.deserialize(blob);
                }
            }, id);

    return new ProcessIndicatorItemWrapper<T>(id, result);
}

From source file:org.theospi.portfolio.presentation.model.impl.HibernatePresentationProperties.java

public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
    byte[] bytes = rs.getBytes(names[0]);
    if (rs.wasNull())
        return null;

    ElementBean elementBean = new ElementBean();
    elementBean.setDeferValidation(true);
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    SAXBuilder saxBuilder = new SAXBuilder();
    saxBuilder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); // SAK-23131
    try {/*from w w  w .j  ava2 s.co  m*/
        Document doc = saxBuilder.build(in);
        elementBean.setBaseElement(doc.getRootElement());
    } catch (JDOMException e) {
        throw new HibernateException(e);
    } catch (IOException e) {
        throw new HibernateException(e);
    }
    return elementBean;
}

From source file:org.sakaiproject.metaobj.shared.model.impl.HibernateStructuredArtifact.java

public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
    byte[] bytes = rs.getBytes(names[0]);
    if (rs.wasNull()) {
        return null;
    }/*w  ww.  j  a  v  a2s.co  m*/

    //TODO figure out how to inject this
    HomeFactory homeFactory = (HomeFactory) ComponentManager.getInstance().get("xmlHomeFactory");
    WritableObjectHome home = (WritableObjectHome) homeFactory.getHome("agent");

    StructuredArtifact artifact = (StructuredArtifact) home.createInstance();
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    SAXBuilder saxBuilder = new SAXBuilder();
    saxBuilder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); // SAK-23245
    try {
        Document doc = saxBuilder.build(in);
        artifact.setBaseElement(doc.getRootElement());
    } catch (JDOMException e) {
        throw new HibernateException(e);
    } catch (IOException e) {
        throw new HibernateException(e);
    }
    return artifact;
}

From source file:lcn.module.batch.web.guide.support.StagingItemReader.java

/**
 * BATCH_STAGING? value? ?//from ww w . j ava 2 s.c o m
 * @return ProcessIndicatorItemWrapper : 
 */
public ProcessIndicatorItemWrapper<T> read() throws DataAccessException {

    if (!initialized) {
        throw new ReaderNotOpenException("Reader must be open before it can be used.");
    }

    Long id = null;
    synchronized (lock) {
        if (keys.hasNext()) {
            id = keys.next();
        }
    }
    logger.debug("Retrieved key from list: " + id);

    if (id == null) {
        return null;
    }
    @SuppressWarnings("unchecked")
    T result = (T) jdbcTemplate.queryForObject("SELECT VALUE FROM BATCH_STAGING WHERE ID=?",
            new ParameterizedRowMapper<Object>() {
                public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                    byte[] blob = rs.getBytes(1);
                    return SerializationUtils.deserialize(blob);
                }
            }, id);

    return new ProcessIndicatorItemWrapper<T>(id, result);

}