Example usage for org.springframework.jdbc.core PreparedStatementCreatorFactory newPreparedStatementCreator

List of usage examples for org.springframework.jdbc.core PreparedStatementCreatorFactory newPreparedStatementCreator

Introduction

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

Prototype

public PreparedStatementCreator newPreparedStatementCreator(@Nullable Object[] params) 

Source Link

Document

Return a new PreparedStatementCreator for the given parameters.

Usage

From source file:org.easyrec.store.dao.core.impl.AuthenticationDAOMysqlImpl.java

public int insertDomainURLForTenant(Integer tenantId, String domain) {

    if (tenantId == null) {
        throw new IllegalArgumentException("tenantId must not be 'null'!");
    }/*  ww w . jav a  2s  .  c om*/
    if (domain == null) {
        throw new IllegalArgumentException("domain must not be 'null'!");
    }
    if (domain.length() == 0) {
        throw new IllegalArgumentException("domain must not be an empty String!");
    }

    StringBuilder sqlString = new StringBuilder("INSERT INTO ");
    sqlString.append(DEFAULT_TABLE_NAME);
    sqlString.append(" SET ");
    sqlString.append(DEFAULT_TENANT_ID_COLUMN_NAME);
    sqlString.append(" =?, ");
    sqlString.append(DEFAULT_DOMAIN_URL_COLUMN_NAME);
    sqlString.append("=?");

    Object[] args = { tenantId, domain };

    int[] argTypes = { Types.INTEGER, Types.VARCHAR };

    PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(sqlString.toString(),
            argTypes);

    int rowsAffected = getJdbcTemplate().update(factory.newPreparedStatementCreator(args));
    return rowsAffected;
}

From source file:org.easyrec.store.dao.core.impl.ItemAssocDAOMysqlImpl.java

@Override
public int insertItemAssoc(ItemAssocVO<Integer, Integer> itemAssoc) {
    // validate input parameters
    if (itemAssoc == null) {
        throw new IllegalArgumentException("missing 'itemAssoc'");
    }/*www.j a v a 2s . c o  m*/

    // validate unique key
    validateUniqueKey(itemAssoc);
    validateAssocValue(itemAssoc);
    validateViewType(itemAssoc);

    if (logger.isDebugEnabled()) {
        logger.debug("inserting 'itemAssoc': " + itemAssoc);
    }

    // @HINT: maybe use UniqueIdService later (instead of auto_imcrement)
    StringBuilder sqlString = new StringBuilder("INSERT INTO ");
    sqlString.append(DEFAULT_TABLE_NAME);
    sqlString.append(" (");
    sqlString.append(DEFAULT_TENANT_COLUMN_NAME);
    sqlString.append(", ");
    sqlString.append(DEFAULT_ITEM_FROM_COLUMN_NAME);
    sqlString.append(", ");
    sqlString.append(DEFAULT_ITEM_FROM_TYPE_COLUMN_NAME);
    sqlString.append(", ");
    sqlString.append(DEFAULT_ASSOC_TYPE_COLUMN_NAME);
    sqlString.append(", ");
    sqlString.append(DEFAULT_ASSOC_VALUE_COLUMN_NAME);
    sqlString.append(", ");
    sqlString.append(DEFAULT_ITEM_TO_COLUMN_NAME);
    sqlString.append(", ");
    sqlString.append(DEFAULT_ITEM_TO_TYPE_COLUMN_NAME);
    sqlString.append(", ");
    sqlString.append(DEFAULT_SOURCE_TYPE_COLUMN_NAME);
    sqlString.append(", ");
    sqlString.append(DEFAULT_SOURCE_INFO_COLUMN_NAME);
    sqlString.append(", ");
    sqlString.append(DEFAULT_VIEW_TYPE_COLUMN_NAME);
    sqlString.append(", ");
    if (itemAssoc.isActive() != null) {
        sqlString.append(DEFAULT_ACTIVE_COLUMN_NAME);
        sqlString.append(", ");
    }
    sqlString.append(DEFAULT_CHANGE_DATE_COLUMN_NAME);
    if (itemAssoc.getChangeDate() == null) {
        itemAssoc.setChangeDate(new Date(System.currentTimeMillis()));
    }
    if (itemAssoc.isActive() != null) {
        sqlString.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    } else {
        sqlString.append(") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    }

    Object[] args;
    int[] argTypes;
    if (itemAssoc.isActive() != null) {
        args = new Object[] { itemAssoc.getTenant(), itemAssoc.getItemFrom().getItem(),
                itemAssoc.getItemFrom().getType(), itemAssoc.getAssocType(), itemAssoc.getAssocValue(),
                itemAssoc.getItemTo().getItem(), itemAssoc.getItemTo().getType(), itemAssoc.getSourceType(),
                itemAssoc.getSourceInfo(), itemAssoc.getViewType(), itemAssoc.isActive(),
                itemAssoc.getChangeDate() };
        argTypes = new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE,
                Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.BOOLEAN,
                Types.TIMESTAMP };
    } else {
        args = new Object[] { itemAssoc.getTenant(), itemAssoc.getItemFrom().getItem(),
                itemAssoc.getItemFrom().getType(), itemAssoc.getAssocType(), itemAssoc.getAssocValue(),
                itemAssoc.getItemTo().getItem(), itemAssoc.getItemTo().getType(), itemAssoc.getSourceType(),
                itemAssoc.getSourceInfo(), itemAssoc.getViewType(), itemAssoc.getChangeDate() };
        argTypes = new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE,
                Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP };
    }
    PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(sqlString.toString(),
            argTypes);
    factory.setReturnGeneratedKeys(true);
    KeyHolder keyHolder = new GeneratedKeyHolder();

    int rowsAffected = getJdbcTemplate().update(factory.newPreparedStatementCreator(args), keyHolder);

    // retrieve auto increment id, and set to VO
    itemAssoc.setId(keyHolder.getKey().longValue());

    return rowsAffected;
}

