rsanchez
2014-12-12 81fc4995eac73c31ad7539226981d3757d3692e6
#2140 fix - Config change to avoid cache in hibernate
2 files modified
changed files
securis/src/main/java/net/curisit/securis/services/LicenseResource.java patch | view | blame | history
securis/src/main/resources/META-INF/persistence.xml patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/LicenseResource.java
....@@ -9,6 +9,8 @@
99 import javax.inject.Inject;
1010 import javax.inject.Provider;
1111 import javax.persistence.EntityManager;
12
+import javax.persistence.PersistenceContext;
13
+import javax.persistence.SynchronizationType;
1214 import javax.persistence.TypedQuery;
1315 import javax.ws.rs.Consumes;
1416 import javax.ws.rs.DELETE;
....@@ -84,6 +86,9 @@
8486
8587 @Inject
8688 private Provider<EntityManager> emProvider;
89
+
90
+ @PersistenceContext(unitName = "localdb", synchronization = SynchronizationType.SYNCHRONIZED)
91
+ private EntityManager entityManager;
8792
8893 @Inject
8994 private LicenseGenerator licenseGenerator;
....@@ -195,22 +200,19 @@
195200
196201 if (!License.Status.isActionValid(License.Action.ACTIVATION, lic.getStatus())) {
197202 LOG.error("License with id {} can not be activated from current license status", licId);
198
- throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "License with id " + licId
203
+ throw new SeCurisServiceException(ErrorCodes.INVALID_DATA, "License with id " + licId
199204 + " can not be activated from the current license status");
200205 }
201206
202207 if (lic.getPack().getNumAvailables() == 0) {
203
- throw new SeCurisServiceException(Status.FORBIDDEN.getStatusCode(), "The pack has not available licenses");
208
+ throw new SeCurisServiceException(ErrorCodes.NO_AVAILABLE_LICENSES, "The pack has not available licenses");
204209 }
205210
206211 validateRequestData(lic.getPack(), lic.getRequestData());
207212
208213 License existingLicense = License.findLicenseByRequestData(lic.getRequestData(), em);
209
- if (existingLicense != null) {
210
- return Response.status(DefaultExceptionHandler.DEFAULT_APP_ERROR_STATUS_CODE)
211
- .header(DefaultExceptionHandler.ERROR_CODE_MESSAGE_HEADER, ErrorCodes.DUPLICATED_REQUEST_DATA)
212
- .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "There is already an active license for current request data")
213
- .type(MediaType.APPLICATION_JSON).entity(existingLicense).build();
214
+ if (existingLicense != null && existingLicense.getStatus() == LicenseStatus.ACTIVE) {
215
+ throw new SeCurisServiceException(ErrorCodes.NO_AVAILABLE_LICENSES, "The pack has not available licenses");
214216 }
215217
216218 lic.setStatus(LicenseStatus.ACTIVE);
securis/src/main/resources/META-INF/persistence.xml
....@@ -12,9 +12,11 @@
1212 <!-- <class>net.curisit.securis.db.UserSettingsUnits</class> -->
1313
1414 <properties>
15
+ <property name="hibernate.cache.provider_class" value="org.hibernate.cache.internal.NoCachingRegionFactory"/>
1516 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
1617 <property name="hibernate.connection.datasource" value="java:comp/env/jdbc/SeCurisDS" />
1718
19
+ <property name="hibernate.cache.use_second_level_cache" value="false" />
1820 <property name="hibernate.show_sql" value="false" />
1921
2022 <!-- <property name="hibernate.format_sql" value="true"/>