mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-09 01:14:16 +08:00
优化代码逻辑
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -70,5 +70,5 @@ public abstract class SimpleGenericEntity<PK> implements GenericEntity<PK> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract SimpleGenericEntity<PK> clone();
|
||||
public abstract CloneableEntity clone();
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,4 +48,5 @@ public interface UserEntity extends UserReadEntity, GenericEntity<String> {
|
||||
|
||||
void setLastLoginIp(String lastLoginIp);
|
||||
|
||||
UserEntity clone();
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user