params.addValue("identificationBarcode", barcode);
Number newId = insert.executeAndReturnKey(params);
if (newId.longValue() != pool.getId()) {
log.error("Expected Pool ID doesn't match returned value from database insert: rolling back...");
new NamedParameterJdbcTemplate(template).update(POOL_DELETE, new MapSqlParameterSource().addValue("poolId", newId.longValue()));
throw new IOException("Something bad happened. Expected Pool ID doesn't match returned value from DB insert");
}
}
else {
throw new IOException("Cannot save Pool - invalid field:" + pool.toString());
}
}
catch (MisoNamingException e) {
throw new IOException("Cannot save Pool - issue with naming scheme", e);
}
/*
String name = AbstractPool.lookupPrefix(pool.getPlatformType())+ DbUtils.getAutoIncrement(template, TABLE_NAME);
params.addValue("name", name);
params.addValue("identificationBarcode", name + "::" + pool.getPlatformType().getKey());
Number newId = insert.executeAndReturnKey(params);
pool.setPoolId(newId.longValue());
pool.setName(name);
*/
}
else {
try {
if (namingScheme.validateField("name", pool.getName())) {
params.addValue("poolId", pool.getId())
.addValue("name", pool.getName())
.addValue("identificationBarcode", pool.getName() + "::" + pool.getPlatformType().getKey());
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
namedTemplate.update(POOL_UPDATE, params);
}
else {
throw new IOException("Cannot save Pool - invalid field:" + pool.toString());
}
}
catch (MisoNamingException e) {
throw new IOException("Cannot save Pool - issue with naming scheme", e);
}
/*
params.addValue("poolId", pool.getPoolId())
.addValue("name", pool.getName())
.addValue("identificationBarcode", pool.getName() + "::" + pool.getPlatformType().getKey());
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
namedTemplate.update(POOL_UPDATE, params);
*/
}
//log.info("Unlinking elements from pool " + pool.getId());
MapSqlParameterSource delparams = new MapSqlParameterSource();
delparams.addValue("pool_poolId", pool.getId());
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
namedTemplate.update(POOL_ELEMENT_DELETE_BY_POOL_ID, delparams);
if (pool.getPoolableElements() != null && !pool.getPoolableElements().isEmpty()) {
String type = pool.getPoolableElements().iterator().next().getClass().getSimpleName();
SimpleJdbcInsert eInsert = new SimpleJdbcInsert(template).withTableName("Pool_Elements");
String lc = type.substring(0, 1).toLowerCase() + type.substring(1);
Cache dc = cacheManager.getCache(lc + "Cache");
Cache ldc = cacheManager.getCache("lazy" + type + "Cache");
for (Poolable d : pool.getPoolableElements()) {
//log.debug("Linking "+d.getName() + " to " + pool.getName());
MapSqlParameterSource esParams = new MapSqlParameterSource();
esParams.addValue("elementId", d.getId())
.addValue("pool_poolId", pool.getId())
.addValue("elementType", d.getClass().getName());
eInsert.execute(esParams);
if (this.cascadeType != null) {
if (this.cascadeType.equals(CascadeType.PERSIST)) {
Store<? super Poolable> dao = daoLookup.lookup(d.getClass());
if (dao != null) {
dao.save(d);
}
}
else if (this.cascadeType.equals(CascadeType.REMOVE)) {
if (d instanceof Plate) {
dc = cacheManager.getCache("plateCache");
ldc = cacheManager.getCache("lazyPlateCache");
}
//if (dc != null) dc.remove(DbUtils.hashCodeCacheKeyFor(d.getId()));
//if (ldc != null) ldc.remove(DbUtils.hashCodeCacheKeyFor(d.getId()));
if (dc != null) DbUtils.updateCaches(cacheManager, d, Poolable.class);
if (ldc != null) DbUtils.updateCaches(cacheManager, d, Poolable.class);
}
}
}
}
MapSqlParameterSource poolparams = new MapSqlParameterSource();
poolparams.addValue("pool_poolId", pool.getId());
NamedParameterJdbcTemplate poolNamedTemplate = new NamedParameterJdbcTemplate(template);
poolNamedTemplate.update(POOL_EXPERIMENT_DELETE_BY_POOL_ID, poolparams);
if (pool.getExperiments() != null && !pool.getExperiments().isEmpty()) {
//Cache ec = cacheManager.getCache("experimentCache");
SimpleJdbcInsert eInsert = new SimpleJdbcInsert(template)