优化代码逻辑

This commit is contained in:
zhouhao
2017-01-09 10:18:55 +08:00
parent 3f61afa70f
commit f78614ab8c
9 changed files with 8 additions and 31 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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();
}

View File

@@ -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;

View File

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

View File

@@ -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());
}
}
}

View File

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

View File

@@ -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());
}
}