Skip to content

AbstractTemplateSupport.decodeEntityBase() saves version property twice (?) #1263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mikereiche opened this issue Nov 5, 2021 · 2 comments
Closed
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@mikereiche
Copy link
Collaborator

It puts it in the new document, then reads that document into readEntity, then sets it again in readEntity.

public <T> T decodeEntityBase(String id, String source, long cas, Class<T> entityClass,
															TransactionResultHolder txResultHolder) {

	final CouchbaseDocument converted = new CouchbaseDocument(id);
	converted.setId(id);
	CouchbasePersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entityClass);
	if (cas != 0 && persistentEntity.getVersionProperty() != null) {
		converted.put(persistentEntity.getVersionProperty().getName(), cas);
	}

	T readEntity = converter.read(entityClass, (CouchbaseDocument) translationService.decode(source, converted));
	final ConvertingPropertyAccessor<T> accessor = getPropertyAccessor(readEntity);

	if (persistentEntity.getVersionProperty() != null) {
		accessor.setProperty(persistentEntity.getVersionProperty(), cas);
	}
	if (persistentEntity.transactionResultProperty() != null) {
		accessor.setProperty(persistentEntity.transactionResultProperty(), System.identityHashCode(txResultHolder));
	}
	N1qlJoinResolver.handleProperties(persistentEntity, accessor, getReactiveTemplate(), id);
	return accessor.getBean();
}
@mikereiche mikereiche added the type: enhancement A general enhancement label Nov 5, 2021
@mikereiche
Copy link
Collaborator Author

Be careful about any 'fixing' here.
The first time it sets it in the 'converted' CouchbaseDocument, the second time it sets it in the resulting entity object.

Refer to #937

@mikereiche
Copy link
Collaborator Author

It's set the first time in case the entity constructor has a "long version" argument. Null is not valid for a "long" argument and an exception will be thrown. This can be avoided by making the argument "Long version"

@mikereiche mikereiche added status: declined A suggestion or change that we don't feel we should currently apply and removed type: enhancement A general enhancement labels Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

1 participant