Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
5be0362d
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5be0362d
编写于
4月 15, 2016
作者:
Y
Yiming Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix some code warning
上级
0ac426a6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
47 deletion
+39
-47
apollo-biz/pom.xml
apollo-biz/pom.xml
+5
-14
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanEntityManager.java
...a/com/ctrip/apollo/biz/datasource/TitanEntityManager.java
+1
-1
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ViewService.java
...c/main/java/com/ctrip/apollo/biz/service/ViewService.java
+6
-6
apollo-common/src/main/java/com/ctrip/apollo/common/utils/BeanUtils.java
...rc/main/java/com/ctrip/apollo/common/utils/BeanUtils.java
+27
-26
未找到文件。
apollo-biz/pom.xml
浏览文件 @
5be0362d
...
...
@@ -28,19 +28,10 @@
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>
local
</id>
<activation>
<activeByDefault>
true
</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanEntityManager.java
浏览文件 @
5be0362d
...
...
@@ -23,7 +23,7 @@ public class TitanEntityManager {
Object
obj
=
clazz
.
newInstance
();
Method
method
=
clazz
.
getMethod
(
"createDataSource"
,
new
Class
[]
{
String
.
class
,
String
.
class
});
return
((
DataSource
)
method
.
invoke
(
obj
,
new
String
[]
{
settings
.
getTitanDbname
(),
settings
.
getTitanUrl
()}));
new
Object
[]
{
settings
.
getTitanDbname
(),
settings
.
getTitanUrl
()}));
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ViewService.java
浏览文件 @
5be0362d
...
...
@@ -36,12 +36,12 @@ public class ViewService {
public
List
<
Cluster
>
findClusters
(
String
appId
)
{
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
emptyList
()
;
}
List
<
Cluster
>
clusters
=
clusterRepository
.
findByAppId
(
appId
);
if
(
clusters
==
null
)
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
emptyList
()
;
}
return
clusters
;
}
...
...
@@ -49,7 +49,7 @@ public class ViewService {
public
List
<
Namespace
>
findNamespaces
(
String
appId
,
String
clusterName
)
{
List
<
Namespace
>
groups
=
namespaceRepository
.
findByAppIdAndClusterName
(
appId
,
clusterName
);
if
(
groups
==
null
)
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
emptyList
()
;
}
return
groups
;
}
...
...
@@ -60,14 +60,14 @@ public class ViewService {
if
(
group
!=
null
)
{
return
findItems
(
group
.
getId
());
}
else
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
emptyList
()
;
}
}
public
List
<
Item
>
findItems
(
Long
namespaceId
)
{
List
<
Item
>
items
=
itemRepository
.
findByNamespaceIdOrderByLineNumAsc
(
namespaceId
);
if
(
items
==
null
)
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
emptyList
()
;
}
return
items
;
}
...
...
@@ -76,7 +76,7 @@ public class ViewService {
List
<
Release
>
releases
=
releaseRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
if
(
releases
==
null
)
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
emptyList
()
;
}
return
releases
;
}
...
...
apollo-common/src/main/java/com/ctrip/apollo/common/utils/BeanUtils.java
浏览文件 @
5be0362d
package
com.ctrip.apollo.common.utils
;
import
java.beans.PropertyDescriptor
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.Collections
;
...
...
@@ -22,9 +23,9 @@ public class BeanUtils {
* List<UserDTO> userDTOs = BeanUtil.batchTransform(UserDTO.class, userBeans);
* </pre>
*/
public
static
<
T
>
List
<
T
>
batchTransform
(
final
Class
<
T
>
clazz
,
List
srcList
)
{
public
static
<
T
>
List
<
T
>
batchTransform
(
final
Class
<
T
>
clazz
,
List
<?
extends
Object
>
srcList
)
{
if
(
CollectionUtils
.
isEmpty
(
srcList
))
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
emptyList
()
;
}
List
<
T
>
result
=
new
ArrayList
<>(
srcList
.
size
());
...
...
@@ -56,12 +57,12 @@ public class BeanUtils {
return
instance
;
}
static
String
[]
getNullPropertyNames
(
Object
source
)
{
private
static
String
[]
getNullPropertyNames
(
Object
source
)
{
final
BeanWrapper
src
=
new
BeanWrapperImpl
(
source
);
java
.
beans
.
PropertyDescriptor
[]
pds
=
src
.
getPropertyDescriptors
();
PropertyDescriptor
[]
pds
=
src
.
getPropertyDescriptors
();
Set
<
String
>
emptyNames
=
new
HashSet
<
String
>();
for
(
java
.
beans
.
PropertyDescriptor
pd
:
pds
)
{
for
(
PropertyDescriptor
pd
:
pds
)
{
Object
srcValue
=
src
.
getPropertyValue
(
pd
.
getName
());
if
(
srcValue
==
null
)
emptyNames
.
add
(
pd
.
getName
());
}
...
...
@@ -74,20 +75,21 @@ public class BeanUtils {
*
* <pre>
* List<UserDTO> userList = userService.queryUsers();
* Map<Integer, userDTO> userIdToUser = BeanUtil.mapByKey("userId", Integer.class, userList,
* UserDTO.class);
* Map<Integer, userDTO> userIdToUser = BeanUtil.mapByKey("userId", userList);
* </pre>
*
* @param key 属性名
*/
public
static
<
K
,
V
>
Map
<
K
,
V
>
mapByKey
(
String
key
,
List
list
)
{
@SuppressWarnings
(
"unchecked"
)
public
static
<
K
,
V
>
Map
<
K
,
V
>
mapByKey
(
String
key
,
List
<?
extends
Object
>
list
)
{
Map
<
K
,
V
>
map
=
new
HashMap
<
K
,
V
>();
if
(
CollectionUtils
.
isEmpty
(
list
))
{
return
map
;
}
try
{
Class
clazz
=
list
.
get
(
0
).
getClass
();
Class
<?
extends
Object
>
clazz
=
list
.
get
(
0
).
getClass
();
Field
field
=
deepFindField
(
clazz
,
key
);
if
(
field
==
null
)
throw
new
IllegalArgumentException
(
"Could not find the key"
);
field
.
setAccessible
(
true
);
for
(
Object
o
:
list
)
{
map
.
put
((
K
)
field
.
get
(
o
),
(
V
)
o
);
...
...
@@ -106,14 +108,16 @@ public class BeanUtils {
* Map<Integer, List<ShopDTO>> city2Shops = BeanUtil.aggByKeyToList("cityId", shopList);
* </pre>
*/
public
static
<
K
,
V
>
Map
<
K
,
List
<
V
>>
aggByKeyToList
(
String
key
,
List
list
)
{
@SuppressWarnings
(
"unchecked"
)
public
static
<
K
,
V
>
Map
<
K
,
List
<
V
>>
aggByKeyToList
(
String
key
,
List
<?
extends
Object
>
list
)
{
Map
<
K
,
List
<
V
>>
map
=
new
HashMap
<
K
,
List
<
V
>>();
if
(
CollectionUtils
.
isEmpty
(
list
))
{
// 防止外面传入空list
return
map
;
}
try
{
Class
clazz
=
list
.
get
(
0
).
getClass
();
Class
<?
extends
Object
>
clazz
=
list
.
get
(
0
).
getClass
();
Field
field
=
deepFindField
(
clazz
,
key
);
if
(
field
==
null
)
throw
new
IllegalArgumentException
(
"Could not find the key"
);
field
.
setAccessible
(
true
);
for
(
Object
o
:
list
)
{
K
k
=
(
K
)
field
.
get
(
o
);
...
...
@@ -136,20 +140,19 @@ public class BeanUtils {
* Set<Integer> userIds = BeanUtil.toPropertySet("userId", userList);
* </pre>
*/
public
static
Set
toPropertySet
(
String
key
,
List
list
)
{
Set
set
=
new
HashSet
();
@SuppressWarnings
(
"unchecked"
)
public
static
<
K
>
Set
<
K
>
toPropertySet
(
String
key
,
List
<?
extends
Object
>
list
)
{
Set
<
K
>
set
=
new
HashSet
<
K
>();
if
(
CollectionUtils
.
isEmpty
(
list
))
{
// 防止外面传入空list
return
set
;
}
try
{
Class
clazz
=
list
.
get
(
0
).
getClass
();
Class
<?
extends
Object
>
clazz
=
list
.
get
(
0
).
getClass
();
Field
field
=
deepFindField
(
clazz
,
key
);
if
(
field
==
null
)
{
return
set
;
}
if
(
field
==
null
)
throw
new
IllegalArgumentException
(
"Could not find the key"
);
field
.
setAccessible
(
true
);
for
(
Object
o
:
list
)
{
set
.
add
(
field
.
get
(
o
));
set
.
add
(
(
K
)
field
.
get
(
o
));
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
...
...
@@ -158,7 +161,7 @@ public class BeanUtils {
}
private
static
Field
deepFindField
(
Class
clazz
,
String
key
)
{
private
static
Field
deepFindField
(
Class
<?
extends
Object
>
clazz
,
String
key
)
{
Field
field
=
null
;
while
(!
clazz
.
getName
().
equals
(
Object
.
class
.
getName
()))
{
try
{
...
...
@@ -204,10 +207,6 @@ public class BeanUtils {
}
}
public
static
List
toPropertyList
(
String
key
,
List
list
)
{
return
new
ArrayList
(
toPropertySet
(
key
,
list
));
}
/**
*
* @param source
...
...
@@ -216,7 +215,7 @@ public class BeanUtils {
public
static
void
copyProperties
(
Object
source
,
Object
target
,
String
...
ignoreProperties
)
{
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
source
,
target
,
ignoreProperties
);
}
/**
* The copy will ignore <em>BaseEntity</em> field
*
...
...
@@ -224,7 +223,9 @@ public class BeanUtils {
* @param target
*/
public
static
void
copyEntityProperties
(
Object
source
,
Object
target
)
{
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
source
,
target
,
"id"
,
"dataChangeCreatedBy"
,
"dataChangeCreatedTime"
,
"dataChangeLastModifiedBy"
,
"dataChangeLastModifiedTime"
);
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
source
,
target
,
COPY_IGNORED_PROPERTIES
);
}
private
static
final
String
[]
COPY_IGNORED_PROPERTIES
=
{
"id"
,
"dataChangeCreatedBy"
,
"dataChangeCreatedTime"
,
"dataChangeLastModifiedBy"
,
"dataChangeLastModifiedTime"
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录