@Test public void testAddActionsToSql() { Parameters parameters = mock(Parameters.class); when(parameters.getActions()).thenReturn(null); StringBuilder stringBuilder = new StringBuilder(); List param = new ArrayList<>(); databaseAnalytics.addActionsToSql(parameters, stringBuilder, param); assertThat(stringBuilder.toString(), is("")); assertThat(param.size(), is(0)); List<String> actions = new ArrayList<>(); actions.add("a1"); when(parameters.getActions()).thenReturn(actions); databaseAnalytics.addActionsToSql(parameters, stringBuilder, param); assertThat(actions.size(), is(1)); assertThat(param.size(), is(1)); assertThat(stringBuilder.toString(), is(" and action in (?) ")); stringBuilder.setLength(0); param.clear(); actions.add("a2"); databaseAnalytics.addActionsToSql(parameters, stringBuilder, param); assertThat(actions.size(), is(2)); assertThat(param.size(), is(2)); assertThat(stringBuilder.toString(), is(" and action in (?,?) ")); }
void addActionsToSql(Parameters parameters, StringBuilder sqlParams, List params) { List<String> actions = parameters.getActions(); if (actions != null) { int num_actions = actions.size(); if (num_actions >= 1) { sqlParams.append(" and action in (?"); params.add(actions.get(0)); } for (int num = 1; num < num_actions; num++) { sqlParams.append(",?"); params.add(actions.get(num)); } if (num_actions >= 1) { sqlParams.append(") "); } } }
DatabaseAnalytics implements AnalyticsRepository { void addActionsToSql(Parameters parameters, StringBuilder sqlParams, List params) { List<String> actions = parameters.getActions(); if (actions != null) { int num_actions = actions.size(); if (num_actions >= 1) { sqlParams.append(" and action in (?"); params.add(actions.get(0)); } for (int num = 1; num < num_actions; num++) { sqlParams.append(",?"); params.add(actions.get(num)); } if (num_actions >= 1) { sqlParams.append(") "); } } } }
DatabaseAnalytics implements AnalyticsRepository { void addActionsToSql(Parameters parameters, StringBuilder sqlParams, List params) { List<String> actions = parameters.getActions(); if (actions != null) { int num_actions = actions.size(); if (num_actions >= 1) { sqlParams.append(" and action in (?"); params.add(actions.get(0)); } for (int num = 1; num < num_actions; num++) { sqlParams.append(",?"); params.add(actions.get(num)); } if (num_actions >= 1) { sqlParams.append(") "); } } } @Inject  DatabaseAnalytics(TransactionFactory transactionFactory, Flyway flyway); }
DatabaseAnalytics implements AnalyticsRepository { void addActionsToSql(Parameters parameters, StringBuilder sqlParams, List params) { List<String> actions = parameters.getActions(); if (actions != null) { int num_actions = actions.size(); if (num_actions >= 1) { sqlParams.append(" and action in (?"); params.add(actions.get(0)); } for (int num = 1; num < num_actions; num++) { sqlParams.append(",?"); params.add(actions.get(num)); } if (num_actions >= 1) { sqlParams.append(") "); } } } @Inject  DatabaseAnalytics(TransactionFactory transactionFactory, Flyway flyway); @Override List<Map> getRollupRows(Experiment.ID experimentId, String rollupDate, Parameters parameters); @Override List<Map> getActionsRows(Experiment.ID experimentID, Parameters parameters); @Override List<Map> getJointActions(Experiment.ID experimentID, Parameters parameters); @Override List<Map> getImpressionRows(Experiment.ID experimentID, Parameters parameters); @Override Map<Bucket.Label, BucketCounts> getEmptyBuckets(Experiment.ID experimentID); @Override List<Map> getCountsFromRollups(Experiment.ID experimentID, Parameters parameters); @Override boolean checkMostRecentRollup(Experiment experiment, Parameters parameters, Date to); }
DatabaseAnalytics implements AnalyticsRepository { void addActionsToSql(Parameters parameters, StringBuilder sqlParams, List params) { List<String> actions = parameters.getActions(); if (actions != null) { int num_actions = actions.size(); if (num_actions >= 1) { sqlParams.append(" and action in (?"); params.add(actions.get(0)); } for (int num = 1; num < num_actions; num++) { sqlParams.append(",?"); params.add(actions.get(num)); } if (num_actions >= 1) { sqlParams.append(") "); } } } @Inject  DatabaseAnalytics(TransactionFactory transactionFactory, Flyway flyway); @Override List<Map> getRollupRows(Experiment.ID experimentId, String rollupDate, Parameters parameters); @Override List<Map> getActionsRows(Experiment.ID experimentID, Parameters parameters); @Override List<Map> getJointActions(Experiment.ID experimentID, Parameters parameters); @Override List<Map> getImpressionRows(Experiment.ID experimentID, Parameters parameters); @Override Map<Bucket.Label, BucketCounts> getEmptyBuckets(Experiment.ID experimentID); @Override List<Map> getCountsFromRollups(Experiment.ID experimentID, Parameters parameters); @Override boolean checkMostRecentRollup(Experiment experiment, Parameters parameters, Date to);  }