Example usage for org.springframework.jdbc.core PreparedStatementCreator PreparedStatementCreator

List of usage examples for org.springframework.jdbc.core PreparedStatementCreator PreparedStatementCreator

Introduction

In this page you can find the example usage for org.springframework.jdbc.core PreparedStatementCreator PreparedStatementCreator.

Prototype

PreparedStatementCreator

Source Link

Usage

From source file:org.ednovo.gooru.infrastructure.persistence.hibernate.resource.ResourceRepositoryHibernate.java

@Override
public void saveTextBook(final Long contentId, final String documentId, final String documentKey) {
    final String sql = "INSERT INTO textbook (content_id, document_id,document_key) values(?,?,?)";
    PreparedStatementCreator creator = new PreparedStatementCreator() {

        @Override/*w  ww .  ja  va  2  s .co m*/
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement saveTextbook = con.prepareStatement(sql);
            saveTextbook.setLong(1, contentId);
            saveTextbook.setString(2, documentId);
            saveTextbook.setString(3, documentKey);
            return saveTextbook;
        }
    };
    getJdbcTemplate().update(creator);
}

From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.AgentDaoImpl.java

/**
 * @see org.gbif.portal.dao.AgentDAO#create(org.gbif.portal.model.Agent)
 *///from   w w  w. j  a  va 2s .  c  om
public long create(final Agent agent) {
    Date now = new Date();
    agent.setModified(now);
    agent.setCreated(now);

    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(AgentDaoImpl.CREATE_SQL);
            ps.setString(1, StringUtils.trimToNull(agent.getName()));
            ps.setString(2, StringUtils.trimToNull(agent.getAddress()));
            ps.setString(3, StringUtils.trimToNull(agent.getEmail()));
            ps.setString(4, StringUtils.trimToNull(agent.getTelephone()));
            ps.setDate(5, createSQLDate(agent.getCreated()));
            ps.setDate(6, createSQLDate(agent.getModified()));
            return ps;
        }
    }, keyHolder);
    agent.setId(keyHolder.getKey().longValue());
    return keyHolder.getKey().longValue();
}

From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.AgentDaoImpl.java

/**
 * @see org.gbif.portal.dao.AgentDAO#updateOrCreate(org.gbif.portal.model.Agent)
 *///from  ww  w.  j  ava2s .c o  m
public long updateOrCreate(final Agent agent) {
    if (agent.getId() <= 0) {
        return create(agent);
    } else {
        Date now = new Date();
        agent.setModified(now);
        getJdbcTemplate().update(new PreparedStatementCreator() {
            public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
                PreparedStatement ps = conn.prepareStatement(AgentDaoImpl.UPDATE_SQL);
                ps.setString(1, StringUtils.trimToNull(agent.getName()));
                ps.setString(2, StringUtils.trimToNull(agent.getAddress()));
                ps.setString(3, StringUtils.trimToNull(agent.getEmail()));
                ps.setString(4, StringUtils.trimToNull(agent.getTelephone()));
                ps.setDate(5, createSQLDate(agent.getModified()));
                ps.setLong(6, agent.getId());
                return ps;
            }
        });
        return agent.getId();
    }
}

From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.AgentDaoImpl.java

/**
 * @see org.gbif.portal.dao.AgentDAO#associateAgentWithResource(long, long, int)
 *///from w  w w.j a  va 2s.  c  om
public void associateAgentWithResource(final long dataResourceId, final long agentId, final int agentType) {
    if (!isAgentAssociatedWithResource(dataResourceId, agentId, agentType)) {
        getJdbcTemplate().update(new PreparedStatementCreator() {
            public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
                PreparedStatement ps = conn.prepareStatement(AgentDaoImpl.SET_TO_DATA_RESOURCE_SQL);
                ps.setLong(1, dataResourceId);
                ps.setLong(2, agentId);
                ps.setInt(3, agentType);
                return ps;
            }
        });
        log.info("agentDaoImpl.associateAgentWithResource", new String[] { String.valueOf(dataResourceId),
                String.valueOf(agentId), String.valueOf(agentType) });
    } else {
        log.info("agentDaoImpl.associateAgentWithResource.exists", new String[] {
                String.valueOf(dataResourceId), String.valueOf(agentId), String.valueOf(agentType) });
    }
}

From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.AgentDaoImpl.java

/**
 * @see org.gbif.portal.dao.AgentDAO#associateAgentWithProvider(long, long, int)
 *//*from   ww w  .j a v a  2 s  .  c  o m*/
public void associateAgentWithProvider(final long dataProviderId, final long agentId, final int agentType) {
    if (!isAgentAssociatedWithProvider(dataProviderId, agentId, agentType)) {
        getJdbcTemplate().update(new PreparedStatementCreator() {
            public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
                PreparedStatement ps = conn.prepareStatement(AgentDaoImpl.SET_TO_DATA_PROVIDER_SQL);
                ps.setLong(1, dataProviderId);
                ps.setLong(2, agentId);
                ps.setInt(3, agentType);
                return ps;
            }
        });
        log.info("agentDaoImpl.associateAgentWithProvider", new String[] { String.valueOf(dataProviderId),
                String.valueOf(agentId), String.valueOf(agentType) });
    } else {
        log.info("agentDaoImpl.associateAgentWithProvider.exists", new String[] {
                String.valueOf(dataProviderId), String.valueOf(agentId), String.valueOf(agentType) });
    }

}

