ソースを参照

优化代码逻辑

zhouhao 8 年 前
コミット
f78614ab8c

+ 2 - 7
hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/datasource/DataSourceHolder.java

@@ -33,13 +33,8 @@ public class DataSourceHolder {
 
     public void init(DataSource dataSource) throws SQLException {
         if (null != dataSource) {
-            Connection connection = null;
-            try {
-                connection = dataSource.getConnection();
+            try (Connection connection = dataSource.getConnection()) {
                 install(dataSource, DatabaseType.fromJdbcUrl(connection.getMetaData().getURL()));
-            } finally {
-                if (null != connection)
-                    connection.close();
             }
         }
     }
@@ -83,7 +78,7 @@ public class DataSourceHolder {
 
     public static void install(DataSource dataSource, DatabaseType databaseType) {
         if (DataSourceHolder.defaultDataSource != null) {
-           return;
+            return;
         }
         DataSourceHolder.defaultDataSource = dataSource;
         DataSourceHolder.defaultDatabaseType = databaseType;

+ 1 - 1
hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/datasource/DynamicDataSource.java

@@ -64,7 +64,7 @@ public interface DynamicDataSource extends DataSource {
      * @param rememberLast 是否记住上一次选中的数据源
      */
     static void useDefault(boolean rememberLast) {
-        if (getActiveDataSourceId() != null && rememberLast)
+        if (rememberLast && null != getActiveDataSourceId())
             ThreadLocalUtils.put(DATA_SOURCE_FLAG_LAST, getActiveDataSourceId());
         ThreadLocalUtils.remove(DATA_SOURCE_FLAG);
     }

+ 0 - 6
hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/SqlBuilder.java

@@ -22,13 +22,7 @@ package org.hswebframework.web.dao.mybatis.builder;
  * @author zhouhao
  */
 public class SqlBuilder {
-    private static boolean dynamic;
-
     public static final Object current() {
         return EasyOrmSqlBuilder.getInstance();
     }
-
-    public static void setDynamic(boolean dynamic) {
-        SqlBuilder.dynamic = dynamic;
-    }
 }

+ 1 - 1
hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/CloneableEntity.java

@@ -6,5 +6,5 @@ package org.hswebframework.web.commons.entity;
  * @author zhouhao
  */
 public interface CloneableEntity extends Entity, Cloneable {
-    <T extends CloneableEntity> T clone();
+    CloneableEntity clone();
 }

+ 1 - 0
hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/GenericEntity.java

@@ -38,6 +38,7 @@ public interface GenericEntity<PK> extends CloneableEntity {
 
     void setProperties(Map<String, Object> properties);
 
+    @SuppressWarnings("unchecked")
     default <T> T getProperty(String propertyName, T defaultValue) {
         Map<String, Object> map = getProperties();
         if (map == null) return null;

+ 1 - 1
hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SimpleGenericEntity.java

@@ -70,5 +70,5 @@ public abstract class SimpleGenericEntity<PK> implements GenericEntity<PK> {
     }
 
     @Override
-    public abstract SimpleGenericEntity<PK> clone();
+    public abstract CloneableEntity clone();
 }

+ 1 - 0
hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/factory/MapperEntityFactory.java

@@ -61,6 +61,7 @@ public class MapperEntityFactory implements EntityFactory {
                     realTypeMapper.put(beanClass, mapper);
                     return mapper.getInstanceGetter().get();
                 } catch (ClassNotFoundException e) {
+                    throw new NotFoundException(e.getMessage());
                 }
             }
         }

+ 1 - 0
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserEntity.java

@@ -48,4 +48,5 @@ public interface UserEntity extends UserReadEntity, GenericEntity<String> {
 
     void setLastLoginIp(String lastLoginIp);
 
+    UserEntity clone();
 }

+ 0 - 15
hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-simple/src/test/java/org/hswebframework/web/service/config/ConfigServiceTests.java

@@ -1,15 +0,0 @@
-package org.hswebframework.web.service.config;
-
-import org.hswebframework.web.service.config.simple.SimpleConfigService;
-
-/**
- * TODO 完成注释
- *
- * @author zhouhao
- */
-public class ConfigServiceTests {
-    public static void main(String[] args) {
-        SimpleConfigService configService =new SimpleConfigService();
-//        System.out.println(new SimpleConfigService().createEntity());
-    }
-}