From source file:org.easyrec.store.dao.core.impl.ProfileDAOMysqlImpl.java

public int storeProfile(Integer tenantId, Integer itemId, Integer itemTypeId, String profileXML) {

    if (tenantId == null) {
        throw new IllegalArgumentException("tenantId must not be 'null'!");
    }//from   w  w w . j a v a  2s . com
    if (itemId == null) {
        throw new IllegalArgumentException("itemId must not be 'null'!");
    }
    if (itemTypeId == null) {
        throw new IllegalArgumentException("itemTypeId must not be 'null'");
    }

    String itemType = itemTypeDAO.getTypeById(tenantId, itemTypeId);

    String mappedItemId = idMappingDAO.lookup(itemId);
    if (mappedItemId == null)
        throw new IllegalArgumentException("itemId has no string equivalent");

    Object[] args = { tenantId, mappedItemId, itemType, profileXML, profileXML };

    int[] argTypes = { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.BLOB };

    PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(STORE_PROFILE_QUERY,
            argTypes);

    int rowsAffected = getJdbcTemplate().update(factory.newPreparedStatementCreator(args));
    return rowsAffected;
}

From source file:org.easyrec.store.dao.core.impl.ProfileDAOMysqlImpl.java

@Override
public boolean deleteProfile(Integer tenantId, Integer itemId, Integer itemTypeId) {

    if (tenantId == null) {
        throw new IllegalArgumentException("tenantId must not be 'null'!");
    }/*from  w w  w  .  j a v a2 s.c  om*/
    if (itemId == null) {
        throw new IllegalArgumentException("itemId must not be 'null'!");
    }
    if (itemTypeId == null) {
        throw new IllegalArgumentException("itemTypeId must not be 'null'");
    }

    String itemType = itemTypeDAO.getTypeById(tenantId, itemTypeId);

    String mappedItemId = idMappingDAO.lookup(itemId);
    if (mappedItemId == null)
        throw new IllegalArgumentException("itemId has no string equivalent");

    Object[] args = { tenantId, mappedItemId, itemType, null, null };

    int[] argTypes = { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.BLOB };

    PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(STORE_PROFILE_QUERY,
            argTypes);

    int rowsAffected = getJdbcTemplate().update(factory.newPreparedStatementCreator(args));
    return (rowsAffected > 0);
}