@Override public int insertAction(ActionVO<Integer, String> typedAction, boolean useDateFromVO) { Integer tenantId = typedAction.getTenant(); if (tenantId == null) { throw new IllegalArgumentException("tenant not specified, can not retrieve type mapping without tenant"); } return actionDAO.insertAction(typeMappingService.convertTypedActionVO(tenantId, typedAction), useDateFromVO); }
public void importActionsFromCSV(String fileName, ActionVO<Integer, String> defaults) { actionService.importActionsFromCSV(fileName, typeMappingService.convertTypedActionVO(defaults.getTenant(), defaults)); }
private void validateNonEmptyFields(ActionVO<Integer, Integer> action, boolean useDateFromVO) { if (action.getTenant() == null) { throw new IllegalArgumentException( "missing constraints, unique key (tenantId, itemTypeId, actionTypeId, actionTime) must be set, missing 'tenantId'"); } if (action.getItem() == null) { throw new IllegalArgumentException( "missing constraints, unique key (tenantId, itemTypeId, actionTypeId, actionTime) must be set, missing 'item'"); } if (action.getItem().getType() == null) { throw new IllegalArgumentException( "missing constraints, unique key (tenantId, itemTypeId, actionTypeId, actionTime) must be set, missing 'itemTypeId'"); } if (action.getActionType() == null) { throw new IllegalArgumentException( "missing constraints, unique key (tenantId, itemTypeId, actionTypeId, actionTime) must be set, missing 'actionTypeId'"); } // in case of automatically generated 'actionTime' on database level leave out check for null if (useDateFromVO && action.getActionTime() == null) { throw new IllegalArgumentException( "missing constraints, unique key (tenantId, itemTypeId, actionTypeId, actionTime) must be set, missing 'actionTime'"); } }
private int insertActionsBulk(final int bulkSize, final List<ActionVO<Integer, Integer>> thisBulk, int currentResult) { List<Object> args = new ArrayList<Object>(thisBulk.size() * ARGT_INSERT.length); StringBuilder query = new StringBuilder(QUERY_INSERT); TIntArrayList argt = new TIntArrayList(bulkSize * ARGT_INSERT.length); //noinspection ForLoopReplaceableByForEach for (int i = 0; i < thisBulk.size(); i++) { query.append(QUERY_INSERT_VALUE); argt.addAll(ARGT_INSERT); } query.replace(query.length() - 2, query.length(), ""); for (ActionVO<Integer, Integer> action : thisBulk) { args.add(action.getTenant()); args.add(action.getUser()); args.add(action.getItem().getItem()); args.add(action.getItem().getType()); args.add(action.getRatingValue()); args.add(action.getActionTime()); } try { currentResult += getJdbcTemplate().update(query.toString(), args.toArray(), argt.toArray()); } catch (Exception e) { e.printStackTrace(System.err); } return currentResult; }
public int insertAction(ActionVO<Integer, Integer> action) { String query = QUERY_INSERT + QUERY_INSERT_VALUE; query = query.substring(0, query.length() - 2); Object[] args = new Object[]{action.getTenant(), action.getUser(), action.getItem().getItem(), action.getItem().getType(), action.getRatingValue(), action.getActionTime()}; return getJdbcTemplate().update(query, args, ARGT_INSERT); }
public int generateActions(int tenantId, TIntSet itemTypeIds, int actionTypeId, Date since) { Preconditions.checkNotNull(itemTypeIds); Preconditions.checkArgument(itemTypeIds.size() > 0, "at least one itemtype must be given"); if (since == null) since = getNewestActionDate(tenantId, itemTypeIds); if (isOnSameDataSourceAsEasyrec()) { Object[] args = new Object[]{tenantId, actionTypeId, since}; String query = QUERY_GENERATE.replace("@@@", generateItemTypeInClause(itemTypeIds)); return getJdbcTemplate().update(query, args, ARGT_GENERATE); } // when not on same datasource the tenantId is ignored and all actions are copied Iterator<ActionVO<Integer, Integer>> actions = actionDAO .getActionIterator(5000, new TimeConstraintVO(since, null)); int result = 0; while (actions.hasNext()) { ActionVO<Integer, Integer> actionVO = actions.next(); if (actionVO.getTenant() != tenantId) continue; if (actionVO.getActionType() != actionTypeId) continue; if (!itemTypeIds.contains(actionVO.getItem().getType())) continue; result += insertAction(actionVO); } return result; }
if (action.getTenant() == null) { AutoImportUtils .logSkippedLine(logger, lineCounter, line, "no value for field 'tenantId' is set");
public int generateActions(final Integer tenantId, final Date since) { if (isOnSameDataSourceAsEasyrec()) { String query; int[] argt; Object[] args; if (since == null) { query = QUERY_GENERATE; argt = ARGT_GENERATE; args = new Object[]{tenantId}; } else { query = QUERY_GENERATE_SINCE; argt = ARGT_GENERATE_SINCE; args = new Object[]{tenantId, since}; } return getJdbcTemplate().update(query, args, argt); } Iterator<ActionVO<Integer, Integer>> actions = actionDAO .getActionIterator(5000, new TimeConstraintVO(since, null)); int result = 0; while (actions.hasNext()) { ActionVO<Integer, Integer> actionVO = actions.next(); Object[] args = new Object[]{actionVO.getTenant(), actionVO.getUser(), actionVO.getItem().getItem(), actionVO.getItem().getType(), actionVO.getActionType(), actionVO.getRatingValue(), actionVO.getActionTime()}; result += getJdbcTemplate().update(QUERY_INSERT, args, ARGT_INSERT); } return result; }
@Override public int insertAction(ActionVO<Integer, Integer> action, boolean useDateFromVO) { if (logger.isTraceEnabled()) { logger.trace("inserting action=" + action); } // validate non-empty fields (NOT NULL) validateNonEmptyFields(action, useDateFromVO); Object[] args = {action.getTenant(), action.getUser(), action.getSessionId(), action.getIp(), ((action.getItem() != null) ? action.getItem().getItem() : null), ((action.getItem() != null) ? action.getItem().getType() : null), action.getActionType(), action.getRatingValue(), action.getSearchSucceeded(), action.getNumberOfFoundItems(), action.getDescription(), ((useDateFromVO && action.getActionTime() != null) ? action.getActionTime() : new Date(System.currentTimeMillis()))}; KeyHolder keyHolder = new GeneratedKeyHolder(); int rowsAffected = getJdbcTemplate().update(PS_INSERT_ACTION.newPreparedStatementCreator(args), keyHolder); // retrieve auto increment id, and set to VO action.setId(keyHolder.getKey().intValue()); return rowsAffected; }
@Override public ActionVO<Integer, String> convertActionVO(Integer tenantId, ActionVO<Integer, Integer> action) { if (action == null) { return null; } return new ActionVO<Integer, String>( action.getId(), action.getTenant(), action.getUser(), action.getSessionId(), action.getIp(), convertItemVO(tenantId, action.getItem()), actionTypeDAO.getTypeById(tenantId, action.getActionType()), action.getRatingValue(), action.getSearchSucceeded(), action.getNumberOfFoundItems(), action.getDescription(), action.getActionTime()); }
@Override public ActionVO<Integer, Integer> convertTypedActionVO(Integer tenantId, ActionVO<Integer, String> typedAction) { if (typedAction == null) { return null; } return new ActionVO<Integer, Integer>( typedAction.getId(), typedAction.getTenant(), typedAction.getUser(), typedAction.getSessionId(), typedAction.getIp(), convertTypedItemVO(tenantId, typedAction.getItem()), actionTypeDAO.getIdOfType(tenantId, typedAction.getActionType()), typedAction.getRatingValue(), typedAction.getSearchSucceeded(), typedAction.getNumberOfFoundItems(), typedAction.getDescription(), typedAction.getActionTime()); }