1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
27
27
28
28
import org .apache .commons .logging .Log ;
29
29
import org .apache .commons .logging .LogFactory ;
30
-
31
30
import org .hibernate .Criteria ;
32
31
import org .hibernate .Filter ;
33
32
import org .hibernate .FlushMode ;
34
33
import org .hibernate .Hibernate ;
35
34
import org .hibernate .HibernateException ;
36
35
import org .hibernate .LockMode ;
37
36
import org .hibernate .LockOptions ;
38
- import org .hibernate .Query ;
39
37
import org .hibernate .ReplicationMode ;
40
38
import org .hibernate .Session ;
41
39
import org .hibernate .SessionFactory ;
@@ -211,7 +209,7 @@ public boolean isCheckWriteOperations() {
211
209
* <p>To specify the query region to be used for queries cached
212
210
* by this template, set the "queryCacheRegion" property.
213
211
* @see #setQueryCacheRegion
214
- * @see Query#setCacheable
212
+ * @see org.hibernate. Query#setCacheable
215
213
* @see Criteria#setCacheable
216
214
*/
217
215
public void setCacheQueries (boolean cacheQueries ) {
@@ -232,7 +230,7 @@ public boolean isCacheQueries() {
232
230
* <p>The cache region will not take effect unless queries created by this
233
231
* template are configured to be cached via the "cacheQueries" property.
234
232
* @see #setCacheQueries
235
- * @see Query#setCacheRegion
233
+ * @see org.hibernate. Query#setCacheRegion
236
234
* @see Criteria#setCacheRegion
237
235
*/
238
236
public void setQueryCacheRegion (String queryCacheRegion ) {
@@ -317,6 +315,7 @@ public <T> T executeWithNativeSession(HibernateCallback<T> action) {
317
315
* @return a result object returned by the action, or {@code null}
318
316
* @throws DataAccessException in case of Hibernate errors
319
317
*/
318
+ @ SuppressWarnings ("deprecation" )
320
319
protected <T > T doExecute (HibernateCallback <T > action , boolean enforceNativeSession ) throws DataAccessException {
321
320
Assert .notNull (action , "Callback object must not be null" );
322
321
@@ -499,7 +498,7 @@ public Object doInHibernate(Session session) throws HibernateException {
499
498
public <T > List <T > loadAll (final Class <T > entityClass ) throws DataAccessException {
500
499
return executeWithNativeSession (new HibernateCallback <List <T >>() {
501
500
@ Override
502
- @ SuppressWarnings ("unchecked" )
501
+ @ SuppressWarnings ({ "unchecked" , "deprecation" } )
503
502
public List <T > doInHibernate (Session session ) throws HibernateException {
504
503
Criteria criteria = session .createCriteria (entityClass );
505
504
criteria .setResultTransformer (Criteria .DISTINCT_ROOT_ENTITY );
@@ -862,8 +861,9 @@ public Object doInHibernate(Session session) {
862
861
public List <?> find (final String queryString , final Object ... values ) throws DataAccessException {
863
862
return executeWithNativeSession (new HibernateCallback <List <?>>() {
864
863
@ Override
864
+ @ SuppressWarnings ({"rawtypes" , "deprecation" })
865
865
public List <?> doInHibernate (Session session ) throws HibernateException {
866
- Query queryObject = session .createQuery (queryString );
866
+ org . hibernate . Query queryObject = session .createQuery (queryString );
867
867
prepareQuery (queryObject );
868
868
if (values != null ) {
869
869
for (int i = 0 ; i < values .length ; i ++) {
@@ -891,13 +891,12 @@ public List<?> findByNamedParam(final String queryString, final String[] paramNa
891
891
}
892
892
return executeWithNativeSession (new HibernateCallback <List <?>>() {
893
893
@ Override
894
+ @ SuppressWarnings ({"rawtypes" , "deprecation" })
894
895
public List <?> doInHibernate (Session session ) throws HibernateException {
895
- Query queryObject = session .createQuery (queryString );
896
+ org . hibernate . Query queryObject = session .createQuery (queryString );
896
897
prepareQuery (queryObject );
897
- if (values != null ) {
898
- for (int i = 0 ; i < values .length ; i ++) {
899
- applyNamedParameterToQuery (queryObject , paramNames [i ], values [i ]);
900
- }
898
+ for (int i = 0 ; i < values .length ; i ++) {
899
+ applyNamedParameterToQuery (queryObject , paramNames [i ], values [i ]);
901
900
}
902
901
return queryObject .list ();
903
902
}
@@ -910,8 +909,9 @@ public List<?> findByValueBean(final String queryString, final Object valueBean)
910
909
911
910
return executeWithNativeSession (new HibernateCallback <List <?>>() {
912
911
@ Override
912
+ @ SuppressWarnings ({"rawtypes" , "deprecation" })
913
913
public List <?> doInHibernate (Session session ) throws HibernateException {
914
- Query queryObject = session .createQuery (queryString );
914
+ org . hibernate . Query queryObject = session .createQuery (queryString );
915
915
prepareQuery (queryObject );
916
916
queryObject .setProperties (valueBean );
917
917
return queryObject .list ();
@@ -928,8 +928,9 @@ public List<?> doInHibernate(Session session) throws HibernateException {
928
928
public List <?> findByNamedQuery (final String queryName , final Object ... values ) throws DataAccessException {
929
929
return executeWithNativeSession (new HibernateCallback <List <?>>() {
930
930
@ Override
931
+ @ SuppressWarnings ({"rawtypes" , "deprecation" })
931
932
public List <?> doInHibernate (Session session ) throws HibernateException {
932
- Query queryObject = session .getNamedQuery (queryName );
933
+ org . hibernate . Query queryObject = session .getNamedQuery (queryName );
933
934
prepareQuery (queryObject );
934
935
if (values != null ) {
935
936
for (int i = 0 ; i < values .length ; i ++) {
@@ -958,8 +959,9 @@ public List<?> findByNamedQueryAndNamedParam(
958
959
}
959
960
return executeWithNativeSession (new HibernateCallback <List <?>>() {
960
961
@ Override
962
+ @ SuppressWarnings ({"rawtypes" , "deprecation" })
961
963
public List <?> doInHibernate (Session session ) throws HibernateException {
962
- Query queryObject = session .getNamedQuery (queryName );
964
+ org . hibernate . Query queryObject = session .getNamedQuery (queryName );
963
965
prepareQuery (queryObject );
964
966
if (values != null ) {
965
967
for (int i = 0 ; i < values .length ; i ++) {
@@ -977,8 +979,9 @@ public List<?> findByNamedQueryAndValueBean(final String queryName, final Object
977
979
978
980
return executeWithNativeSession (new HibernateCallback <List <?>>() {
979
981
@ Override
982
+ @ SuppressWarnings ({"rawtypes" , "deprecation" })
980
983
public List <?> doInHibernate (Session session ) throws HibernateException {
981
- Query queryObject = session .getNamedQuery (queryName );
984
+ org . hibernate . Query queryObject = session .getNamedQuery (queryName );
982
985
prepareQuery (queryObject );
983
986
queryObject .setProperties (valueBean );
984
987
return queryObject .list ();
@@ -1033,6 +1036,7 @@ public <T> List<T> findByExample(T exampleEntity, int firstResult, int maxResult
1033
1036
}
1034
1037
1035
1038
@ Override
1039
+ @ SuppressWarnings ("deprecation" )
1036
1040
public <T > List <T > findByExample (
1037
1041
final String entityName , final T exampleEntity , final int firstResult , final int maxResults )
1038
1042
throws DataAccessException {
@@ -1066,8 +1070,9 @@ public List<T> doInHibernate(Session session) throws HibernateException {
1066
1070
public Iterator <?> iterate (final String queryString , final Object ... values ) throws DataAccessException {
1067
1071
return executeWithNativeSession (new HibernateCallback <Iterator <?>>() {
1068
1072
@ Override
1073
+ @ SuppressWarnings ({"rawtypes" , "deprecation" })
1069
1074
public Iterator <?> doInHibernate (Session session ) throws HibernateException {
1070
- Query queryObject = session .createQuery (queryString );
1075
+ org . hibernate . Query queryObject = session .createQuery (queryString );
1071
1076
prepareQuery (queryObject );
1072
1077
if (values != null ) {
1073
1078
for (int i = 0 ; i < values .length ; i ++) {
@@ -1093,8 +1098,9 @@ public void closeIterator(Iterator<?> it) throws DataAccessException {
1093
1098
public int bulkUpdate (final String queryString , final Object ... values ) throws DataAccessException {
1094
1099
return executeWithNativeSession (new HibernateCallback <Integer >() {
1095
1100
@ Override
1101
+ @ SuppressWarnings ({"rawtypes" , "deprecation" })
1096
1102
public Integer doInHibernate (Session session ) throws HibernateException {
1097
- Query queryObject = session .createQuery (queryString );
1103
+ org . hibernate . Query queryObject = session .createQuery (queryString );
1098
1104
prepareQuery (queryObject );
1099
1105
if (values != null ) {
1100
1106
for (int i = 0 ; i < values .length ; i ++) {
@@ -1122,7 +1128,7 @@ public Integer doInHibernate(Session session) throws HibernateException {
1122
1128
* @see FlushMode#MANUAL
1123
1129
*/
1124
1130
protected void checkWriteOperationAllowed (Session session ) throws InvalidDataAccessApiUsageException {
1125
- if (isCheckWriteOperations () && session .getFlushMode ().lessThan (FlushMode .COMMIT )) {
1131
+ if (isCheckWriteOperations () && SessionFactoryUtils .getFlushMode (session ).lessThan (FlushMode .COMMIT )) {
1126
1132
throw new InvalidDataAccessApiUsageException (
1127
1133
"Write operations are not allowed in read-only mode (FlushMode.MANUAL): " +
1128
1134
"Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition." );
@@ -1136,7 +1142,8 @@ protected void checkWriteOperationAllowed(Session session) throws InvalidDataAcc
1136
1142
* @see #setCacheQueries
1137
1143
* @see #setQueryCacheRegion
1138
1144
*/
1139
- protected void prepareQuery (Query queryObject ) {
1145
+ @ SuppressWarnings ({"rawtypes" , "deprecation" })
1146
+ protected void prepareQuery (org .hibernate .Query queryObject ) {
1140
1147
if (isCacheQueries ()) {
1141
1148
queryObject .setCacheable (true );
1142
1149
if (getQueryCacheRegion () != null ) {
@@ -1192,7 +1199,8 @@ protected void prepareCriteria(Criteria criteria) {
1192
1199
* @param value the value of the parameter
1193
1200
* @throws HibernateException if thrown by the Query object
1194
1201
*/
1195
- protected void applyNamedParameterToQuery (Query queryObject , String paramName , Object value )
1202
+ @ SuppressWarnings ({"rawtypes" , "deprecation" })
1203
+ protected void applyNamedParameterToQuery (org .hibernate .Query queryObject , String paramName , Object value )
1196
1204
throws HibernateException {
1197
1205
1198
1206
if (value instanceof Collection ) {
@@ -1221,6 +1229,7 @@ public CloseSuppressingInvocationHandler(Session target) {
1221
1229
}
1222
1230
1223
1231
@ Override
1232
+ @ SuppressWarnings ("deprecation" )
1224
1233
public Object invoke (Object proxy , Method method , Object [] args ) throws Throwable {
1225
1234
// Invocation on Session interface coming in...
1226
1235
@@ -1243,8 +1252,8 @@ else if (method.getName().equals("close")) {
1243
1252
1244
1253
// If return value is a Query or Criteria, apply transaction timeout.
1245
1254
// Applies to createQuery, getNamedQuery, createCriteria.
1246
- if (retVal instanceof Query ) {
1247
- prepareQuery (((Query ) retVal ));
1255
+ if (retVal instanceof org . hibernate . Query ) {
1256
+ prepareQuery (((org . hibernate . Query ) retVal ));
1248
1257
}
1249
1258
if (retVal instanceof Criteria ) {
1250
1259
prepareCriteria (((Criteria ) retVal ));
0 commit comments