Skip to content

Commit

Permalink
Merge pull request #24 from T-baby/dev
Browse files Browse the repository at this point in the history
支持java6
  • Loading branch information
T-baby authored Oct 13, 2016
2 parents fd12d7c + fc0e1cf commit 62e9a2f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/cybermkd/kit/MongoIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MongoIndex extends IndexOptions {

private Bson bson;

private List<IndexModel> indexModels = new ArrayList<>();
private List<IndexModel> indexModels = new ArrayList<IndexModel>();

public MongoIndex(String collectionName) {
this.collectionName = collectionName;
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/com/cybermkd/kit/MongoKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void apply(Document document) {
return list;
}

public <T> List<T> aggregate(String collectionName, List<Bson> query, boolean allowDiskUse, Class<T> clazz) {
public <T> List<T> aggregate(String collectionName, List<Bson> query, boolean allowDiskUse, final Class<T> clazz) {

final List list = new ArrayList();

Expand Down Expand Up @@ -140,7 +140,7 @@ public <T> T findOne(String collectionName, Bson query, Bson sort, String join,
}

public List<JSONObject> find(String collectionName, Bson query, Bson sort, Bson projection, int limit,
int skip, String join) {
int skip, final String join) {

final List<JSONObject> list = new ArrayList<JSONObject>();

Expand All @@ -159,7 +159,7 @@ public void apply(Document document) {
}

public <T> List<T> find(String collectionName, Bson query, Bson sort, Bson projection, int limit, int skip,
String join, Class<T> clazz) {
final String join, final Class<T> clazz) {

final List list = new ArrayList();

Expand Down Expand Up @@ -214,7 +214,11 @@ public String validation(Object obj) {
Set<ConstraintViolation<Object>> constraintViolations = validator
.validate(obj);//验证某个对象,其实也可以只验证其中的某一个属性的

constraintViolations.forEach((ConstraintViolation c) -> buffer.append(c.getMessage()));
Iterator iter = constraintViolations.iterator();
while(iter.hasNext()){
ConstraintViolation c= (ConstraintViolation) iter.next();
buffer.append(c.getMessage());
}

return buffer.toString();
}
Expand All @@ -227,7 +231,7 @@ public String validation(Object obj, String[] keys) {
Validator validator = Validation.buildDefaultValidatorFactory()
.getValidator();

Set<ConstraintViolation<Object>> constraintViolations = new HashSet<>();
Set<ConstraintViolation<Object>> constraintViolations = new HashSet<ConstraintViolation<Object>>();

for (String key : keys) {
Iterator<ConstraintViolation<Object>> it = validator.validateProperty(obj, key).iterator();
Expand All @@ -238,7 +242,11 @@ public String validation(Object obj, String[] keys) {
}


constraintViolations.forEach((ConstraintViolation c) -> buffer.append(c.getMessage()));
Iterator iter = constraintViolations.iterator();
while(iter.hasNext()){
ConstraintViolation c= (ConstraintViolation) iter.next();
buffer.append(c.getMessage());
}

return buffer.toString();
}
Expand All @@ -253,7 +261,7 @@ public List<String> setIndex(String collectionName, List<IndexModel> list) {

public List<JSONObject> getIndex(String collectionName) {

List list = new ArrayList();
final List list = new ArrayList();

Block<Document> block = new Block<Document>() {

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/cybermkd/kit/MongoQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import org.bson.conversions.Bson;
import org.bson.types.ObjectId;

import javax.validation.ConstraintViolation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -196,9 +198,12 @@ public MongoQuery size(String key, int size) {
public MongoQuery in(String key, List values) {
if ("_id".equals(key)) {
List<ObjectId> idList = new ArrayList<ObjectId>();
values.forEach(value -> {

Iterator iter = values.iterator();
while(iter.hasNext()){
Object value= (Object) iter.next();
idList.add(new ObjectId(String.valueOf(value)));
});
}
query.add(Filters.in(key, idList));
} else {
query.add(Filters.in(key, values));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/cybermkd/plugin/MongoPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class MongoPlugin {

private MongoClientOptions.Builder options = MongoClientOptions.builder();

private List<ServerAddress> hostList = new ArrayList<>();
private List<ServerAddress> hostList = new ArrayList<ServerAddress>();

private List<MongoCredential> authList = new ArrayList<>();
private List<MongoCredential> authList = new ArrayList<MongoCredential>();

/*数据库名*/
private String database;
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/com/cybermkd/validation/TypeValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ public void initialize(Type type) {

@Override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
switch (value) {
case "int":
return isInt(s);
case "double":
return isDouble(s);
case "boolean":
return isDouble(s);
default:
return true;
if (value.equals("int")) {
return isInt(s);
} else if (value.equals("double")) {
return isDouble(s);
} else if (value.equals("boolean")) {
return isDouble(s);
} else {
return true;
}
}

Expand Down

0 comments on commit 62e9a2f

Please sign in to comment.