Skip to content

Expose some private methods of the template and repository #1310

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
jorgerod opened this issue Jan 25, 2022 · 7 comments · Fixed by #1317
Closed

Expose some private methods of the template and repository #1310

jorgerod opened this issue Jan 25, 2022 · 7 comments · Fixed by #1317
Labels
type: enhancement A general enhancement

Comments

@jorgerod
Copy link
Contributor

jorgerod commented Jan 25, 2022

Hello

Both repositories and templates are extensible but I have found several private methods that I would need to be able to extend efficiently.

Something similar was done on this issue:

What do you think?

Thanks in advance

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 25, 2022
@mikereiche
Copy link
Collaborator

Isn't 'protected' sufficient for accessing with a subclass?

Can you give an example of what you are wanting to do?

@jorgerod
Copy link
Contributor Author

Hi @mikereiche

With protected would be perfect but they are with default visibility (only accessible within the package).

@mikereiche
Copy link
Collaborator

"there are classes with the constructor not visible and others with the public constructor. "

I believe the constructors are/should be only called by corresponding method in Reactive/CouchbaseTemplate and none of them need to be public. Can you explain the case where they would need to be public? Can you explain the case where you would need getScope() and getCollection() to be public?

@Override
public <T> ReactiveInsertById<T> insertById(Class<T> domainType) {
	return new ReactiveInsertByIdOperationSupport(this).insertById(domainType);
}

@jorgerod
Copy link
Contributor Author

jorgerod commented Feb 1, 2022

Hi

I would need that getScope() and getCollection() to be protected.

For example, I extends SimpleCouchbaseRepository for override method save (add operation insert)

public class CouchbaseBaseRepository<T> extends SimpleCouchbaseRepository<T, String> {

	@Override
	@SuppressWarnings("unchecked")
	public <S extends T> S save(S entity) {
		Assert.notNull(entity, "Entity must not be null!");
		// if entity has non-null, non-zero version property, then replace()
		S result;
		if (hasNonZeroVersionProperty(entity, operations.getConverter())) {
		     result = (S) operations.replaceById(getJavaType()).inScope(getScope()).inCollection(getCollection()).one(entity);
		} else {
		     result = (S) operations.upsertById(getJavaType()).inScope(getScope()).inCollection(getCollection()).one(entity);
		}  else {
                   //Creating new document
                    result = (S) operations.insertById(getJavaType()).inScope(getScope()).inCollection(getCollection()).one(entity);
               }
		return result;
	}

On the other hand, I also extend the template by adding another operation and it would be very useful to use the method

Thank you very much

@mikereiche
Copy link
Collaborator

Ok - that code isn't even going to compile with the two consecutive else's without if's .
If this is to work-around #1277, please just submit a PR according to the issue.

I also extend the template by adding another operation

But why?

@jorgerod
Copy link
Contributor Author

jorgerod commented Feb 1, 2022

Ok - that code isn't even going to compile with the two consecutive else's without if's . If this is to work-around #1277, please just submit a PR according to the issue.

Ok, I will make a PR with that change.

I also extend the template by adding another operation

But why?

Both the repository and the template are public and, therefore, extensible. I have added my own operations to the repository (and, consequently, to the template).

The operations that I have added are, for example, the saving with the possibility of the insertById, operations to work the api of subdocuments, I have added the touch operation...

All these operations now I have to make them compatible with the scopes and the collections and, since the repositories and the templates are public, I ask that the methods getScope, getCollection and potentiallyConvertRuntimeException are protected.

I hope I have explained myself better.

If you have any doubt, we will be happy to talk about it.

Best regards

@mikereiche
Copy link
Collaborator

mikereiche commented Feb 1, 2022

have added the touch operation...

getAndTouch is already present - see #982

saving with the possibility of the insertById

insertById will be fixed with see #1277.

potentiallyConvertRuntimeException

Is this to convert CasMismatch to OptimisticLockingFailure as for #1314? The issue seems to be the documentation, not the code as the code always converted it to DataIntegrityViolation.

We're not going to open up APIs to work-around bugs as an alternative to fixing bugs.

Can you create a PR for the addition of Subdocument support?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
3 participants