/** * Checks whether two <code>Action</code> objects point to the same item * * @param action * @return */ public boolean hasSameBelongingItem(ActionVO<I,T> action) { return isBelongingToItem(action.getItem()); }
@SuppressWarnings("unchecked") @Override public ActionVO<I,T> clone() throws CloneNotSupportedException { ActionVO<I,T> clonedActionVO = (ActionVO<I,T>) super.clone(); clonedActionVO.setItem(clonedActionVO.getItem().clone()); return clonedActionVO; } }
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'"); } }
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); }
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; }
@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; }
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; }
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; }
action = currentAction; return new RatingVO<Integer, String>(action.getItem(), ((double) (sumCurrentRatingValues / (double) countCurrentActions)), actionsForTenantUserItemTriple.size(), action.getActionTime(), action.getUser()); return new RatingVO<Integer, String>(action.getItem(), actionMapping.get(action.getActionType()), actionsForTenantUserItemTriple.size(), action.getActionTime(), action.getUser()); return new RatingVO<Integer, String>(action.getItem(), actionMapping.get(action.getActionType()), actionsForTenantUserItemTriple.size(), action.getActionTime(), action.getUser()); return new RatingVO<Integer, String>(currentAction.getItem(), actionMapping.get(currentAction.getActionType()), actionsForTenantUserItemTriple.size(), action.getActionTime(), currentAction.getUser()); return new RatingVO<Integer, String>(action.getItem(), actionMapping.get(action.getActionType()), actionsForTenantUserItemTriple.size(), action.getActionTime(), action.getUser()); return new RatingVO<Integer, String>(action.getItem(), actionMapping.get(action.getActionType()), actionsForTenantUserItemTriple.size(), action.getActionTime(), action.getUser());
action.getItem().setItem(Integer.parseInt(elementsOfLine[4])); } catch (NumberFormatException nfe) { AutoImportUtils.logSkippedLine(logger, lineCounter, line, action.getItem().setType(Integer.parseInt(elementsOfLine[5])); } catch (NumberFormatException nfe) { AutoImportUtils.logSkippedLine(logger, lineCounter, line, if (action.getItem().getType() == null) { AutoImportUtils.logSkippedLine(logger, lineCounter, line, "no value for field 'itemTypeId' is set");
if (defaultValue != null) { try { action.getItem().setItem(Integer.parseInt(defaultValue)); } catch (NumberFormatException nfe) { logger.warn("the default value for 'itemId' in the CSV header is no valid 'Integer', passed type='" + if (defaultValue != null) { try { action.getItem().setType(Integer.parseInt(defaultValue)); } catch (NumberFormatException nfe) { logger.warn(
@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()); }
@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()); }