From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.AgentDaoImpl.java

/**
 * @see org.gbif.portal.dao.AgentDAO#disassociateAgentWithResource(long, long, int)
 *///from   w  w  w.j a  v a  2s . co  m
public void disassociateAgentWithResource(final long dataResourceId, final long agentId, final int agentType) {
    getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(AgentDaoImpl.DELETE_RESOURCE_AGENT);
            ps.setLong(1, dataResourceId);
            ps.setLong(2, agentId);
            ps.setInt(3, agentType);
            return ps;
        }
    });
}

From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.AgentDaoImpl.java

/**
 * @see org.gbif.portal.dao.AgentDAO#disassociateAgentWithProvider(long, long, int)
 *///from   w ww. j av a 2s.  co m
public void disassociateAgentWithProvider(final long dataProviderId, final long agentId, final int agentType) {
    getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(AgentDaoImpl.DELETE_PROVIDER_AGENT);
            ps.setLong(1, dataProviderId);
            ps.setLong(2, agentId);
            ps.setInt(3, agentType);
            return ps;
        }
    });
}

From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.IdentifierRecordDaoImpl.java

public long create(final IdentifierRecord identifierRecord) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(IdentifierRecordDaoImpl.CREATE_SQL);
            ps.setLong(1, identifierRecord.getDataResourceId());
            ps.setLong(2, identifierRecord.getOccurrenceId());
            ps.setInt(3, identifierRecord.getIdentifierType());
            ps.setString(4,//from   w w  w. j a  va  2s. c o m
                    StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                            StringUtils.replace(identifierRecord.getIdentifier(), "\n", " "), "\r", " "), "\t",
                            " ")));
            return ps;
        }
    }, keyHolder);
    identifierRecord.setId(keyHolder.getKey().longValue());
    return keyHolder.getKey().longValue();
}

From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.ImageRecordDaoImpl.java

public long create(final ImageRecord imageRecord) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(ImageRecordDaoImpl.CREATE_SQL);
            ps.setLong(1, imageRecord.getDataResourceId());
            ps.setObject(2, imageRecord.getOccurrenceId());
            ps.setLong(3, imageRecord.getTaxonConceptId());
            ps.setString(4,/*from www.  j a  v  a2 s  .  com*/
                    StringUtils.trimToNull(StringUtils.replace(StringUtils
                            .replace(StringUtils.replace(imageRecord.getRawImageType(), "\n", " "), "\r", " "),
                            "\t", " ")));
            ps.setInt(5, imageRecord.getImageType());
            ps.setString(6, StringUtils.trimToNull(StringUtils.replace(
                    StringUtils.replace(StringUtils.replace(imageRecord.getUrl(), "\n", " "), "\r", " "), "\t",
                    " ")));
            ps.setString(7,
                    StringUtils.trimToNull(StringUtils.replace(StringUtils
                            .replace(StringUtils.replace(imageRecord.getDescription(), "\n", " "), "\r", " "),
                            "\t", " ")));
            ps.setString(8, StringUtils.trimToNull(StringUtils.replace(
                    StringUtils.replace(StringUtils.replace(imageRecord.getRights(), "\n", " "), "\r", " "),
                    "\t", " ")));
            ps.setString(9,
                    StringUtils.trimToNull(StringUtils.replace(
                            StringUtils.replace(StringUtils.replace(imageRecord.getHtmlForDisplay(), "\n", " "),
                                    "\r", " "),
                            "\t", " ")));
            return ps;
        }
    }, keyHolder);
    imageRecord.setId(keyHolder.getKey().longValue());
    return keyHolder.getKey().longValue();
}

From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.LinkRecordDaoImpl.java

public long create(final LinkRecord linkRecord) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(LinkRecordDaoImpl.CREATE_SQL);
            ps.setLong(1, linkRecord.getDataResourceId());
            ps.setLong(2, linkRecord.getOccurrenceId());
            ps.setLong(3, linkRecord.getTaxonConceptId());
            ps.setString(4,//from   w ww .  j a  va  2s.c  om
                    StringUtils.trimToNull(StringUtils.replace(StringUtils
                            .replace(StringUtils.replace(linkRecord.getRawLinkType(), "\n", " "), "\r", " "),
                            "\t", " ")));
            ps.setInt(5, linkRecord.getLinkType());
            ps.setString(6,
                    StringUtils.trimToNull(StringUtils.replace(
                            StringUtils.replace(StringUtils.replace(linkRecord.getUrl(), "\n", " "), "\r", " "),
                            "\t", " ")));
            ps.setString(7,
                    StringUtils.trimToNull(StringUtils.replace(StringUtils
                            .replace(StringUtils.replace(linkRecord.getDescription(), "\n", " "), "\r", " "),
                            "\t", " ")));
            return ps;
        }
    }, keyHolder);
    linkRecord.setId(keyHolder.getKey().longValue());
    return keyHolder.getKey().longValue();
}