List of usage examples for org.apache.commons.lang StringUtils repeat
public static String repeat(String str, String separator, int repeat)
Repeat a String repeat
times to form a new String, with a String separator injected each time.
From source file:com.dilipkumarg.qb.InsertQueryBuilder.java
private String buildPlaceHolders(int size) { return StringUtils.repeat(PLACE_HOLDER, SEPARATOR, size); }
From source file:io.cloudslang.engine.queue.repositories.ExecutionQueueRepositoryImpl.java
@Override public List<ExecutionMessage> pollRecovery(String workerId, int maxSize, ExecStatus... statuses) { pollForRecoveryJDBCTemplate.setMaxRows(maxSize); pollForRecoveryJDBCTemplate.setFetchSize(maxSize); // prepare the sql statement String sqlStatPrvTable = QUERY_WORKER_RECOVERY_SQL.replaceAll(":status", StringUtils.repeat("?", ",", statuses.length)); String sqlStatActiveTable = QUERY_WORKER_RECOVERY_SQL.replaceAll(":status", StringUtils.repeat("?", ",", statuses.length)); // prepare the argument java.lang.Object[] values;// w ww.j a v a 2 s.c o m values = new Object[statuses.length + 1]; values[0] = workerId; int i = 1; for (ExecStatus status : statuses) { values[i++] = status.getNumber(); } List<ExecutionMessage> resultPrvTable = doSelectWithTemplate(pollForRecoveryJDBCTemplate, sqlStatPrvTable, new ExecutionMessageRowMapper(), values); List<ExecutionMessage> resultActiveTable = doSelectWithTemplate(pollForRecoveryJDBCTemplate, sqlStatActiveTable, new ExecutionMessageRowMapper(), values); Map<Long, ExecutionMessage> resultAsMap = new HashMap<>(); for (ExecutionMessage executionMessage : resultPrvTable) { //remove duplications resultAsMap.put(executionMessage.getExecStateId(), executionMessage); } for (ExecutionMessage executionMessage : resultActiveTable) { //remove duplications resultAsMap.put(executionMessage.getExecStateId(), executionMessage); } return new ArrayList<>(resultAsMap.values()); }
From source file:io.cloudslang.engine.queue.repositories.ExecutionQueueRepositoryImpl.java
@Override public List<ExecutionMessage> poll(String workerId, int maxSize, ExecStatus... statuses) { pollJDBCTemplate.setMaxRows(maxSize); pollJDBCTemplate.setFetchSize(maxSize); // prepare the sql statement String sqlStat = QUERY_WORKER_SQL.replaceAll(":status", StringUtils.repeat("?", ",", statuses.length)); // prepare the argument java.lang.Object[] values;//from w w w. j a v a2 s .com values = new Object[statuses.length + 1]; values[0] = workerId; int i = 1; for (ExecStatus status : statuses) { values[i++] = status.getNumber(); } return doSelectWithTemplate(pollJDBCTemplate, sqlStat, new ExecutionMessageRowMapper(), values); }
From source file:io.cloudslang.engine.queue.repositories.ExecutionQueueRepositoryImpl.java
@Override public void deleteFinishedSteps(Set<Long> ids) { if (ids == null || ids.size() == 0) return;/*from w ww .j a v a2 s .co m*/ // Access STATES first and then QUEUES - same order as ExecutionQueueService#enqueue (prevents deadlocks on MSSQL) String query = QUERY_DELETE_FINISHED_STEPS_FROM_STATES.replaceAll(":ids", StringUtils.repeat("?", ",", ids.size())); Object[] args = ids.toArray(new Object[ids.size()]); logSQL(query, args); int deletedRows = deleteFinishedStepsJDBCTemplate.update(query, args); //MUST NOT set here maxRows!!!! It must delete all without limit!!! if (logger.isDebugEnabled()) { logger.debug("Deleted " + deletedRows + " rows of finished steps from OO_EXECUTION_STATES table."); } query = QUERY_DELETE_FINISHED_STEPS_FROM_QUEUES.replaceAll(":ids", StringUtils.repeat("?", ",", ids.size())); logSQL(query, args); deletedRows = deleteFinishedStepsJDBCTemplate.update(query, args); //MUST NOT set here maxRows!!!! It must delete all without limit!!! if (logger.isDebugEnabled()) { logger.debug("Deleted " + deletedRows + " rows of finished steps from OO_EXECUTION_QUEUES table."); } }
From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.ideainstance.IdeaInstanceDAO.java
private List<Integer> loadIdeaInstanceIdeas(String code, Collection<Integer> ideaStatus, Connection conn) { List<Integer> ideaidList = new ArrayList<Integer>(); PreparedStatement stat = null; ResultSet res = null;// ww w .ja v a 2s .co m try { String query = LOAD_IDEAINSTANCE_IDEAS; if (null != ideaStatus && !ideaStatus.isEmpty()) { query = query + " AND status IN (" + StringUtils.repeat("?", ", ", ideaStatus.size()) + ") "; } stat = conn.prepareStatement(query); int index = 1; stat.setString(index++, code); if (null != ideaStatus && !ideaStatus.isEmpty()) { Iterator<Integer> it = ideaStatus.iterator(); while (it.hasNext()) { stat.setInt(index++, it.next()); } } res = stat.executeQuery(); while (res.next()) { ideaidList.add(res.getInt("id")); } } catch (Throwable t) { _logger.error("Error loading ideainstance related ideas {}", code, t); throw new RuntimeException("Error loading ideainstance related ideas", t); } finally { closeDaoResources(res, stat, null); } return ideaidList; }
From source file:io.cloudslang.engine.queue.repositories.ExecutionQueueRepositoryImpl.java
@Override public Map<Long, Payload> findPayloadByExecutionIds(Long... ids) { String qMarks = StringUtils.repeat("?", ",", ids.length); String sqlStat = QUERY_PAYLOAD_BY_EXECUTION_IDS.replace(":IDS", qMarks); final Map<Long, Payload> result = new HashMap<>(); findPayloadByExecutionIdsJDBCTemplate.query(sqlStat, ids, new RowCallbackHandler() { @Override// w ww.j av a 2 s .c om public void processRow(ResultSet resultSet) throws SQLException { result.put(resultSet.getLong(1), new Payload(resultSet.getBytes("payload"))); } }); return result; }
From source file:io.cloudslang.engine.queue.repositories.ExecutionQueueRepositoryImpl.java
@Override public List<ExecutionMessage> findByStatuses(int maxSize, ExecStatus... statuses) { findByStatusesJDBCTemplate.setMaxRows(maxSize); findByStatusesJDBCTemplate.setFetchSize(maxSize); // prepare the sql statement String sqlStat = QUERY_MESSAGES_BY_STATUSES.replaceAll(":status", StringUtils.repeat("?", ",", statuses.length)); // set ? according to the number of parameters Object[] values = new Object[statuses.length]; int i = 0;//from w w w .jav a2s.c o m for (ExecStatus status : statuses) { values[i++] = status.getNumber(); } try { return doSelectWithTemplate(findByStatusesJDBCTemplate, sqlStat, new ExecutionMessageWithoutPayloadRowMapper(), values); } catch (RuntimeException ex) { logger.error(sqlStat, ex); throw ex; } }
From source file:net.ymate.platform.persistence.jdbc.dialect.AbstractDialect.java
public String buildInsertSQL(Class<? extends IEntity> entityClass, String prefix, IShardingable shardingable, Fields fields) {//www . ja v a 2s . co m EntityMeta _meta = EntityMeta.createAndGet(entityClass); ExpressionUtils _exp = ExpressionUtils.bind("INSERT INTO ${table_name} (${fields}) VALUES (${values})") .set("table_name", buildTableName(prefix, _meta, shardingable)); // Fields _fields = Fields.create(); if (fields == null || fields.fields().isEmpty()) { _fields.add(_meta.getPropertyNames()); } else { _fields.add(fields); __doValidProperty(_meta, _fields, false); } return _exp.set("fields", __doGenerateFieldsFormatStr(_fields, null, null)) .set("values", StringUtils.repeat("?", ", ", _fields.fields().size())).getResult(); }
From source file:net.ymate.platform.persistence.jdbc.query.Cond.java
public Cond in(String field, Params params) { __condSB.append(field).append(" IN (").append(StringUtils.repeat("?", ", ", params.params().size())) .append(")"); __params.add(params);/*from ww w.jav a2s. co m*/ return this; }
From source file:net.ymate.platform.persistence.jdbc.query.Insert.java
@Override public String toString() { return "INSERT INTO ".concat(__tableName).concat(" (").concat(StringUtils.join(__fields.fields(), ", ")) .concat(") VALUES (").concat(StringUtils.repeat("?", ", ", __params.params().size())).concat(")"); }