Omaha #3454 Fixing usage of getSession() to ensure proper session closure

Former-commit-id: 50f5c8d1e3 [formerly fc36b84fa43c354b674f040ae5d2647df5b3122f]
Former-commit-id: bbd2081844
This commit is contained in:
Benjamin Phillippe 2014-10-28 11:30:25 -05:00
parent 9973cc8340
commit 8cd0c6542c
6 changed files with 97 additions and 59 deletions

View file

@ -47,6 +47,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* ------------ ---------- ----------- --------------------------
* 7/24/07 353 bphillip Initial Check in
* 10/16/2014 3454 bphillip Upgrading to Hibernate 4
* 10/28/2014 3454 bphillip Fix usage of getSession()
*
* </pre>
*
@ -170,7 +171,13 @@ public class RadarStationDao extends CoreDao {
}
crit.add(stationEq);
Session session = getSession();
return crit.getExecutableCriteria(session).list();
try {
return crit.getExecutableCriteria(session).list();
} finally {
if (session != null){
session.close();
}
}
} else {
logger.warn("Cannot execute spatial query with less than 3 points");
return new ArrayList<RadarStation>();

View file

@ -47,6 +47,7 @@ import com.raytheon.uf.edex.pointdata.PointDataPluginDao;
* Aug 30, 2013 2298 rjpeter Make getPluginName abstract
* Mar 27, 2014 2811 skorolev Updated logger.
* Jun 06, 2014 2061 bsteffen Extend PointDataPluginDao
* 10/28/2014 3454 bphillip Fix usage of getSession()
*
* </pre>
*
@ -122,13 +123,14 @@ public class ACARSDao extends PointDataPluginDao<ACARSRecord> {
* The HQL query string
* @return The list of objects returned by the query
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<?> executeACARSQuery(final String hqlQuery) {
List<?> result = (List<?>) txTemplate
.execute(new TransactionCallback() {
@Override
public List<?> doInTransaction(TransactionStatus status) {
Query hibQuery = getSession(false)
Query hibQuery = getCurrentSession()
.createQuery(hqlQuery);
// hibQuery.setCacheMode(CacheMode.NORMAL);
// hibQuery.setCacheRegion(QUERY_CACHE_REGION);

View file

@ -43,6 +43,7 @@ import com.raytheon.uf.edex.plugin.acarssounding.tools.ACARSSoundingTools;
* ------------ ---------- ----------- --------------------------
* Jan 21, 2009 1939 jkorman Initial creation
* Aug 18, 2014 3530 bclement removed warning from executeSoundingQuery()
* 10/28/2014 3454 bphillip Fix usage of getSession()
*
* </pre>
*
@ -107,7 +108,7 @@ public class ACARSSoundingDao extends DefaultPluginDao {
List<?> result = (List<?>) txTemplate
.execute(new TransactionCallback<Object>() {
public List<?> doInTransaction(TransactionStatus status) {
Query hibQuery = getSession(false)
Query hibQuery = getCurrentSession()
.createQuery(hqlQuery);
return hibQuery.list();
}

View file

@ -93,6 +93,7 @@ import com.raytheon.uf.edex.decodertools.time.TimeTools;
* May 20, 2014 2536 bclement moved from edex.textdb to edex.plugin.text
* Sep 18, 2014 3627 mapeters Updated deprecated {@link TimeTools} usage.
* 10/16/2014 3454 bphillip Upgrading to Hibernate 4
* 10/28/2014 3454 bphillip Fix usage of getSession()
* </pre>
*
* @author garmendariz
@ -191,47 +192,52 @@ public class StdTextProductDao extends CoreDao {
prodId.setCccid(ccc);
prodId.setNnnid(nnn);
prodId.setXxxid(xxx);
Session session = this.getSession();
try {
Query query = this.getSession().createQuery(
"SELECT refTime from "
+ textProduct.getClass().getSimpleName()
+ " where prodId = :prodid");
query.setParameter("prodid", prodId);
List<?> results = query.list();
if (results == null || results.size() < 1) {
// save
create(textProduct);
success = true;
} else {
// don't save
success = false;
}
} catch (Exception e) {
logger.error("Error storing text product", e);
}
if (success) {
try {
String cccid = prodId.getCccid();
String nnnid = prodId.getNnnid();
String xxxid = prodId.getXxxid();
Query query = this
.getSession()
.createQuery(
"SELECT versionstokeep FROM TextProductInfo WHERE "
+ "prodId.cccid = :cccid AND prodId.nnnid = :nnnid AND prodId.xxxid = :xxxid");
query.setParameter("cccid", cccid);
query.setParameter("nnnid", nnnid);
query.setParameter("xxxid", xxxid);
Query query = session.createQuery("SELECT refTime from "
+ textProduct.getClass().getSimpleName()
+ " where prodId = :prodid");
query.setParameter("prodid", prodId);
List<?> results = query.list();
if (results == null || results.size() < 1) {
TextProductInfo tpi = new TextProductInfo(cccid, nnnid,
xxxid);
create(tpi);
// save
create(textProduct);
success = true;
} else {
// don't save
success = false;
}
} catch (Exception e) {
logger.error("Error verify text product info", e);
logger.error("Error storing text product", e);
}
if (success) {
try {
String cccid = prodId.getCccid();
String nnnid = prodId.getNnnid();
String xxxid = prodId.getXxxid();
Query query = session
.createQuery(
"SELECT versionstokeep FROM TextProductInfo WHERE "
+ "prodId.cccid = :cccid AND prodId.nnnid = :nnnid AND prodId.xxxid = :xxxid");
query.setParameter("cccid", cccid);
query.setParameter("nnnid", nnnid);
query.setParameter("xxxid", xxxid);
List<?> results = query.list();
if (results == null || results.size() < 1) {
TextProductInfo tpi = new TextProductInfo(cccid, nnnid,
xxxid);
create(tpi);
}
} catch (Exception e) {
logger.error("Error verify text product info", e);
}
}
} finally {
if (session != null) {
session.close();
}
}
@ -550,8 +556,10 @@ public class StdTextProductDao extends CoreDao {
public long getLatestTime(AFOSProductId afosId) {
long latestTime = 0L;
Session sess = null;
try {
Session sess = getSession();
sess = getSession();
Map<?, ?> tmp = buildCriterions(ProdCCC_ID, afosId.getCcc(),
ProdNNN_ID, afosId.getNnn(), ProdXXX_ID, afosId.getXxx());
@ -573,6 +581,10 @@ public class StdTextProductDao extends CoreDao {
}
} catch (Exception e) {
logger.error("Error occurred getting latest time", e);
}finally{
if(sess != null){
sess.close();
}
}
return latestTime;

View file

@ -27,6 +27,7 @@ import java.util.Map;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
@ -57,6 +58,7 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery;
* Nov 08, 2013 2361 njensen Chaged method signature of saveOrUpdate(Object)
* May 22, 2014 2536 bclement moved from autobldsrv to edex.plugin.text
* 10/16/2014 3454 bphillip Upgrading to Hibernate 4
* 10/28/2014 3454 bphillip Fix usage of getSession()
* </pre>
*
* @author mfegan
@ -110,25 +112,30 @@ public class SubscriptionDAO extends CoreDao {
*/
public boolean write(SubscriptionRecord record) {
// query
Query query = this
.getSession()
.createQuery(
"from SubscriptionRecord where type = :type and trigger = :trigger and runner = :runner and script = :script and filepath = :filepath and arguments = :arguments");
query.setParameter("type", record.getType());
query.setParameter("trigger", record.getTrigger());
query.setParameter("runner", record.getRunner());
query.setParameter("script", record.getScript());
query.setParameter("filepath", record.getFilepath());
query.setParameter("arguments", record.getArguments());
List<?> results = query.list();
Session session = this.getSession();
try {
Query query = session
.createQuery("from SubscriptionRecord where type = :type and trigger = :trigger and runner = :runner and script = :script and filepath = :filepath and arguments = :arguments");
query.setParameter("type", record.getType());
query.setParameter("trigger", record.getTrigger());
query.setParameter("runner", record.getRunner());
query.setParameter("script", record.getScript());
query.setParameter("filepath", record.getFilepath());
query.setParameter("arguments", record.getArguments());
List<?> results = query.list();
if (results.size() > 0) {
return false;
} else {
create(record);
sendSubscriptionNotifyMessage(String
.valueOf(record.getIdentifier()));
return true;
if (results.size() > 0) {
return false;
} else {
create(record);
sendSubscriptionNotifyMessage(String.valueOf(record
.getIdentifier()));
return true;
}
} finally {
if (session != null) {
session.close();
}
}
}
@ -172,7 +179,7 @@ public class SubscriptionDAO extends CoreDao {
@Override
public List<SubscriptionRecord> doInTransaction(
TransactionStatus status) {
Criteria criteria = getSession().createCriteria(
Criteria criteria = getCurrentSession().createCriteria(
daoClass);
return criteria.list();
}

View file

@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import com.raytheon.uf.common.dataplugin.text.db.WatchWarn;
import com.raytheon.uf.edex.database.DataAccessLayerException;
@ -44,6 +45,7 @@ import com.raytheon.uf.edex.database.dao.DaoConfig;
* Oct 1, 2008 1538 jkorman Added additional functionality.
* Aug 9, 2010 3944 cjeanbap Added method, queryAllWatchWarn.
* May 20, 2014 2536 bclement moved from edex.textdb to edex.plugin.text
* 10/28/2014 3454 bphillip Fix usage of getSession()
* </pre>
*
* @author garmendariz
@ -109,8 +111,15 @@ public class WatchWarnDao extends CoreDao {
@SuppressWarnings("unchecked")
public List<WatchWarn> queryAllWatchWarn() {
Criteria criteria = getSession().createCriteria(WatchWarn.class);
Session session = getSession();
try{
Criteria criteria = session.createCriteria(WatchWarn.class);
return criteria.list();
} finally {
if(session != null){
session.close();
}
}
}
}