Commit 2fa3ac9b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

fail safe close db connection added

parent fc92b70f
......@@ -80,14 +80,16 @@ public class PermanentDatabaseLevelCache extends XmlParser implements PermanentD
@Override
public CacheQuery call() throws Exception {
logger.debug("Query task call");
dbUtils.createSessionForCurrentThread();
logger.debug("Query task session started");
CacheQuery entry = getCacheQueryDao().getByQuery((String) query, type);
logger.debug("Query task data retrieved");
dbUtils.closeSessionForCurrentThread();
logger.debug("Query task return");
return entry;
logger.debug("Query task call");
try {
dbUtils.createSessionForCurrentThread();
logger.debug("Query task session started");
CacheQuery entry = getCacheQueryDao().getByQuery((String) query, type);
logger.debug("Query task data retrieved");
return entry;
} finally {
dbUtils.closeSessionForCurrentThread();
}
}
}
......@@ -227,26 +229,29 @@ public class PermanentDatabaseLevelCache extends XmlParser implements PermanentD
@Override
public CacheQuery call() throws Exception {
logger.debug("Add task call");
dbUtils.createSessionForCurrentThread();
CacheQuery entry = getCacheQueryDao().getByQuery((String) query, type);
if (entry == null) {
entry = new CacheQuery();
entry.setQuery((String) query);
entry.setAccessed(Calendar.getInstance());
} else {
entry.setAccessed(Calendar.getInstance());
}
entry.setValue(value);
entry.setType(type);
Calendar expires = Calendar.getInstance();
expires.add(Calendar.DAY_OF_MONTH, type.getValidity());
entry.setExpires(expires);
getCacheQueryDao().add(entry);
dbUtils.closeSessionForCurrentThread();
return entry;
logger.debug("Add task call");
try {
dbUtils.createSessionForCurrentThread();
CacheQuery entry = getCacheQueryDao().getByQuery((String) query, type);
if (entry == null) {
entry = new CacheQuery();
entry.setQuery((String) query);
entry.setAccessed(Calendar.getInstance());
} else {
entry.setAccessed(Calendar.getInstance());
}
entry.setValue(value);
entry.setType(type);
Calendar expires = Calendar.getInstance();
expires.add(Calendar.DAY_OF_MONTH, type.getValidity());
entry.setExpires(expires);
getCacheQueryDao().add(entry);
return entry;
} finally {
dbUtils.closeSessionForCurrentThread();
}
}
}
......@@ -290,13 +295,16 @@ public class PermanentDatabaseLevelCache extends XmlParser implements PermanentD
@Override
public CacheQuery call() throws Exception {
logger.debug("Remove task call");
dbUtils.createSessionForCurrentThread();
CacheQuery entry = getCacheQueryDao().getByQuery((String) query, type);
if (entry != null) {
getCacheQueryDao().delete(entry);
}
dbUtils.closeSessionForCurrentThread();
return entry;
try {
dbUtils.createSessionForCurrentThread();
CacheQuery entry = getCacheQueryDao().getByQuery((String) query, type);
if (entry != null) {
getCacheQueryDao().delete(entry);
}
return entry;
} finally {
dbUtils.closeSessionForCurrentThread();
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment