use of com.mongodb.lang.Nullable in project morphia by mongodb.
the class Mapper method getId.
/**
* Gets the ID value for an entity
*
* @param entity the entity to process
* @return the ID value
*/
@Nullable
public Object getId(@Nullable Object entity) {
if (entity == null) {
return null;
}
try {
final EntityModel model = getEntityModel(entity.getClass());
final PropertyModel idField = model.getIdProperty();
if (idField != null) {
return idField.getValue(entity);
}
} catch (NotMappableException ignored) {
}
return null;
}
use of com.mongodb.lang.Nullable in project morphia by mongodb.
the class ReferenceCodec method encodeId.
/**
* Encodes a value
*
* @param mapper
* @param value the value to encode
* @param model the mapped class of the field type
* @return the encoded value
* @morphia.internal
*/
@Nullable
public static Object encodeId(Mapper mapper, Object value, EntityModel model) {
Object idValue;
Class<?> type;
if (value instanceof Key) {
idValue = ((Key) value).getId();
String collectionName = ((Key<?>) value).getCollection();
type = collectionName != null ? mapper.getClassFromCollection(collectionName) : ((Key<?>) value).getType();
if (type == null) {
throw new MappingException("The type for the reference could not be determined for the key " + value);
}
} else {
idValue = mapper.getId(value);
if (idValue == null) {
return !mapper.isMappable(value.getClass()) ? value : null;
}
type = value.getClass();
}
String valueCollectionName = mapper.getEntityModel(type).getCollectionName();
String fieldCollectionName = model.getCollectionName();
Reference annotation = model.getAnnotation(Reference.class);
if (annotation != null && !annotation.idOnly() || valueCollectionName != null && !valueCollectionName.equals(fieldCollectionName)) {
idValue = new DBRef(valueCollectionName, idValue);
}
return idValue;
}
use of com.mongodb.lang.Nullable in project mongo-java-driver by mongodb.
the class ClusterFixture method getOverriddenStreamFactoryFactory.
@Nullable
public static StreamFactoryFactory getOverriddenStreamFactoryFactory() {
String streamType = System.getProperty("org.mongodb.test.async.type", "nio2");
if (nettyStreamFactoryFactory == null && streamType.equals("netty")) {
NettyStreamFactoryFactory.Builder builder = NettyStreamFactoryFactory.builder();
String sslProvider = System.getProperty("org.mongodb.test.netty.ssl.provider");
if (sslProvider != null) {
SslContext sslContext;
try {
sslContext = SslContextBuilder.forClient().sslProvider(SslProvider.valueOf(sslProvider)).build();
} catch (SSLException e) {
throw new MongoClientException("Unable to create Netty SslContext", e);
}
builder.sslContext(sslContext);
}
nettyStreamFactoryFactory = builder.build();
}
return nettyStreamFactoryFactory;
}
use of com.mongodb.lang.Nullable in project mongo-java-driver by mongodb.
the class MongoClientDelegate method createClientSession.
@Nullable
public ClientSession createClientSession(final ClientSessionOptions options, final ReadConcern readConcern, final WriteConcern writeConcern, final ReadPreference readPreference) {
notNull("readConcern", readConcern);
notNull("writeConcern", writeConcern);
notNull("readPreference", readPreference);
ClusterDescription connectedClusterDescription = getConnectedClusterDescription();
if (connectedClusterDescription.getLogicalSessionTimeoutMinutes() == null && connectedClusterDescription.getConnectionMode() != ClusterConnectionMode.LOAD_BALANCED) {
return null;
} else {
ClientSessionOptions mergedOptions = ClientSessionOptions.builder(options).defaultTransactionOptions(TransactionOptions.merge(options.getDefaultTransactionOptions(), TransactionOptions.builder().readConcern(readConcern).writeConcern(writeConcern).readPreference(readPreference).build())).build();
return new ClientSessionImpl(serverSessionPool, originator, mergedOptions, this);
}
}
use of com.mongodb.lang.Nullable in project mongo-java-driver by mongodb.
the class Crypt method fetchKeys.
private void fetchKeys(final MongoCryptContext cryptContext, @Nullable final String databaseName, final MonoSink<RawBsonDocument> sink) {
keyRetriever.find(cryptContext.getMongoOperation()).doOnSuccess(results -> {
for (BsonDocument result : results) {
cryptContext.addMongoOperationResult(result);
}
cryptContext.completeMongoOperation();
executeStateMachineWithSink(cryptContext, databaseName, sink);
}).doOnError(t -> sink.error(MongoException.fromThrowableNonNull(t))).subscribe();
}
Aggregations