Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
5be0362d
Commit
5be0362d
authored
Apr 15, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some code warning
parent
0ac426a6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
47 deletions
+39
-47
pom.xml
apollo-biz/pom.xml
+5
-14
TitanEntityManager.java
...a/com/ctrip/apollo/biz/datasource/TitanEntityManager.java
+1
-1
ViewService.java
...c/main/java/com/ctrip/apollo/biz/service/ViewService.java
+6
-6
BeanUtils.java
...rc/main/java/com/ctrip/apollo/common/utils/BeanUtils.java
+27
-26
No files found.
apollo-biz/pom.xml
View file @
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
View file @
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
View file @
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
View file @
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"
};
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment