Skip to content

Provide lifecycle events when using QueryDSL [DATAMONGO-1185] #2104

Closed
@spring-projects-issues

Description

@spring-projects-issues

Jordi Llach Fernandez opened DATAMONGO-1185 and commented

As far as I know and remember interface auto-generated methods, @Query methods, ... and in fact all the rest end up using MongoTemplate.

As described in http://docs.spring.io/spring-data/data-mongo/docs/1.6.2.RELEASE/reference/html/#mongodb.mapping-usage.events lifecycle events work when using MongoTemplate but they do no work when using QueryDSL because it does not use MongoTemplate

We have implemented an extension of SpringDataMongodbQuery which in turn is used by QueryDSL that fires afterLoad and afterConvert events to the ApplicationContext

	public CtvSpringDataMongodbQuery(final ApplicationEventPublisher eventPublisher, final MongoOperations operations, final Class<? extends T> type) {
		this(eventPublisher, operations, type, operations.getCollectionName(type));
	}

	public CtvSpringDataMongodbQuery(final ApplicationEventPublisher eventPublisher, final MongoOperations operations, final Class<? extends T> type, String collectionName) {
		super(operations.getCollection(collectionName), new Function<DBObject, T>() {
			public T apply(DBObject input) {
                eventPublisher.publishEvent(new AfterLoadEvent<T>(input, (Class<T>)type));
				T read = operations.getConverter().read(type, input);
                eventPublisher.publishEvent(new AfterConvertEvent<T>(input, read));
                return read;
			}
		}, new CtvSpringDataMongodbSerializer(operations.getConverter()));
		this.operations = operations;
	}

I think that it would be quite useful to trigger lifecycle events in all cases, actually I think that QueryDSL is the missing part in all the work done in this area


Issue Links:

  • DATAMONGO-1848 Migrate to Document API-based Querydsl implementation
    ("depends on")
  • DATAMONGO-700 Events not triggered during Querydsl repository usage

Referenced from: pull request #324

1 votes, 3 watchers

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions