diff --git a/edexOsgi/com.raytheon.edex.plugin.radar/src/com/raytheon/edex/plugin/radar/dao/RadarStationDao.java b/edexOsgi/com.raytheon.edex.plugin.radar/src/com/raytheon/edex/plugin/radar/dao/RadarStationDao.java index 756c4db368..42148d412c 100644 --- a/edexOsgi/com.raytheon.edex.plugin.radar/src/com/raytheon/edex/plugin/radar/dao/RadarStationDao.java +++ b/edexOsgi/com.raytheon.edex.plugin.radar/src/com/raytheon/edex/plugin/radar/dao/RadarStationDao.java @@ -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() * * * @@ -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(); diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.acars/src/com/raytheon/uf/edex/plugin/acars/dao/ACARSDao.java b/edexOsgi/com.raytheon.uf.edex.plugin.acars/src/com/raytheon/uf/edex/plugin/acars/dao/ACARSDao.java index 07e71d1f2e..e623daaf7a 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.acars/src/com/raytheon/uf/edex/plugin/acars/dao/ACARSDao.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.acars/src/com/raytheon/uf/edex/plugin/acars/dao/ACARSDao.java @@ -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() * * * @@ -122,13 +123,14 @@ public class ACARSDao extends PointDataPluginDao { * 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); diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.acarssounding/src/com/raytheon/uf/edex/plugin/acarssounding/dao/ACARSSoundingDao.java b/edexOsgi/com.raytheon.uf.edex.plugin.acarssounding/src/com/raytheon/uf/edex/plugin/acarssounding/dao/ACARSSoundingDao.java index f9e93d352f..a7ae0441ca 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.acarssounding/src/com/raytheon/uf/edex/plugin/acarssounding/dao/ACARSSoundingDao.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.acarssounding/src/com/raytheon/uf/edex/plugin/acarssounding/dao/ACARSSoundingDao.java @@ -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() * * * @@ -107,7 +108,7 @@ public class ACARSSoundingDao extends DefaultPluginDao { List result = (List) txTemplate .execute(new TransactionCallback() { public List doInTransaction(TransactionStatus status) { - Query hibQuery = getSession(false) + Query hibQuery = getCurrentSession() .createQuery(hqlQuery); return hibQuery.list(); } diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/StdTextProductDao.java b/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/StdTextProductDao.java index 582cf6d3e4..85dd4267fc 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/StdTextProductDao.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/StdTextProductDao.java @@ -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() * * * @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; diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/SubscriptionDAO.java b/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/SubscriptionDAO.java index f2646114b5..736364e8a1 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/SubscriptionDAO.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/SubscriptionDAO.java @@ -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() * * * @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 doInTransaction( TransactionStatus status) { - Criteria criteria = getSession().createCriteria( + Criteria criteria = getCurrentSession().createCriteria( daoClass); return criteria.list(); } diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/WatchWarnDao.java b/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/WatchWarnDao.java index c8456ed499..ff81d5361d 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/WatchWarnDao.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.text/src/com/raytheon/uf/edex/plugin/text/dao/WatchWarnDao.java @@ -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() * * * @author garmendariz @@ -109,8 +111,15 @@ public class WatchWarnDao extends CoreDao { @SuppressWarnings("unchecked") public List 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(); + } + } } }