DeviationDAOCachedMergingMySQL extends AbstractTableCreatingDroppingDAOImpl implements DeviationDAO { public synchronized Deviation getDeviation(final int tenantId, final int item1Id, final int item1TypeId, final int item2Id, int item2TypeId) { Object[] args = new Object[]{tenantId, item1TypeId, item2TypeId, item1Id, item2Id}; List<Deviation> deviations = QUERY_GET_CACHED_DEVIATION.execute(args); if (deviations.size() > 0) return deviations.get(0); deviations = QUERY_GET_DEVIATION.execute(args); if (deviations.size() == 0) return null; Deviation result = deviations.get(0); insertCachedDeviation(result); return result; } DeviationDAOCachedMergingMySQL(DataSource dataSource, SqlScriptService sqlScriptService); void starting(); void endUpdate(); void finished(final int tenantId, final int itemTypeId); synchronized Deviation getDeviation(final int tenantId, final int item1Id, final int item1TypeId,
                                               final int item2Id, int item2TypeId); List<Deviation> getDeviationsOrdered(final int tenantId, final int itemTypeId, final int itemId,
                                                final Long minCountConstraint,
                                                final Integer maxNumberOfDeviationsConstraint); @Nonnull Set<TenantItem> getItemIds(final int tenantId, final TIntSet itemTypeIds); synchronized int insertDeviation(final Deviation deviation); synchronized int insertDeviations(final List<Deviation> deviations); @Override String getDefaultTableName(); @Override String getTableCreatingSQLScriptName(); @Override void dropTable(); static final int[] NO_TYPES; }
@Test public void getDeviation_shouldReturnDeviationOrNull() { assertThat(cachedMergingMySqlDeviationDAO.getDeviation(1, 1, 1, 2, 1), equalToDeviationAndId(new Deviation(1, 1, 1, 1, 2, 1, 1.0, 2))); assertThat(cachedMergingMySqlDeviationDAO.getDeviation(1, 1, 1, 3, 3), equalToDeviationAndId(new Deviation(2, 1, 1, 1, 3, 3, 3.0, 4))); assertThat(cachedMergingMySqlDeviationDAO.getDeviation(1, 1, 1, 4, 5), equalToDeviationAndId(new Deviation(3, 1, 1, 1, 4, 5, 5.0, 6))); assertThat(cachedMergingMySqlDeviationDAO.getDeviation(1, 2, 1, 3, 7), equalToDeviationAndId(new Deviation(4, 1, 2, 1, 3, 7, 7.0, 8))); assertThat(cachedMergingMySqlDeviationDAO.getDeviation(1, 2, 1, 4, 9), equalToDeviationAndId(new Deviation(5, 1, 2, 1, 4, 9, 9.0, 10))); assertThat(cachedMergingMySqlDeviationDAO.getDeviation(1, 3, 1, 4, 11), equalToDeviationAndId(new Deviation(6, 1, 3, 1, 4, 11, 11.0, 12))); assertThat(cachedMergingMySqlDeviationDAO.getDeviation(2, 1, 1, 2, 13), equalToDeviationAndId(new Deviation(7, 2, 1, 1, 2, 13, 13.0, 14))); assertThat(cachedMergingMySqlDeviationDAO.getDeviation(1, 5, 1, 1, 2), is(nullValue())); assertThat(cachedMergingMySqlDeviationDAO.getDeviation(1, 1, 1, 5, 2), is(nullValue())); assertThat(cachedMergingMySqlDeviationDAO.getDeviation(1, 1, 2, 2, 2), is(nullValue())); assertThat(cachedMergingMySqlDeviationDAO.getDeviation(3, 1, 1, 2, 2), is(nullValue())); }