@Test public void testKeyForNoMaster() throws Exception { final LookUpQueryParameterStrategy<CsvImportDescriptor, CsvImportTuple, CsvValueAdapter> sqlStrategy = mockery.mock(LookUpQueryParameterStrategy.class, "sqlStrategy"); final GenericDAO<Object, Long> genericDAO = mockery.mock(GenericDAO.class, "genericDAO"); final LookUpQuery query = mockery.mock(LookUpQuery.class, "query"); final CsvImportDescriptor descriptor = mockery.mock(CsvImportDescriptor.class, "descriptor"); final CsvImportColumn codeColumn = mockery.mock(CsvImportColumn.class, "codeColumn"); final CsvImportTuple tuple = mockery.mock(CsvImportTuple.class, "tuple"); final CsvValueAdapter adapter = mockery.mock(CsvValueAdapter.class, "adapter"); mockery.checking(new Expectations() {{ allowing(codeColumn).getColumnIndex(); will(returnValue(3)); allowing(codeColumn).getName(); will(returnValue("code")); allowing(codeColumn).getLookupQuery(); will(returnValue("queryString")); allowing(codeColumn).isUseMasterObject(); will(returnValue(false)); oneOf(sqlStrategy).getQuery(descriptor, null, tuple, adapter, "queryString"); will(returnValue(query)); oneOf(query).getQueryString(); will(returnValue("queryString")); oneOf(query).getParameters(); will(returnValue(new Object[] { "p1", "p2" })); }}); final EntityCacheKeyStrategy strategy = new ColumnLookUpQueryCacheKeyStrategy(sqlStrategy, genericDAO); final String key = strategy.keyFor(descriptor, codeColumn, null, tuple, adapter); assertEquals("code_3_queryString_p1_p2", key); mockery.assertIsSatisfied(); }
@Override public String keyFor(final CsvImportDescriptor descriptor, final CsvImportColumn column, final Object masterObject, final CsvImportTuple tuple, final CsvValueAdapter adapter) { final LookUpQuery query = lookUpStrategy.getQuery(descriptor, masterObject, tuple, adapter, column.getLookupQuery()); final StringBuilder sb = new StringBuilder(); sb.append(column.getName()).append('_').append(column.getColumnIndex()).append('_').append(query.getQueryString()); for (Object obj : query.getParameters()) { sb.append('_').append(obj); } if (column.isUseMasterObject()) { final Object pk; if (masterObject != null) { pk = genericDAO.getEntityIdentifier(masterObject); } else { pk = null; } if (pk != null) { sb.append('_').append(pk); } else { sb.append("_NA"); } } return sb.toString(); }
ColumnLookUpQueryCacheKeyStrategy implements EntityCacheKeyStrategy { @Override public String keyFor(final CsvImportDescriptor descriptor, final CsvImportColumn column, final Object masterObject, final CsvImportTuple tuple, final CsvValueAdapter adapter) { final LookUpQuery query = lookUpStrategy.getQuery(descriptor, masterObject, tuple, adapter, column.getLookupQuery()); final StringBuilder sb = new StringBuilder(); sb.append(column.getName()).append('_').append(column.getColumnIndex()).append('_').append(query.getQueryString()); for (Object obj : query.getParameters()) { sb.append('_').append(obj); } if (column.isUseMasterObject()) { final Object pk; if (masterObject != null) { pk = genericDAO.getEntityIdentifier(masterObject); } else { pk = null; } if (pk != null) { sb.append('_').append(pk); } else { sb.append("_NA"); } } return sb.toString(); } }
ColumnLookUpQueryCacheKeyStrategy implements EntityCacheKeyStrategy { @Override public String keyFor(final CsvImportDescriptor descriptor, final CsvImportColumn column, final Object masterObject, final CsvImportTuple tuple, final CsvValueAdapter adapter) { final LookUpQuery query = lookUpStrategy.getQuery(descriptor, masterObject, tuple, adapter, column.getLookupQuery()); final StringBuilder sb = new StringBuilder(); sb.append(column.getName()).append('_').append(column.getColumnIndex()).append('_').append(query.getQueryString()); for (Object obj : query.getParameters()) { sb.append('_').append(obj); } if (column.isUseMasterObject()) { final Object pk; if (masterObject != null) { pk = genericDAO.getEntityIdentifier(masterObject); } else { pk = null; } if (pk != null) { sb.append('_').append(pk); } else { sb.append("_NA"); } } return sb.toString(); } ColumnLookUpQueryCacheKeyStrategy(final LookUpQueryParameterStrategy<CsvImportDescriptor, CsvImportTuple, CsvValueAdapter> lookUpStrategy,
                                             final GenericDAO<Object, Long> genericDAO); }
ColumnLookUpQueryCacheKeyStrategy implements EntityCacheKeyStrategy { @Override public String keyFor(final CsvImportDescriptor descriptor, final CsvImportColumn column, final Object masterObject, final CsvImportTuple tuple, final CsvValueAdapter adapter) { final LookUpQuery query = lookUpStrategy.getQuery(descriptor, masterObject, tuple, adapter, column.getLookupQuery()); final StringBuilder sb = new StringBuilder(); sb.append(column.getName()).append('_').append(column.getColumnIndex()).append('_').append(query.getQueryString()); for (Object obj : query.getParameters()) { sb.append('_').append(obj); } if (column.isUseMasterObject()) { final Object pk; if (masterObject != null) { pk = genericDAO.getEntityIdentifier(masterObject); } else { pk = null; } if (pk != null) { sb.append('_').append(pk); } else { sb.append("_NA"); } } return sb.toString(); } ColumnLookUpQueryCacheKeyStrategy(final LookUpQueryParameterStrategy<CsvImportDescriptor, CsvImportTuple, CsvValueAdapter> lookUpStrategy,
                                             final GenericDAO<Object, Long> genericDAO); @Override String keyFor(final CsvImportDescriptor descriptor,
                         final CsvImportColumn column,
                         final Object masterObject,
                         final CsvImportTuple tuple,
                         final CsvValueAdapter adapter); }
ColumnLookUpQueryCacheKeyStrategy implements EntityCacheKeyStrategy { @Override public String keyFor(final CsvImportDescriptor descriptor, final CsvImportColumn column, final Object masterObject, final CsvImportTuple tuple, final CsvValueAdapter adapter) { final LookUpQuery query = lookUpStrategy.getQuery(descriptor, masterObject, tuple, adapter, column.getLookupQuery()); final StringBuilder sb = new StringBuilder(); sb.append(column.getName()).append('_').append(column.getColumnIndex()).append('_').append(query.getQueryString()); for (Object obj : query.getParameters()) { sb.append('_').append(obj); } if (column.isUseMasterObject()) { final Object pk; if (masterObject != null) { pk = genericDAO.getEntityIdentifier(masterObject); } else { pk = null; } if (pk != null) { sb.append('_').append(pk); } else { sb.append("_NA"); } } return sb.toString(); } ColumnLookUpQueryCacheKeyStrategy(final LookUpQueryParameterStrategy<CsvImportDescriptor, CsvImportTuple, CsvValueAdapter> lookUpStrategy,
                                             final GenericDAO<Object, Long> genericDAO); @Override String keyFor(final CsvImportDescriptor descriptor,
                         final CsvImportColumn column,
                         final Object masterObject,
                         final CsvImportTuple tuple,
                         final CsvValueAdapter adapter);  }