Skip to content

Commit

Permalink
update 断言相关
Browse files Browse the repository at this point in the history
  • Loading branch information
HbnKing committed Dec 13, 2023
1 parent d669f18 commit 9eb1373
Show file tree
Hide file tree
Showing 2 changed files with 2,954 additions and 187 deletions.
47 changes: 23 additions & 24 deletions mars-core/src/main/java/com/whaleal/mars/session/DatastoreImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import com.mongodb.client.result.UpdateResult;
import com.mongodb.lang.Nullable;
import com.whaleal.icefrog.core.collection.ListUtil;
import com.whaleal.icefrog.core.lang.Precondition;
import com.whaleal.icefrog.core.map.MapUtil;
import com.whaleal.icefrog.core.util.ObjectUtil;
import com.whaleal.icefrog.core.util.OptionalUtil;
Expand Down Expand Up @@ -95,7 +94,7 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;

import static com.whaleal.icefrog.core.lang.Precondition.*;
import static com.whaleal.mars.util.Assert.*;


/**
Expand Down Expand Up @@ -183,7 +182,7 @@ public < T > boolean collectionExists( Class< T > entityClass ) {

@Override
public boolean collectionExists( String collectionName ) {
Precondition.notNull(collectionName, "CollectionName must not be null");
notNull(collectionName, "CollectionName must not be null");
for (String name : this.getDatabase().listCollectionNames()) {
if (collectionName.equals(name)) {
return true;
Expand Down Expand Up @@ -234,27 +233,27 @@ public < T > MongoCollection< T > getCollection( Class< T > type, String collect

@Override
public Document executeCommand( String jsonCommand ) {
Precondition.notNull(jsonCommand);
notNull(jsonCommand);
return this.database.runCommand(Document.parse(jsonCommand));
}

@Override
public Document executeCommand( Document command ) {
Precondition.notNull(command);
notNull(command);
return this.database.runCommand(command);
}

@Override
public Document executeCommand( Document command, ReadPreference readPreference ) {
Precondition.notNull(command);
notNull(command);
return this.database.runCommand(command, readPreference);
}

@Override
public boolean exists( Query query, Class< ? > entityClass, String collectionName ) {

Precondition.notNull(query, "Query can not be null");
Precondition.hasText(collectionName, "CollectionName passed in to exist can't be null");
notNull(query, "Query can not be null");
hasText(collectionName, "CollectionName passed in to exist can't be null");

Optional< ? > o = doFindOne(query, entityClass, collectionName);
return o.isPresent();
Expand All @@ -264,10 +263,10 @@ public boolean exists( Query query, Class< ? > entityClass, String collectionNam
@Override
public < T > UpdateResult replace( Query query, T replacement, ReplaceOptions options, String collectionName ) {

Precondition.notNull(query, "Query must not be null");
Precondition.hasText(collectionName, "Collection name must not be null or empty");
Precondition.notNull(replacement, "Replacement must not be null!");
Precondition.notNull(options, "Options must not be null Use ReplaceOptions#new() instead");
notNull(query, "Query must not be null");
hasText(collectionName, "Collection name must not be null or empty");
notNull(replacement, "Replacement must not be null!");
notNull(options, "Options must not be null Use ReplaceOptions#new() instead");

MongoCollection< T > collection = this.getCollection((Class< T >) replacement.getClass(), collectionName);

Expand Down Expand Up @@ -332,8 +331,8 @@ public com.mongodb.client.result.DeleteResult deleteMulti( Query query, Class< ?
@SuppressWarnings("ConstantConditions")
protected < T > com.mongodb.client.result.DeleteResult doDelete( Query query, @Nullable Class< T > entityClass, String collectionName, com.mongodb.client.model.DeleteOptions options,
boolean multi ) {
Precondition.notNull(query, "Query must not be null");
Precondition.hasText(collectionName, "Collection name must not be null or empty");
notNull(query, "Query must not be null");
hasText(collectionName, "Collection name must not be null or empty");

if (query.getHint() != null) {
String hint = query.getHint();
Expand Down Expand Up @@ -388,8 +387,8 @@ protected < T > com.mongodb.client.result.DeleteResult doDelete( Query query, @N
}

protected < T > FindIterable< T > doFind( Query query, @Nullable Class< T > entityClass, String collectionName ) {
Precondition.notNull(query, "Query must not be null");
Precondition.hasText(collectionName, "CollectionName must not be null or empty");
notNull(query, "Query must not be null");
hasText(collectionName, "CollectionName must not be null or empty");

MongoCollection< T > collection = this.getCollection(entityClass, collectionName);

Expand Down Expand Up @@ -490,8 +489,8 @@ public < T > Optional< T > findById( Object id, Class< T > entityClass, String c

// @Override
private < T > T doInsertOne( T entity, InsertOneOptions options, String collectionName ) {
Precondition.notNull(entity, "entity must not be null");
Precondition.hasText(collectionName, "collectionName must not be null");
notNull(entity, "entity must not be null");
hasText(collectionName, "collectionName must not be null");



Expand Down Expand Up @@ -671,7 +670,7 @@ public UpdateResult upsert( Query query, UpdateDefinition update, String collect
@Override
public UpdateResult upsert( Query query, UpdateDefinition update, Class< ? > entityClass, String collectionName ) {

Precondition.notNull(entityClass, "EntityClass must not be null");
notNull(entityClass, "EntityClass must not be null");

return doUpdate(collectionName, query, update, entityClass, true, false);
}
Expand All @@ -689,7 +688,7 @@ public UpdateResult updateFirst( Query query, UpdateDefinition update, String co
@Override
public UpdateResult updateFirst( Query query, UpdateDefinition update, Class< ? > entityClass, String collectionName ) {

Precondition.notNull(entityClass, "EntityClass must not be null");
notNull(entityClass, "EntityClass must not be null");

return doUpdate(collectionName, query, update, entityClass, false, false);
}
Expand All @@ -707,7 +706,7 @@ public UpdateResult updateMulti( Query query, UpdateDefinition update, String co
@Override
public UpdateResult updateMulti( Query query, UpdateDefinition update, Class< ? > entityClass, String collectionName ) {

Precondition.notNull(entityClass, "EntityClass must not be null");
notNull(entityClass, "EntityClass must not be null");

return doUpdate(collectionName, query, update, entityClass, false, true);
}
Expand Down Expand Up @@ -742,9 +741,9 @@ public < T > T save( T entity, String collectionName ) {
protected < T > UpdateResult doUpdate( String collectionName, Query query, UpdateDefinition update,
@Nullable Class< ? > entityClass, boolean upsert, boolean multi ) {

Precondition.notNull(collectionName, "CollectionName must not be null");
Precondition.notNull(query, "Query must not be null");
Precondition.notNull(update, "Update must not be null");
notNull(collectionName, "CollectionName must not be null");
notNull(query, "Query must not be null");
notNull(update, "Update must not be null");

if (query.isSorted() && LOGGER.isWarnEnabled()) {

Expand Down
Loading

0 comments on commit 9eb1373

Please sign in to comment.