Polish.
This commit is contained in:
@@ -109,11 +109,9 @@ public abstract class AbstractMongoSessionConverter implements GenericConverter
|
||||
|
||||
if (DBObject.class.isAssignableFrom(sourceType.getType())) {
|
||||
return convert(new Document(((DBObject) source).toMap()));
|
||||
}
|
||||
else if (Document.class.isAssignableFrom(sourceType.getType())) {
|
||||
} else if (Document.class.isAssignableFrom(sourceType.getType())) {
|
||||
return convert((Document) source);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return convert((MongoSession) source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public JacksonMongoSessionConverter() {
|
||||
this(Collections.<Module>emptyList());
|
||||
this(Collections.emptyList());
|
||||
}
|
||||
|
||||
public JacksonMongoSessionConverter(Iterable<Module> modules) {
|
||||
@@ -66,9 +66,10 @@ public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter
|
||||
|
||||
if (FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) {
|
||||
return Query.query(Criteria.where(PRINCIPAL_FIELD_NAME).is(indexValue));
|
||||
}
|
||||
return Query.query(Criteria.where(ATTRS_FIELD_NAME +
|
||||
} else {
|
||||
return Query.query(Criteria.where(ATTRS_FIELD_NAME +
|
||||
MongoSession.coverDot(indexName)).is(indexValue));
|
||||
}
|
||||
}
|
||||
|
||||
private ObjectMapper buildObjectMapper() {
|
||||
@@ -94,8 +95,7 @@ public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter
|
||||
DBObject dbSession = (DBObject) JSON.parse(this.objectMapper.writeValueAsString(source));
|
||||
dbSession.put(PRINCIPAL_FIELD_NAME, extractPrincipal(source));
|
||||
return dbSession;
|
||||
}
|
||||
catch (JsonProcessingException e) {
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalStateException("Cannot convert MongoExpiringSession", e);
|
||||
}
|
||||
}
|
||||
@@ -107,8 +107,7 @@ public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter
|
||||
|
||||
try {
|
||||
return this.objectMapper.readValue(json, MongoSession.class);
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
LOG.error("Error during Mongo Session deserialization", e);
|
||||
return null;
|
||||
}
|
||||
@@ -120,11 +119,11 @@ public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter
|
||||
public String translate(String propertyName) {
|
||||
if (propertyName.equals("id")) {
|
||||
return "_id";
|
||||
}
|
||||
else if (propertyName.equals("_id")) {
|
||||
} else if (propertyName.equals("_id")) {
|
||||
return "id";
|
||||
} else {
|
||||
return propertyName;
|
||||
}
|
||||
return propertyName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,14 +76,16 @@ public class JdkMongoSessionConverter extends AbstractMongoSessionConverter {
|
||||
if (FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME
|
||||
.equals(indexName)) {
|
||||
return Query.query(Criteria.where(PRINCIPAL_FIELD_NAME).is(indexValue));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DBObject convert(MongoSession session) {
|
||||
|
||||
BasicDBObject basicDBObject = new BasicDBObject();
|
||||
|
||||
basicDBObject.put(ID, session.getId());
|
||||
basicDBObject.put(CREATION_TIME, session.getCreationTime());
|
||||
basicDBObject.put(LAST_ACCESSED_TIME, session.getLastAccessedTime());
|
||||
@@ -91,6 +93,7 @@ public class JdkMongoSessionConverter extends AbstractMongoSessionConverter {
|
||||
basicDBObject.put(PRINCIPAL_FIELD_NAME, extractPrincipal(session));
|
||||
basicDBObject.put(EXPIRE_AT_FIELD_NAME, session.getExpireAt());
|
||||
basicDBObject.put(ATTRIBUTES, serializeAttributes(session));
|
||||
|
||||
return basicDBObject;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,8 @@ package org.springframework.session.data.mongo;
|
||||
|
||||
import static org.springframework.session.data.mongo.MongoSessionUtils.*;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.bson.Document;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
|
||||
import org.springframework.session.ReactorSessionRepository;
|
||||
|
||||
@@ -42,8 +39,7 @@ public class ReactiveMongoOperationsSessionRepository implements ReactorSessionR
|
||||
|
||||
private final ReactiveMongoOperations mongoOperations;
|
||||
|
||||
private AbstractMongoSessionConverter mongoSessionConverter =
|
||||
SessionConverterProvider.getDefaultMongoConverter();
|
||||
private AbstractMongoSessionConverter mongoSessionConverter = SessionConverterProvider.getDefaultMongoConverter();
|
||||
|
||||
private Integer maxInactiveIntervalInSeconds = DEFAULT_INACTIVE_INTERVAL;
|
||||
private String collectionName = DEFAULT_COLLECTION_NAME;
|
||||
@@ -67,15 +63,9 @@ public class ReactiveMongoOperationsSessionRepository implements ReactorSessionR
|
||||
@Override
|
||||
public Mono<MongoSession> createSession() {
|
||||
|
||||
return Mono.defer(() -> {
|
||||
MongoSession session = new MongoSession();
|
||||
|
||||
if (this.maxInactiveIntervalInSeconds != null) {
|
||||
session.setMaxInactiveInterval(Duration.ofSeconds(this.maxInactiveIntervalInSeconds));
|
||||
}
|
||||
|
||||
return Mono.just(session);
|
||||
});
|
||||
return Mono.justOrEmpty(this.maxInactiveIntervalInSeconds)
|
||||
.map(MongoSession::new)
|
||||
.switchIfEmpty(Mono.just(new MongoSession()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +101,7 @@ public class ReactiveMongoOperationsSessionRepository implements ReactorSessionR
|
||||
return findSession(id)
|
||||
.map(document -> convertToSession(this.mongoSessionConverter, document))
|
||||
.filter(mongoSession -> !mongoSession.isExpired())
|
||||
.switchIfEmpty(Mono.defer(() -> delete(id).then(Mono.empty())));
|
||||
.switchIfEmpty(Mono.defer(() -> this.delete(id).then(Mono.empty())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +115,7 @@ public class ReactiveMongoOperationsSessionRepository implements ReactorSessionR
|
||||
return this.mongoOperations.remove(findSession(id), this.collectionName).then();
|
||||
}
|
||||
|
||||
Mono<Document> findSession(String id) {
|
||||
private Mono<Document> findSession(String id) {
|
||||
return this.mongoOperations.findById(id, Document.class, this.collectionName);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.session.data.mongo;
|
||||
package org.springframework.session.data.mongo.config.annotation.web.reactive;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -13,11 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.session.data.mongo;
|
||||
package org.springframework.session.data.mongo.config.annotation.web.reactive;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
|
||||
import org.springframework.session.data.mongo.ReactiveMongoOperationsSessionRepository;
|
||||
|
||||
/**
|
||||
* Configure a {@link ReactiveMongoOperationsSessionRepository} using a provided {@link ReactiveMongoOperations}.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.session.data.mongo;
|
||||
package org.springframework.session.data.mongo.config.annotation.web.reactive;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
Reference in New Issue
Block a user