Skip to content
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

KeyValueTemplate assumes a map only and tries to assign ID [DATAKV-127] #106

Open
spring-projects-issues opened this issue Feb 12, 2016 · 0 comments
Assignees
Labels
type: bug A general bug

Comments

@spring-projects-issues
Copy link

Wallace Wadge opened DATAKV-127 and commented

Apologies for the length of this post but before I explain my issue, a little discussion is in order (I think this would be a great example project actually). I like Spring Data Rest, but I don't want to expose my DB objects as my api to allow me to modify my DB without affecting my api. My DB code also lives in a separate isolated module.

I have 2 modules, a web front-end and a core; so for eg I have a Client class for my DB and ApiClient for my api. Now Spring Data KeyValue allows me to treat a map as a repository -- Great! So on web module I define my repositories + API entities and on backend I have completely different repositories, and because I have a common interface my backend mapping code is very simple, for eg:

class Foo implements KeyValueAdapter { ....
    @Override
    public boolean contains(Serializable id, Serializable keyspace) {
        boolean result = false;
        try {
            Repository repo = getRepositoryFor(keyspace.toString());

            Class<?> modelClass = apiToModelClass(keyspace); // just a naming convention

           Path<Number> idPath = path(Number.class, path(modelClass, (String)keyspace), "id");
            Predicate mainPredicate = predicate(Ops.EQ, idPath, Expressions.constant(id));

            result = ((QueryDslPredicateExecutor)repo).exists(allOf(mainPredicate, securityContextPredicate(modelClass)));
        } catch (ClassNotFoundException e) {
            log.error("Unable to invoke repo invoker for contains", e);
        }

        return result;
    }

I even map querydsl predicates between the two worlds which is very nice too, everything based on my single Api->DB model mapper (orika in my case).

Now for the problem:

KeyValueTemplate assumes I will always need to generate an ID to store in some map so IdentifierGenerator is hard-coded to DefaultIdentifierGenerator.INSTANCE; but in my case I want to send null to the other side because it will be filled later on by the db layer. Can you please:

  • Allow us to override KeyValueTemplate identifierGenerator property
  • Remove the assert in insert(...)
  • Pass more meta-data/call an alternate adapter method since both insert and update call the same .put(..) method

No further details from DATAKV-127

@spring-projects-issues spring-projects-issues added the type: bug A general bug label Dec 31, 2020
@jxblum jxblum changed the title KeyValueTemplate assumes a map only and tries to assign ID [DATAKV-127] KeyValueTemplate assumes a map only and tries to assign ID [DATAKV-127] Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants