br.com.anteros.nosql.persistence.mongodb.session.MongoEntityAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Anteros-NoSql-Persistence-MongoDB Show documentation
Show all versions of Anteros-NoSql-Persistence-MongoDB Show documentation
Anteros NoSQL Persistence MongoDB.
package br.com.anteros.nosql.persistence.mongodb.session;
import java.util.LinkedHashMap;
import org.bson.Document;
import org.bson.types.ObjectId;
import br.com.anteros.nosql.persistence.metadata.NoSQLDescriptionEntity;
import br.com.anteros.nosql.persistence.metadata.NoSQLDescriptionField;
import br.com.anteros.nosql.persistence.mongodb.mapping.MongoObjectMapper;
import br.com.anteros.nosql.persistence.mongodb.query.MongoCriteria;
import br.com.anteros.nosql.persistence.mongodb.query.MongoQuery;
import br.com.anteros.nosql.persistence.proxy.ProxyHelper;
import br.com.anteros.nosql.persistence.session.NoSQLEntityAdapter;
import br.com.anteros.nosql.persistence.session.NoSQLMappedDocument;
import br.com.anteros.nosql.persistence.session.mapping.AbstractNoSQLObjectMapper;
import br.com.anteros.nosql.persistence.session.query.NoSQLQuery;
public class MongoEntityAdapter implements NoSQLEntityAdapter {
private T entity;
private NoSQLDescriptionEntity descriptionEntity;
private AbstractNoSQLObjectMapper mapper;
private MongoEntityAdapter(T entity, NoSQLDescriptionEntity descriptionEntity, AbstractNoSQLObjectMapper mapper) {
this.entity = entity;
this.descriptionEntity = descriptionEntity;
this.mapper = mapper;
}
public static MongoEntityAdapter of(T entity, NoSQLDescriptionEntity descriptionEntity,
AbstractNoSQLObjectMapper mapper) {
return new MongoEntityAdapter<>(entity, descriptionEntity, mapper);
}
@Override
public String getIdFieldName() {
return descriptionEntity.getDescriptionIdField().getName();
}
@Override
public Object getId() {
return descriptionEntity.getDescriptionIdField().getObjectValue(entity);
}
@Override
public NoSQLQuery getByIdQuery() {
Object newId = getId();
if (newId instanceof String) {
newId = new ObjectId(newId.toString());
}
return MongoQuery.of(MongoCriteria.where("_id").is(newId));
}
@Override
public NoSQLQuery getQueryForVersion() {
NoSQLDescriptionField descriptionIdField = descriptionEntity.getDescriptionIdField();
NoSQLDescriptionField descriptionVersionField = descriptionEntity.getDescriptionVersionField();
return MongoQuery
.of(MongoCriteria.where(descriptionIdField.getName()).is(descriptionIdField.getObjectValue(entity))//
.and(descriptionVersionField.getName()).is(descriptionVersionField.getObjectValue(entity)));
}
@Override
public NoSQLMappedDocument toMappedDocument() {
final LinkedHashMap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy