/** * stores the given EntityInvocationHandler represented Entity in the given Collection * * @param handler EntityInvocationHandler (Entity) to save * @param coll MongoCollection to save entity into */ @SuppressWarnings( "unchecked" ) static <T extends Entity> void save( EntityInvocationHandler handler, MongoCollection<T> coll ) { for ( ParameterProperty cpp : handler.properties.getValidationProperties() ) { cpp.validate( handler.data.get( cpp.getMongoName() ) ); } BsonDocumentWrapper wrapper = new BsonDocumentWrapper<>( handler.proxy, (org.bson.codecs.Encoder<Entity>) coll.getCodecRegistry().get( handler.properties.getEntityClass() ) ); UpdateResult res = coll.updateOne( new BsonDocument( "_id", BsonDocumentWrapper.asBsonDocument( EntityCodec._obtainId( handler.proxy ), idRegistry ) ), new BsonDocument( "$set", wrapper ), new UpdateOptions() ); if ( res.getMatchedCount() == 0 ) { // TODO this seems too nasty, there must be a better way.for now live with it coll.insertOne( (T) handler.proxy ); } handler.persist(); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { System.out.println("toBsonDocument called"); return new BsonDocumentWrapper<SyncConnectionInfo>(this, codecRegistry.get(SyncConnectionInfo.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<SyncUserSession>(this, codecRegistry.get(SyncUserSession.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<SyncNode>(this, codecRegistry.get(SyncNode.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<SyncUser>(this, codecRegistry.get(SyncUser.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<SyncMap>(this, codecRegistry.get(SyncMap.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<MongoToOracleMap>(this, codecRegistry.get(MongoToOracleMap.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<OracleToMongoMap>(this, codecRegistry.get(OracleToMongoMap.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<MongoToOracleEvent>(this, codecRegistry.get(MongoToOracleEvent.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<SyncError>(this, codecRegistry.get(SyncError.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<OracleToMongoEvent>(this, codecRegistry.get(OracleToMongoEvent.class)); }
@SuppressWarnings("rawtypes") @Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<SyncEvent>(this, codecRegistry.get(SyncEvent.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<SyncMarker>(this, codecRegistry.get(SyncMarker.class)); }
default BsonValue asBsonValue(T id, TypeCodecRegistry typeCodecRegistry) { return BsonDocumentWrapper.asBsonDocument(id, typeCodecRegistry.getRegistry()); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> documentClass, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<ChapterBeanImpl>(this, codecRegistry.get(ChapterBeanImpl.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> documentClass, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<AnnotationBeanImpl>(this, codecRegistry.get(AnnotationBeanImpl.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> documentClass, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<UserBeanImpl>(this, codecRegistry.get(UserBeanImpl.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> documentClass, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<BibleBeanImpl>(this, codecRegistry.get(BibleBeanImpl.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> documentClass, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<BookBeanImpl>(this, codecRegistry.get(BookBeanImpl.class)); }
@Override public <TDocument> BsonDocument toBsonDocument(Class<TDocument> documentClass, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<VerseBeanImpl>(this, codecRegistry.get(VerseBeanImpl.class)); }
@Override public <C> BsonDocument toBsonDocument(Class<C> documentClass, CodecRegistry codecRegistry) { return new BsonDocumentWrapper<>(obj, codecRegistry.get(JsonObject.class)); }
/** * Converts the given {@link Object} into a {@link BsonDocument} using the registered * {@link Codec} in the {@link CodecRegistry}. * * @param expression the object to convert * @return the corresponding {@link BsonDocument} or <code>null</code> */ public static BsonDocument asBsonDocument(final Object expression) { return BsonDocumentWrapper.asBsonDocument(expression, codecRegistry); }