'not equals' condition when using Spring CrudRepository - spring-data-jpa

How should I build my findBy method name so I can implement a where clause -
statusCode != 'Denied'
Is this be an option?
findByStatusCodeNotIn(List<String> statusCode);
What if I want to just pass a String instead of a list?
Thank You

Have you taken a look at the documentation about this in the Spring Data JPA docs?
#findByStatusCodeNot(String statusCode);
It's akin the example in the docs like:
#findByLastnameNot

According to the Spring Data JPA Documentation on https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#reference
you can achieve this by using the "Not" keyword. forinstance your method would be
findByStatusCodeNot(String statusCode);
This means to achieve "statusCode != 'Denied'", you would call the method as
findByStatusCodeNot('Denied');

#Dovmo is right, but also keep in mind that if you are operating on String data, you may have to take case into account, i.e. findByStatusCodeNot(String statusCode) will find only records that are not 'Denied' as is, but not for instance 'DeniEd'. For case-insensitive searches, you can append IgnoreCase - findByStatusCodeNotIgnoreCase(String statusCode)
In general, please follow the link that #Dovmo gave.

According to the spring JPA repository docs we can use the <> symbol in place of !=
so the query would be
statusCode <> 'Denied'
this would be helpful if you want to write a #Query instead of the inbuild repository methods.

Related

Query MongoDB with dynamic selector in Camel

I found a solution here: How do I create a dynamic equals query using Apache Camel and MongoDB?
But this looks like a lot of work. Doesn't Camel have a simpler way to pass values to a MongoDB query? I wish we could just pass the actual find({}) language that Mongo uses.
Here is what I have working, with some logging showing what it's doing:
.setHeader(MongoDbConstants.CRITERIA, new Expression() {
#Override
public <T> T evaluate(Exchange exchange, Class<T> type) {
Long drRequestId = exchange.getIn().getHeader("orderid", Long.class);
Bson equalsClause = Filters.eq("id", drRequestId);
return exchange.getContext().getTypeConverter().convertTo(type, equalsClause);
};
})
.log(MongoDbConstants.CRITERIA)
.log("${headers.CamelMongoDbCriteria}")
.to("mongodb:mongo?database={{spring.data.mongodb.database}}&collection=ftx_orders&operation=findOneByQuery")
did you try with ${body.id}?
Also, you can also send it in header, setting using
exchange.getIn().setHeader("id","value");
and then using the same way you mentioned above.
.setHeader(MongoDbConstants.CRITERIA, constant(Filters.eq("name", simple("${header.id}"))))

TYPO3 queryBuilder: How to work with BINARY in where() clause?

I just have a short question.
There's no description in the following API overview of TYPO3 how to use a "BINARY" in where() clause: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/QueryBuilder/Index.html#expr
What I want to achieve? this one:
WEHRE BINARY `buyer_code` = "f#F67d";
Actually I can only do the following:
->where(
$queryBuilder->expr()->eq('buyer_code', 'f#F67d')
);
But in this case I don't get a satisfying result for myself because I need case-sensitive here :-)
An another buyer_code exists "f#F67D" (the last char is uppercase) but I do need to look for the other one.
Thanks for helping.
Since TYPO3 is using Doctrine API here, you could try to do
->where('BINARY `buyer_code` = ' . $queryBuilder->createNamedParameter('f#F67d'))
Please keep in mind, that this query now only works for database backends, supporting the BINARY keyword!
Please have a look at Doctrine2 case-sensitive query The thread is a bit older, but seems to cover background and solution for your problem.

Alternative of SQL LEN() Function in Realm

Is there anything similar to SQL LEN() Function in realm? How can I retrieve something like
SELECT * FROM Customers WHERE LEN(CustomerName) = 10;
Using realm in swift, I tried
realm.objects(Customers.self).filter("LEN(CustomerName) == 3")
got this error
Unable to parse function name 'LEN:' into supported selector (LEN:)
Realm does not yet support filtering based on the length of a string property. If this is something you'd like to use, please file an enhancement request on Realm Cocoa's GitHub page.
Maybe you are looking for #count property,
realm.objects(Customers.self).filter("CustomerName.#count == 3")
Check this collection query properties.

Multiples document s types refinementfilters

i am using rest api search to get documents with certain extensions types.
I am having this code:
&refinementfilters=or'(fileExtension:equals("aspx"),fileExtension:equals("wmv"))'
The whole code is:
https://myUrl/_api/search/query?selectproperties='Path,Url,Title,Size,IsDocument,PictureUrl,LastModifiedTime'&querytext='wildlife'&refinementfilters= '(fileExtension:equals("aspx"))'
i would like to use rest api refinementfilters fileExtension using or, but the syntax with the OR condition doesn' t work, can you halp me point out
where the problem can be ?
Cheers
To apply multiple filters via refinementfilters property, replace
refinementfilters='(fileExtension:equals("aspx"))'
with
refinementfilters='fileExtension:or("aspx","wmv")'
Example
/_api/search/query?selectproperties='Path,Url,Title,Size,IsDocument,PictureUrl,LastModifiedTime'&querytext='*'&refinementfilters= 'fileExtension:or("docx","pdf")'
As far as general syntax, the quotes for the OR are in the wrong place:
Original version:
&refinementfilters=or'(fileExtension:equals("aspx"),fileExtension:equals("wmv"))'
Corrected version:
&refinementfilters='or(fileExtension:equals("aspx"),fileExtension:equals("wmv"))'

Play Framework - find Object with "Or" in the query

It is possible to use "AND" while querying for Objects in Entity like
Post.find("byTitleLikeAndAuthor", "%hello%", connectedUser).fetch();
but is it possible to user "OR" while querying, like
Post.find("byNameOrEmail", name, email).fetch();
Thank you
Fixed!!
Use Post.find(" name = ? or email ?", name, email).fetch();
While using "where" in the query, it fails saying "unexpected token"
It is indeed possible to use "And" clauses when constructing objects, but I'm not aware of a possibility in simplified query to use "Or".
However, play can be used in many ways. Instead of writing :
Post.find("byNameOrEmail", name, email).fetch();
You can write :
Post.find("name = ? or email = ?", name, email).fetch();
using JPQL syntax.
It's not possible to use simplified query with or. To enable it you must change the implementation of findByToJPQL in the class play.db.jpa.JPQL. Wrote test and enhance the documentation and create a patch.
How ever you can use the JPQL.