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:
parent
9973cc8340
commit
8cd0c6542c
6 changed files with 97 additions and 59 deletions
|
@ -47,6 +47,7 @@ import com.vividsolutions.jts.geom.Coordinate;
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------ ---------- ----------- --------------------------
|
||||||
* 7/24/07 353 bphillip Initial Check in
|
* 7/24/07 353 bphillip Initial Check in
|
||||||
* 10/16/2014 3454 bphillip Upgrading to Hibernate 4
|
* 10/16/2014 3454 bphillip Upgrading to Hibernate 4
|
||||||
|
* 10/28/2014 3454 bphillip Fix usage of getSession()
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -170,7 +171,13 @@ public class RadarStationDao extends CoreDao {
|
||||||
}
|
}
|
||||||
crit.add(stationEq);
|
crit.add(stationEq);
|
||||||
Session session = getSession();
|
Session session = getSession();
|
||||||
return crit.getExecutableCriteria(session).list();
|
try {
|
||||||
|
return crit.getExecutableCriteria(session).list();
|
||||||
|
} finally {
|
||||||
|
if (session != null){
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Cannot execute spatial query with less than 3 points");
|
logger.warn("Cannot execute spatial query with less than 3 points");
|
||||||
return new ArrayList<RadarStation>();
|
return new ArrayList<RadarStation>();
|
||||||
|
|
|
@ -47,6 +47,7 @@ import com.raytheon.uf.edex.pointdata.PointDataPluginDao;
|
||||||
* Aug 30, 2013 2298 rjpeter Make getPluginName abstract
|
* Aug 30, 2013 2298 rjpeter Make getPluginName abstract
|
||||||
* Mar 27, 2014 2811 skorolev Updated logger.
|
* Mar 27, 2014 2811 skorolev Updated logger.
|
||||||
* Jun 06, 2014 2061 bsteffen Extend PointDataPluginDao
|
* Jun 06, 2014 2061 bsteffen Extend PointDataPluginDao
|
||||||
|
* 10/28/2014 3454 bphillip Fix usage of getSession()
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -122,13 +123,14 @@ public class ACARSDao extends PointDataPluginDao<ACARSRecord> {
|
||||||
* The HQL query string
|
* The HQL query string
|
||||||
* @return The list of objects returned by the query
|
* @return The list of objects returned by the query
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public List<?> executeACARSQuery(final String hqlQuery) {
|
public List<?> executeACARSQuery(final String hqlQuery) {
|
||||||
|
|
||||||
List<?> result = (List<?>) txTemplate
|
List<?> result = (List<?>) txTemplate
|
||||||
.execute(new TransactionCallback() {
|
.execute(new TransactionCallback() {
|
||||||
@Override
|
@Override
|
||||||
public List<?> doInTransaction(TransactionStatus status) {
|
public List<?> doInTransaction(TransactionStatus status) {
|
||||||
Query hibQuery = getSession(false)
|
Query hibQuery = getCurrentSession()
|
||||||
.createQuery(hqlQuery);
|
.createQuery(hqlQuery);
|
||||||
// hibQuery.setCacheMode(CacheMode.NORMAL);
|
// hibQuery.setCacheMode(CacheMode.NORMAL);
|
||||||
// hibQuery.setCacheRegion(QUERY_CACHE_REGION);
|
// hibQuery.setCacheRegion(QUERY_CACHE_REGION);
|
||||||
|
|
|
@ -43,6 +43,7 @@ import com.raytheon.uf.edex.plugin.acarssounding.tools.ACARSSoundingTools;
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------ ---------- ----------- --------------------------
|
||||||
* Jan 21, 2009 1939 jkorman Initial creation
|
* Jan 21, 2009 1939 jkorman Initial creation
|
||||||
* Aug 18, 2014 3530 bclement removed warning from executeSoundingQuery()
|
* Aug 18, 2014 3530 bclement removed warning from executeSoundingQuery()
|
||||||
|
* 10/28/2014 3454 bphillip Fix usage of getSession()
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -107,7 +108,7 @@ public class ACARSSoundingDao extends DefaultPluginDao {
|
||||||
List<?> result = (List<?>) txTemplate
|
List<?> result = (List<?>) txTemplate
|
||||||
.execute(new TransactionCallback<Object>() {
|
.execute(new TransactionCallback<Object>() {
|
||||||
public List<?> doInTransaction(TransactionStatus status) {
|
public List<?> doInTransaction(TransactionStatus status) {
|
||||||
Query hibQuery = getSession(false)
|
Query hibQuery = getCurrentSession()
|
||||||
.createQuery(hqlQuery);
|
.createQuery(hqlQuery);
|
||||||
return hibQuery.list();
|
return hibQuery.list();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* May 20, 2014 2536 bclement moved from edex.textdb to edex.plugin.text
|
||||||
* Sep 18, 2014 3627 mapeters Updated deprecated {@link TimeTools} usage.
|
* Sep 18, 2014 3627 mapeters Updated deprecated {@link TimeTools} usage.
|
||||||
* 10/16/2014 3454 bphillip Upgrading to Hibernate 4
|
* 10/16/2014 3454 bphillip Upgrading to Hibernate 4
|
||||||
|
* 10/28/2014 3454 bphillip Fix usage of getSession()
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author garmendariz
|
* @author garmendariz
|
||||||
|
@ -191,47 +192,52 @@ public class StdTextProductDao extends CoreDao {
|
||||||
prodId.setCccid(ccc);
|
prodId.setCccid(ccc);
|
||||||
prodId.setNnnid(nnn);
|
prodId.setNnnid(nnn);
|
||||||
prodId.setXxxid(xxx);
|
prodId.setXxxid(xxx);
|
||||||
|
Session session = this.getSession();
|
||||||
try {
|
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 {
|
try {
|
||||||
String cccid = prodId.getCccid();
|
Query query = session.createQuery("SELECT refTime from "
|
||||||
String nnnid = prodId.getNnnid();
|
+ textProduct.getClass().getSimpleName()
|
||||||
String xxxid = prodId.getXxxid();
|
+ " where prodId = :prodid");
|
||||||
Query query = this
|
query.setParameter("prodid", prodId);
|
||||||
.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);
|
|
||||||
List<?> results = query.list();
|
List<?> results = query.list();
|
||||||
|
|
||||||
if (results == null || results.size() < 1) {
|
if (results == null || results.size() < 1) {
|
||||||
TextProductInfo tpi = new TextProductInfo(cccid, nnnid,
|
// save
|
||||||
xxxid);
|
create(textProduct);
|
||||||
create(tpi);
|
success = true;
|
||||||
|
} else {
|
||||||
|
// don't save
|
||||||
|
success = false;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} 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) {
|
public long getLatestTime(AFOSProductId afosId) {
|
||||||
long latestTime = 0L;
|
long latestTime = 0L;
|
||||||
|
|
||||||
|
Session sess = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Session sess = getSession();
|
sess = getSession();
|
||||||
|
|
||||||
Map<?, ?> tmp = buildCriterions(ProdCCC_ID, afosId.getCcc(),
|
Map<?, ?> tmp = buildCriterions(ProdCCC_ID, afosId.getCcc(),
|
||||||
ProdNNN_ID, afosId.getNnn(), ProdXXX_ID, afosId.getXxx());
|
ProdNNN_ID, afosId.getNnn(), ProdXXX_ID, afosId.getXxx());
|
||||||
|
@ -573,6 +581,10 @@ public class StdTextProductDao extends CoreDao {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error occurred getting latest time", e);
|
logger.error("Error occurred getting latest time", e);
|
||||||
|
}finally{
|
||||||
|
if(sess != null){
|
||||||
|
sess.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return latestTime;
|
return latestTime;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.Query;
|
import org.hibernate.Query;
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.springframework.transaction.TransactionStatus;
|
import org.springframework.transaction.TransactionStatus;
|
||||||
import org.springframework.transaction.support.TransactionCallback;
|
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)
|
* Nov 08, 2013 2361 njensen Chaged method signature of saveOrUpdate(Object)
|
||||||
* May 22, 2014 2536 bclement moved from autobldsrv to edex.plugin.text
|
* May 22, 2014 2536 bclement moved from autobldsrv to edex.plugin.text
|
||||||
* 10/16/2014 3454 bphillip Upgrading to Hibernate 4
|
* 10/16/2014 3454 bphillip Upgrading to Hibernate 4
|
||||||
|
* 10/28/2014 3454 bphillip Fix usage of getSession()
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author mfegan
|
* @author mfegan
|
||||||
|
@ -110,25 +112,30 @@ public class SubscriptionDAO extends CoreDao {
|
||||||
*/
|
*/
|
||||||
public boolean write(SubscriptionRecord record) {
|
public boolean write(SubscriptionRecord record) {
|
||||||
// query
|
// query
|
||||||
Query query = this
|
Session session = this.getSession();
|
||||||
.getSession()
|
try {
|
||||||
.createQuery(
|
Query query = session
|
||||||
"from SubscriptionRecord where type = :type and trigger = :trigger and runner = :runner and script = :script and filepath = :filepath and arguments = :arguments");
|
.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("type", record.getType());
|
||||||
query.setParameter("trigger", record.getTrigger());
|
query.setParameter("trigger", record.getTrigger());
|
||||||
query.setParameter("runner", record.getRunner());
|
query.setParameter("runner", record.getRunner());
|
||||||
query.setParameter("script", record.getScript());
|
query.setParameter("script", record.getScript());
|
||||||
query.setParameter("filepath", record.getFilepath());
|
query.setParameter("filepath", record.getFilepath());
|
||||||
query.setParameter("arguments", record.getArguments());
|
query.setParameter("arguments", record.getArguments());
|
||||||
List<?> results = query.list();
|
List<?> results = query.list();
|
||||||
|
|
||||||
if (results.size() > 0) {
|
if (results.size() > 0) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
create(record);
|
create(record);
|
||||||
sendSubscriptionNotifyMessage(String
|
sendSubscriptionNotifyMessage(String.valueOf(record
|
||||||
.valueOf(record.getIdentifier()));
|
.getIdentifier()));
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (session != null) {
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +179,7 @@ public class SubscriptionDAO extends CoreDao {
|
||||||
@Override
|
@Override
|
||||||
public List<SubscriptionRecord> doInTransaction(
|
public List<SubscriptionRecord> doInTransaction(
|
||||||
TransactionStatus status) {
|
TransactionStatus status) {
|
||||||
Criteria criteria = getSession().createCriteria(
|
Criteria criteria = getCurrentSession().createCriteria(
|
||||||
daoClass);
|
daoClass);
|
||||||
return criteria.list();
|
return criteria.list();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
|
||||||
import com.raytheon.uf.common.dataplugin.text.db.WatchWarn;
|
import com.raytheon.uf.common.dataplugin.text.db.WatchWarn;
|
||||||
import com.raytheon.uf.edex.database.DataAccessLayerException;
|
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.
|
* Oct 1, 2008 1538 jkorman Added additional functionality.
|
||||||
* Aug 9, 2010 3944 cjeanbap Added method, queryAllWatchWarn.
|
* Aug 9, 2010 3944 cjeanbap Added method, queryAllWatchWarn.
|
||||||
* May 20, 2014 2536 bclement moved from edex.textdb to edex.plugin.text
|
* May 20, 2014 2536 bclement moved from edex.textdb to edex.plugin.text
|
||||||
|
* 10/28/2014 3454 bphillip Fix usage of getSession()
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author garmendariz
|
* @author garmendariz
|
||||||
|
@ -109,8 +111,15 @@ public class WatchWarnDao extends CoreDao {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<WatchWarn> queryAllWatchWarn() {
|
public List<WatchWarn> queryAllWatchWarn() {
|
||||||
|
|
||||||
Criteria criteria = getSession().createCriteria(WatchWarn.class);
|
Session session = getSession();
|
||||||
|
try{
|
||||||
|
Criteria criteria = session.createCriteria(WatchWarn.class);
|
||||||
|
|
||||||
return criteria.list();
|
return criteria.list();
|
||||||
|
} finally {
|
||||||
|
if(session != null){
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue