AppsService.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.maxkey.persistence.service;
  17. import java.time.Duration;
  18. import java.util.List;
  19. import org.apache.mybatis.jpa.persistence.JpaBaseService;
  20. import org.ehcache.UserManagedCache;
  21. import org.ehcache.config.builders.ExpiryPolicyBuilder;
  22. import org.ehcache.config.builders.UserManagedCacheBuilder;
  23. import org.maxkey.domain.apps.Apps;
  24. import org.maxkey.domain.apps.UserApps;
  25. import org.maxkey.persistence.mapper.AppsMapper;
  26. import org.springframework.stereotype.Repository;
  27. @Repository
  28. public class AppsService extends JpaBaseService<Apps>{
  29. protected final static UserManagedCache<String, Apps> appsDetailsStore =
  30. UserManagedCacheBuilder.newUserManagedCacheBuilder(String.class, Apps.class)
  31. .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofHours(1)))
  32. .build(true);
  33. public AppsService() {
  34. super(AppsMapper.class);
  35. }
  36. /* (non-Javadoc)
  37. * @see com.connsec.db.service.BaseService#getMapper()
  38. */
  39. @Override
  40. public AppsMapper getMapper() {
  41. // TODO Auto-generated method stub
  42. return (AppsMapper)super.getMapper();
  43. }
  44. public boolean insertApp(Apps app) {
  45. return ((AppsMapper)super.getMapper()).insertApp(app)>0;
  46. };
  47. public boolean updateApp(Apps app) {
  48. return ((AppsMapper)super.getMapper()).updateApp(app)>0;
  49. };
  50. public boolean updateExtendAttr(Apps app) {
  51. return ((AppsMapper)super.getMapper()).updateExtendAttr(app)>0;
  52. }
  53. public List<UserApps> queryMyApps(UserApps userApplications){
  54. return getMapper().queryMyApps(userApplications);
  55. }
  56. //cache for running
  57. public void storeCacheAppDetails(String appId, Apps appDetails) {
  58. appsDetailsStore.put(appId, appDetails);
  59. }
  60. public Apps getCacheAppDetails(String appId) {
  61. Apps appDetails=appsDetailsStore.get(appId);
  62. return appDetails;
  63. }
  64. }