Browse Source

add EntityFactory

zhouhao 7 years ago
parent
commit
3e1c073b99

+ 20 - 1
hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/AbstractOAuth2CrudService.java

@@ -2,10 +2,12 @@ package org.hswebframework.web.service.oauth2;
 
 import org.hswebframework.utils.ClassUtils;
 import org.hswebframework.web.authorization.oauth2.client.OAuth2RequestService;
+import org.hswebframework.web.commons.entity.factory.EntityFactory;
+import org.hswebframework.web.service.CreateEntityService;
 import org.springframework.beans.factory.annotation.Autowired;
 
 @SuppressWarnings("unchecked")
-public abstract class AbstractOAuth2CrudService<E, PK> implements OAuth2CrudService<E, PK> {
+public abstract class AbstractOAuth2CrudService<E, PK> implements CreateEntityService<E>, OAuth2CrudService<E, PK> {
 
     private Class<E> entityType;
 
@@ -13,11 +15,23 @@ public abstract class AbstractOAuth2CrudService<E, PK> implements OAuth2CrudServ
 
     private OAuth2RequestService oAuth2RequestService;
 
+    private EntityFactory entityFactory;
+
     public AbstractOAuth2CrudService() {
         entityType = (Class) ClassUtils.getGenericType(this.getClass(), 0);
         primaryKeyType = (Class) ClassUtils.getGenericType(this.getClass(), 1);
     }
 
+    @Override
+    public E createEntity() {
+        return entityFactory.newInstance(entityType);
+    }
+
+    @Override
+    public Class<E> getEntityInstanceType() {
+        return entityType;
+    }
+
     @Override
     public OAuth2RequestService getRequestService() {
         return oAuth2RequestService;
@@ -39,6 +53,11 @@ public abstract class AbstractOAuth2CrudService<E, PK> implements OAuth2CrudServ
         return primaryKeyType;
     }
 
+    @Autowired
+    public void setEntityFactory(EntityFactory entityFactory) {
+        this.entityFactory = entityFactory;
+    }
+
     @Autowired
     public void setoAuth2RequestService(OAuth2RequestService oAuth2RequestService) {
         this.oAuth2RequestService = oAuth2RequestService;