List of usage examples for java.sql Types INTEGER
int INTEGER
To view the source code for java.sql Types INTEGER.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type INTEGER
.
From source file:com.liferay.portal.upgrade.util.Table.java
public void setColumn(PreparedStatement ps, int index, Integer type, String value) throws Exception { int t = type.intValue(); int paramIndex = index + 1; if (t == Types.BIGINT) { ps.setLong(paramIndex, GetterUtil.getLong(value)); } else if (t == Types.BOOLEAN) { ps.setBoolean(paramIndex, GetterUtil.getBoolean(value)); } else if ((t == Types.CLOB) || (t == Types.VARCHAR)) { value = StringUtil.replace(value, SAFE_CHARS[1], SAFE_CHARS[0]); ps.setString(paramIndex, value); } else if (t == Types.DOUBLE) { ps.setDouble(paramIndex, GetterUtil.getDouble(value)); } else if (t == Types.FLOAT) { ps.setFloat(paramIndex, GetterUtil.getFloat(value)); } else if (t == Types.INTEGER) { ps.setInt(paramIndex, GetterUtil.getInteger(value)); } else if (t == Types.SMALLINT) { ps.setShort(paramIndex, GetterUtil.getShort(value)); } else if (t == Types.TIMESTAMP) { if (StringPool.NULL.equals(value)) { ps.setTimestamp(paramIndex, null); } else {/*from w w w . j a v a2 s . c om*/ DateFormat df = DateUtil.getISOFormat(); ps.setTimestamp(paramIndex, new Timestamp(df.parse(value).getTime())); } } else { throw new UpgradeException("Upgrade code using unsupported class type " + type); } }
From source file:architecture.user.dao.impl.ExternalJdbcUserDao.java
public void delete(User user) { getExtendedJdbcTemplate().update(getSql("DELETE_GROUP_MEMBERSHIP"), new Object[] { user.getUserId() }, new int[] { Types.INTEGER }); extendedPropertyDao.deleteProperties(userPropertyTableName, userPropertyPrimaryColumnName, user.getUserId());/*from ww w.j a va 2 s . c om*/ getExtendedJdbcTemplate().update(getSql("DELETE_USER_BY_ID"), new Object[] { user.getUserId() }, new int[] { Types.INTEGER }); }
From source file:com.opengamma.masterdb.position.DbPositionMaster.java
/** * Inserts a new document./* w ww . j ava2s . co m*/ * * @param document the document, not null * @return the new document, not null */ @Override protected PositionDocument insert(final PositionDocument document) { ArgumentChecker.notNull(document.getPosition(), "document.position"); ArgumentChecker.notNull(document.getPosition().getQuantity(), "document.position.quantity"); for (final ManageableTrade trade : document.getPosition().getTrades()) { ArgumentChecker.notNull(trade.getQuantity(), "position.trade.quantity"); ArgumentChecker.notNull(trade.getCounterpartyExternalId(), "position.trade.counterpartyexternalid"); ArgumentChecker.notNull(trade.getTradeDate(), "position.trade.tradedate"); } try (Timer.Context context = _insertTimer.time()) { final long positionId = nextId("pos_master_seq"); final long positionOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : positionId); final UniqueId positionUid = createUniqueId(positionOid, positionId); final ManageablePosition position = document.getPosition(); // the arguments for inserting into the position table final DbMapSqlParameterSource docArgs = new DbMapSqlParameterSource() .addValue("position_id", positionId).addValue("position_oid", positionOid) .addTimestamp("ver_from_instant", document.getVersionFromInstant()) .addTimestampNullFuture("ver_to_instant", document.getVersionToInstant()) .addTimestamp("corr_from_instant", document.getCorrectionFromInstant()) .addTimestampNullFuture("corr_to_instant", document.getCorrectionToInstant()) .addValue("quantity", position.getQuantity(), Types.DECIMAL) .addValue("provider_scheme", position.getProviderId() != null ? position.getProviderId().getScheme().getName() : null, Types.VARCHAR) .addValue("provider_value", position.getProviderId() != null ? position.getProviderId().getValue() : null, Types.VARCHAR); // the arguments for inserting into the pos_attribute table final List<DbMapSqlParameterSource> posAttrList = Lists.newArrayList(); for (final Entry<String, String> entry : position.getAttributes().entrySet()) { final long posAttrId = nextId("pos_trade_attr_seq"); final DbMapSqlParameterSource posAttrArgs = new DbMapSqlParameterSource() .addValue("attr_id", posAttrId).addValue("pos_id", positionId) .addValue("pos_oid", positionOid).addValue("key", entry.getKey()) .addValue("value", entry.getValue()); posAttrList.add(posAttrArgs); } // the arguments for inserting into the idkey tables final List<DbMapSqlParameterSource> posAssocList = new ArrayList<DbMapSqlParameterSource>(); final Set<Pair<String, String>> schemeValueSet = Sets.newHashSet(); for (final ExternalId id : position.getSecurityLink().getAllExternalIds()) { final DbMapSqlParameterSource assocArgs = new DbMapSqlParameterSource() .addValue("position_id", positionId).addValue("key_scheme", id.getScheme().getName()) .addValue("key_value", id.getValue()); posAssocList.add(assocArgs); schemeValueSet.add(Pair.of(id.getScheme().getName(), id.getValue())); } // the arguments for inserting into the trade table final List<DbMapSqlParameterSource> tradeList = Lists.newArrayList(); final List<DbMapSqlParameterSource> tradeAssocList = Lists.newArrayList(); final List<DbMapSqlParameterSource> tradeAttributeList = Lists.newArrayList(); for (final ManageableTrade trade : position.getTrades()) { final long tradeId = nextId("pos_master_seq"); final long tradeOid = (trade.getUniqueId() != null ? extractOid(trade.getUniqueId()) : tradeId); final ExternalId counterpartyId = trade.getCounterpartyExternalId(); final DbMapSqlParameterSource tradeArgs = new DbMapSqlParameterSource() .addValue("trade_id", tradeId).addValue("trade_oid", tradeOid) .addValue("position_id", positionId).addValue("position_oid", positionOid) .addValue("quantity", trade.getQuantity()).addDate("trade_date", trade.getTradeDate()) .addTimeAllowNull("trade_time", trade.getTradeTime() != null ? trade.getTradeTime().toLocalTime() : null) .addValue("zone_offset", trade.getTradeTime() != null ? trade.getTradeTime().getOffset().getTotalSeconds() : null, Types.INTEGER) .addValue("cparty_scheme", counterpartyId.getScheme().getName()) .addValue("cparty_value", counterpartyId.getValue()) .addValue("provider_scheme", position.getProviderId() != null ? position.getProviderId().getScheme().getName() : null, Types.VARCHAR) .addValue("provider_value", position.getProviderId() != null ? position.getProviderId().getValue() : null, Types.VARCHAR) .addValue("premium_value", trade.getPremium(), Types.DOUBLE) .addValue("premium_currency", trade.getPremiumCurrency() != null ? trade.getPremiumCurrency().getCode() : null, Types.VARCHAR) .addDateAllowNull("premium_date", trade.getPremiumDate()) .addTimeAllowNull("premium_time", (trade.getPremiumTime() != null ? trade.getPremiumTime().toLocalTime() : null)) .addValue("premium_zone_offset", trade.getPremiumTime() != null ? trade.getPremiumTime().getOffset().getTotalSeconds() : null, Types.INTEGER); tradeList.add(tradeArgs); // trade attributes final Map<String, String> attributes = new HashMap<String, String>(trade.getAttributes()); for (final Entry<String, String> entry : attributes.entrySet()) { final long tradeAttrId = nextId("pos_trade_attr_seq"); final DbMapSqlParameterSource tradeAttributeArgs = new DbMapSqlParameterSource() .addValue("attr_id", tradeAttrId).addValue("trade_id", tradeId) .addValue("trade_oid", tradeOid).addValue("key", entry.getKey()) .addValue("value", entry.getValue()); tradeAttributeList.add(tradeAttributeArgs); } // set the trade uniqueId final UniqueId tradeUid = createUniqueId(tradeOid, tradeId); IdUtils.setInto(trade, tradeUid); trade.setParentPositionId(positionUid); for (final ExternalId id : trade.getSecurityLink().getAllExternalIds()) { final DbMapSqlParameterSource assocArgs = new DbMapSqlParameterSource() .addValue("trade_id", tradeId).addValue("key_scheme", id.getScheme().getName()) .addValue("key_value", id.getValue()); tradeAssocList.add(assocArgs); schemeValueSet.add(Pair.of(id.getScheme().getName(), id.getValue())); } } final List<DbMapSqlParameterSource> idKeyList = new ArrayList<DbMapSqlParameterSource>(); final String sqlSelectIdKey = getElSqlBundle().getSql("SelectIdKey"); for (final Pair<String, String> pair : schemeValueSet) { final DbMapSqlParameterSource idkeyArgs = new DbMapSqlParameterSource() .addValue("key_scheme", pair.getFirst()).addValue("key_value", pair.getSecond()); if (getJdbcTemplate().queryForList(sqlSelectIdKey, idkeyArgs).isEmpty()) { // select avoids creating unecessary id, but id may still not be used final long idKeyId = nextId("pos_idkey_seq"); idkeyArgs.addValue("idkey_id", idKeyId); idKeyList.add(idkeyArgs); } } final String sqlDoc = getElSqlBundle().getSql("Insert", docArgs); final String sqlIdKey = getElSqlBundle().getSql("InsertIdKey"); final String sqlPosition2IdKey = getElSqlBundle().getSql("InsertPosition2IdKey"); final String sqlTrade = getElSqlBundle().getSql("InsertTrade"); final String sqlTrade2IdKey = getElSqlBundle().getSql("InsertTrade2IdKey"); final String sqlPositionAttributes = getElSqlBundle().getSql("InsertPositionAttributes"); final String sqlTradeAttributes = getElSqlBundle().getSql("InsertTradeAttributes"); getJdbcTemplate().update(sqlDoc, docArgs); getJdbcTemplate().batchUpdate(sqlIdKey, idKeyList.toArray(new DbMapSqlParameterSource[idKeyList.size()])); getJdbcTemplate().batchUpdate(sqlPosition2IdKey, posAssocList.toArray(new DbMapSqlParameterSource[posAssocList.size()])); getJdbcTemplate().batchUpdate(sqlTrade, tradeList.toArray(new DbMapSqlParameterSource[tradeList.size()])); getJdbcTemplate().batchUpdate(sqlTrade2IdKey, tradeAssocList.toArray(new DbMapSqlParameterSource[tradeAssocList.size()])); getJdbcTemplate().batchUpdate(sqlPositionAttributes, posAttrList.toArray(new DbMapSqlParameterSource[posAttrList.size()])); getJdbcTemplate().batchUpdate(sqlTradeAttributes, tradeAttributeList.toArray(new DbMapSqlParameterSource[tradeAttributeList.size()])); // set the uniqueId position.setUniqueId(positionUid); document.setUniqueId(positionUid); return document; } }
From source file:org.owasp.proxy.http.dao.JdbcMessageDAO.java
public int saveMessageContent(byte[] messageContent) throws DataAccessException { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(CONTENT, messageContent, Types.LONGVARBINARY); params.addValue(SIZE, messageContent.length, Types.INTEGER); KeyHolder key = new GeneratedKeyHolder(); getNamedParameterJdbcTemplate().update(INSERT_CONTENT, params, key); return key.getKey().intValue(); }
From source file:com.aw.core.dao.DAOSql.java
protected void dbmsOutputPrint(Connection conn, StringBuffer buf) throws java.sql.SQLException { String getLineSql = "begin dbms_output.get_line(?,?); end;"; CallableStatement stmt = conn.prepareCall(getLineSql); boolean hasMore = true; stmt.registerOutParameter(1, Types.VARCHAR); stmt.registerOutParameter(2, Types.INTEGER); while (hasMore) { boolean status = stmt.execute(); hasMore = (stmt.getInt(2) == 0); if (hasMore) { buf.append(stmt.getString(1)).append("\n"); }/* ww w . j a v a 2 s .c o m*/ } stmt.close(); }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableContextUtil.java
public static String getPartitionSizeValidationError(int colType, String column, String partitionSize) { switch (colType) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: try {/*from w w w. j a v a 2 s.c om*/ int intVal = Integer.parseInt(partitionSize); if (intVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.BIGINT: // TIME, DATE, and TIMESTAMP are represented as long (epoch) case Types.TIME: case Types.DATE: case Types.TIMESTAMP: try { long longVal = Long.parseLong(partitionSize); if (longVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.FLOAT: case Types.REAL: try { float floatVal = Float.parseFloat(partitionSize); if (floatVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.DOUBLE: try { double doubleVal = Double.parseDouble(partitionSize); if (doubleVal <= 0) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; case Types.NUMERIC: case Types.DECIMAL: try { BigDecimal decimalValue = new BigDecimal(partitionSize); if (decimalValue.signum() < 1) { return createPartitionSizeValidationError(column, partitionSize, colType, GENERIC_PARTITION_SIZE_GT_ZERO_MSG); } } catch (NumberFormatException e) { return createPartitionSizeValidationError(column, partitionSize, colType, e.getMessage()); } break; } return null; }
From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java
@Override public int addDevice(final Device device) { int uid = -1; Connection conn = null;//w ww .j a v a2s. com CallableStatement stmt = null; ResultSet rs = null; try { conn = _dataSource.getConnection(); stmt = conn.prepareCall("{call SP_REGISTERDEVICE (?,?,?,?)}"); stmt.registerOutParameter(1, Types.INTEGER); stmt.setInt(2, device.getUserUid()); stmt.setString(3, device.getDeviceId()); stmt.setString(4, device.getDeviceType()); stmt.execute(); uid = stmt.getInt(1); } catch (SQLException e) { LOG.error(Throwables.getStackTraceAsString(e)); } finally { DbUtils.closeQuietly(conn, stmt, rs); } if (LOG.isDebugEnabled()) { LOG.debug("DEVICE [method:{} result:{}]", new Object[] { "edit", uid }); } return uid; }
From source file:com.zimbra.cs.db.DbMailItem.java
public static String copy(MailItem item, int id, String uuid, Folder folder, int indexId, int parentId, String locator, String metadata, boolean fromDumpster) throws ServiceException { Mailbox mbox = item.getMailbox();/*from ww w .ja va2 s. c o m*/ String prevFolders = null; if (id <= 0 || folder == null || parentId == 0) { throw ServiceException.FAILURE("invalid data for DB item copy", null); } checkNamingConstraint(mbox, folder.getId(), item.getName(), id); DbConnection conn = mbox.getOperationConnection(); PreparedStatement stmt = null; try { String srcTable = getMailItemTableName(mbox, fromDumpster); String destTable = getMailItemTableName(mbox); String mailbox_id = DebugConfig.disableMailboxGroups ? "" : "mailbox_id, "; stmt = conn.prepareStatement("INSERT INTO " + destTable + "(" + mailbox_id + " id, type, parent_id, folder_id, prev_folders, index_id, imap_id, date, size, locator, blob_digest," + " unread, flags, tag_names, sender, subject, name, metadata, mod_metadata, change_date, mod_content, uuid) " + "SELECT " + MAILBOX_ID_VALUE + " ?, type, ?, ?, ?, ?, ?, date, size, ?, blob_digest, unread," + " flags, tag_names, sender, subject, name, ?, ?, ?, ?, ? FROM " + srcTable + " WHERE " + IN_THIS_MAILBOX_AND + "id = ?"); int pos = 1; pos = setMailboxId(stmt, mbox, pos); stmt.setInt(pos++, id); // ID if (parentId <= 0) { stmt.setNull(pos++, Types.INTEGER); // PARENT_ID null for messages in virtual convs } else { stmt.setInt(pos++, parentId); // or, PARENT_ID specified by caller } stmt.setInt(pos++, folder.getId()); // FOLDER_ID int modseq = mbox.getOperationChangeID(); prevFolders = findPrevFolders(item, modseq); stmt.setString(pos++, prevFolders); if (indexId == MailItem.IndexStatus.NO.id()) { stmt.setNull(pos++, Types.INTEGER); } else { stmt.setInt(pos++, indexId); } stmt.setInt(pos++, id); // IMAP_ID is initially the same as ID stmt.setString(pos++, locator); stmt.setString(pos++, checkMetadataLength(metadata)); // METADATA stmt.setInt(pos++, modseq); // MOD_METADATA stmt.setInt(pos++, mbox.getOperationTimestamp()); // CHANGE_DATE stmt.setInt(pos++, mbox.getOperationChangeID()); // MOD_CONTENT stmt.setString(pos++, uuid); // UUID pos = setMailboxId(stmt, mbox, pos); stmt.setInt(pos++, item.getId()); int num = stmt.executeUpdate(); if (num != 1) { throw ServiceException.FAILURE("failed to create object", null); } DbTag.storeTagReferences(mbox, id, item.getType(), item.getInternalFlagBitmask(), item.isUnread()); DbTag.storeTagReferences(mbox, id, item.getType(), item.getTags()); } catch (SQLException e) { // catch item_id uniqueness constraint violation and return failure if (Db.errorMatches(e, Db.Error.DUPLICATE_ROW)) { throw MailServiceException.ALREADY_EXISTS(id, e); } else { throw ServiceException.FAILURE("copying " + item.getType() + ": " + item.getId(), e); } } finally { DbPool.closeStatement(stmt); } return prevFolders; }
From source file:dao.MetricsDAO.java
public static String updateMetricValues(int id, Map<String, String[]> params) { String message = "Internal error"; if (params == null || params.size() == 0) { return "Empty post body"; }/*from w ww . j av a 2 s . c o m*/ boolean needAnd = false; String setClause = ""; String description = ""; String[] descArray = null; List<Object> args = new ArrayList<Object>(); List<Integer> argTypes = new ArrayList<Integer>(); if (params.containsKey(MetricRowMapper.METRIC_DESCRIPTION_COLUMN)) { descArray = params.get(MetricRowMapper.METRIC_DESCRIPTION_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_DESCRIPTION)) { descArray = params.get(MetricRowMapper.METRIC_MODULE_DESCRIPTION); } if (descArray != null && descArray.length > 0) { description = descArray[0]; setClause += MetricRowMapper.METRIC_DESCRIPTION_COLUMN + " = ? "; needAnd = true; args.add(description); argTypes.add(Types.VARCHAR); } String dashboard = ""; String[] dashboardArray = null; if (params.containsKey(MetricRowMapper.METRIC_DASHBOARD_NAME_COLUMN)) { dashboardArray = params.get(MetricRowMapper.METRIC_DASHBOARD_NAME_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_DASHBOARD_NAME)) { dashboardArray = params.get(MetricRowMapper.METRIC_MODULE_DASHBOARD_NAME); } if (dashboardArray != null && dashboardArray.length > 0) { dashboard = dashboardArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_DASHBOARD_NAME_COLUMN + " = ? "; needAnd = true; args.add(dashboard); argTypes.add(Types.VARCHAR); } String type = ""; String[] typeArray = null; if (params.containsKey(MetricRowMapper.METRIC_REF_ID_TYPE_COLUMN)) { typeArray = params.get(MetricRowMapper.METRIC_REF_ID_TYPE_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_REF_ID_TYPE)) { typeArray = params.get(MetricRowMapper.METRIC_MODULE_REF_ID_TYPE); } if (typeArray != null && typeArray.length > 0) { type = typeArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_REF_ID_TYPE_COLUMN + " = ? "; needAnd = true; args.add(type); argTypes.add(Types.VARCHAR); } String grain = ""; String[] grainArray = null; if (params.containsKey(MetricRowMapper.METRIC_GRAIN_COLUMN)) { grainArray = params.get(MetricRowMapper.METRIC_GRAIN_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_GRAIN)) { grainArray = params.get(MetricRowMapper.METRIC_MODULE_GRAIN); } if (grainArray != null && grainArray.length > 0) { grain = grainArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_GRAIN_COLUMN + " = ? "; needAnd = true; args.add(grain); argTypes.add(Types.VARCHAR); } String formula = ""; String[] formulaArray = null; if (params.containsKey(MetricRowMapper.METRIC_FORMULA_COLUMN)) { formulaArray = params.get(MetricRowMapper.METRIC_FORMULA_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_FORMULA)) { formulaArray = params.get(MetricRowMapper.METRIC_MODULE_FORMULA); } if (formulaArray != null && formulaArray.length > 0) { formula = formulaArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_FORMULA_COLUMN + " = ? "; needAnd = true; args.add(formula); argTypes.add(Types.VARCHAR); } String displayFactorString = ""; Double displayFactor = 0.0; String[] displayFactorArray = null; if (params.containsKey(MetricRowMapper.METRIC_DISPLAY_FACTOR_COLUMN)) { displayFactorArray = params.get(MetricRowMapper.METRIC_DISPLAY_FACTOR_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_DISPLAY_FACTOR)) { displayFactorArray = params.get(MetricRowMapper.METRIC_MODULE_DISPLAY_FACTOR); } if (displayFactorArray != null && displayFactorArray.length > 0) { displayFactorString = displayFactorArray[0]; try { displayFactor = Double.parseDouble(displayFactorString); if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_DISPLAY_FACTOR_COLUMN + " = ? "; needAnd = true; args.add(displayFactor); argTypes.add(Types.DECIMAL); } catch (NumberFormatException e) { Logger.error("MetricDAO updateMetricValues wrong page parameter. Error message: " + e.getMessage()); displayFactor = 0.0; } } String displayFactorSym = ""; String[] factorSymArray = null; if (params.containsKey(MetricRowMapper.METRIC_DISPLAY_FACTOR_SYM_COLUMN)) { factorSymArray = params.get(MetricRowMapper.METRIC_DISPLAY_FACTOR_SYM_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_DISPLAY_FACTOR_SYM)) { factorSymArray = params.get(MetricRowMapper.METRIC_MODULE_DISPLAY_FACTOR_SYM); } if (factorSymArray != null && factorSymArray.length > 0) { displayFactorSym = factorSymArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_DISPLAY_FACTOR_SYM_COLUMN + " = ? "; needAnd = true; args.add(displayFactorSym); argTypes.add(Types.VARCHAR); } String groupSkString = ""; Integer groupSk = 0; String[] groupSkArray = null; if (params.containsKey(MetricRowMapper.METRIC_SUB_CATEGORY_COLUMN)) { groupSkArray = params.get(MetricRowMapper.METRIC_SUB_CATEGORY_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_SUB_CATEGORY)) { groupSkArray = params.get(MetricRowMapper.METRIC_MODULE_SUB_CATEGORY); } if (groupSkArray != null && groupSkArray.length > 0) { groupSkString = groupSkArray[0]; try { groupSk = Integer.parseInt(groupSkString); if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_SUB_CATEGORY_COLUMN + " = ? "; needAnd = true; args.add(groupSk); argTypes.add(Types.INTEGER); } catch (NumberFormatException e) { Logger.error("MetricDAO updateMetricValues wrong page parameter. Error message: " + e.getMessage()); groupSk = 0; } } String metricSource = ""; String[] metricSourceArray = null; if (params.containsKey(MetricRowMapper.METRIC_SOURCE_COLUMN)) { metricSourceArray = params.get(MetricRowMapper.METRIC_SOURCE_COLUMN); } else if (params.containsKey(MetricRowMapper.METRIC_MODULE_SOURCE)) { metricSourceArray = params.get(MetricRowMapper.METRIC_MODULE_SOURCE); } if (metricSourceArray != null && metricSourceArray.length > 0) { metricSource = metricSourceArray[0]; if (needAnd) { setClause += ", "; } setClause += MetricRowMapper.METRIC_SOURCE_COLUMN + " = ? "; needAnd = true; args.add(metricSource); argTypes.add(Types.VARCHAR); } if (StringUtils.isNotBlank(setClause)) { args.add(id); argTypes.add(Types.SMALLINT); int row = getJdbcTemplate().update(UPDATE_METRIC.replace("$SET_CLAUSE", setClause), args.toArray(), Ints.toArray(argTypes)); if (row > 0) { message = ""; } } else { message = "Wrong post body"; } return message; }
From source file:org.owasp.proxy.http.dao.JdbcMessageDAO.java
public int saveMessageContent(InputStream messageContent) throws DataAccessException { CountingInputStream cis = new CountingInputStream(messageContent); MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(CONTENT, cis, Types.LONGVARBINARY); params.addValue(SIZE, 0, Types.INTEGER); KeyHolder key = new GeneratedKeyHolder(); getNamedParameterJdbcTemplate().update(INSERT_CONTENT, params, key); int id = key.getKey().intValue(); params = new MapSqlParameterSource(); params.addValue(SIZE, cis.getCount(), Types.INTEGER); getNamedParameterJdbcTemplate().update(UPDATE_CONTENT_SIZE, params); return id;/*from www .jav a2 s . c o m*/ }