In clause parameters with SPEL - spring-data

I'm trying to pass multiple In Clause parameters using Spring-El, my query is:
#Query(nativeQuery = true, value = "select a.* from ACC a where (a.iban, a.currency) in (:#{#ibanAccounts.accountNumber} , :#{#ibanAccounts.currency})")
List<ACC> getAccount(#Param("ibanAccounts") List<AccountDetails> ibanAccounts);
But I'm getting following error:
EL1008E:(pos 14): Property or field 'accountNumber' cannot be found on object of type 'java.util.ArrayList$SubList' - maybe not public?
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 14): Property or field 'accountNumber' cannot be found on object of type 'java.util.ArrayList$SubList' - maybe not public?
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:224)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:46)
at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:374)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88)
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131)
In AccountDetails the field is present with public getter.
Can anyone please guide me what's wrong?

I believe what you are looking for is collection projection.
So you need to use something like this
#Query(nativeQuery = true, value = "select a.* from ACC a where (a.iban, a.currency) in :#{#ibanAccounts.![accountNumber]} , :#{#ibanAccounts.currency})")
List<ACC> getAccount(#Param("ibanAccounts") List<AccountDetails> ibanAccounts);

Related

How to append to array field with bulk_update

I have a ArrayField in a Peewee model backed by postgresql DB. How can I append to that field on conflict while upserting in bulk?
Model:
class User(Model):
id = BigAutoField(primary_key=True, unique=True)
tags = ArrayField(CharField, null=True)
SQL query I want to execute:
update user as u set tags = array_append(u.tags, val.tag)
from (values (2, 'test'::varchar)) as val(id, tag)
where u.id = val.id;
I've been trying for to figure out even for single insert, but facing issues in typecasting:
User.insert(user).on_conflict(
conflict_target=[User.id],
update={User.tags: fn.array_append(user['tag'])}
).execute()
Error I'm getting:
function array_append(unknown) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
How do I type cast the text to varchar in peewee?
You can try the following:
User.insert(user).on_conflict(
conflict_target=[User.id],
update={User.tags: fn.array_append(user['tag'].cast('varchar'))}
).execute()

DQL to query type fragments in documentum

I have an object in docmentum, this object has attributes and type fragments, I want to query by a type fragment attribute value. My object name is CIC and it has a type fragment called Emision which has an attrribute called receptor, so when I do :
select * from dfl_cic c where c.emision.receptor = "XXXXX"
I get an error, so how I can query by this value ??

Is there a Method to find datatypes of schema-less properties of a vertex in OrientDB?

Is there a SQL method to find property datatypes for schema-less properties in OrientDB?
There is .type() or .javatype() which can be used against a property in a select query like -
"SELECT Title.type() from #36:1"
This only provides the type for non null properties. Any properties with Null value return no type information.
Also I tried method called 'getPropertyNames' in Javascript function as well (link below).
https://orientdb.com/javadoc/develop/com/orientechnologies/orient/core/record/impl/OVertexDelegate.html#getPropertyNames--
I can use this in a function to pull out all property names but didnt find any similar method to pull PropertyTypes.
var db = orient.getDatabase();
var result = db.command('SELECT FROM V WHERE #rid = '+ id );
var fields = result[0].getRecord().getPropertyNames();
return fields;
Please provide guidance on how to get all property (schema and schema-less) property types for a Vertex record in OrientDB 3.0.
Either SQL method or Javascript Method and its usage will be very helpful.
Appreciate your help.
From the documentation: https://orientdb.com/docs/last/SQL.html#query-the-schema
I think this could help you:
select expand(properties) from (
select expand(classes) from metadata:schema
) where name = 'OUser'
And you could reference to the nummber of type (type column) here:
https://orientdb.com/docs/last/Types.html#supported-types

Possible bug in breeze 1.4.14

I haven't tested this against the 1.4.16 release that came out a couple of weeks ago but there is nothing in the release notes about it.
The problem occurs with predicates where the value you are comparing is identical to the name of a property on any entity that breeze knows about. A simple test case is :
var query = breeze.EntityQuery.from('Items');
var pred = breeze.Predicate.create('name', breeze.FilterQueryOp.Contains, searchTerm);
query = query.where(pred);
Where searchTerm is equal to any string other than "name" this produces an oData query as below:
Items?$filter=(substringof(%27somevalue%27%2CName)%20eq%20true)
but if searchTerm = "name" then it produces the following query
Items?$filter=(substringof(Name%2CName)%20eq%20true)
Which istead of comparing the string 'name' against the property Name, it compares the property Name with itself.
I have not tested every operator but as far as I can tell it does not matter which you use you get the same behaviour.
You also get the same problem when querying navigation properties but it usually results in an invalid query. Below is a predicate for the same entity but against a navigation property tags that contains a collection of ItemTag entities that have a "Tag" property on them.
breeze.Predicate.create('tags', breeze.filterQueryOp.Any, 'tag', breeze.filterQueryOp.Contains, searchTerm)
It works fine for any searchTerm other than "tag" where it produces an oData request as below:
Items?$filter=Tags%2Fany(x1%3A%20substringof(%27somevalue%27%2Cx1%2FTag)%20eq%20true)
but if the searchTerm is "tag" then it requests:
Items?$filter=Tags%2Fany(x1%3A%20substringof(Tag%2Cx1%2FTag)%20eq%20true)
which produces an error of "Could not find a property named 'Tag' on type 'Item'" because the property Tag exists on the ItemTag entity.
In short breeze seems to infer that any search term that is identical to the name of a property it knows about, refers to that property rather than being a string literal value.
Has anyone else encountered this?
Is this a bug, or is there a way to explicitly tell breeze to interpret that value as a string literal and not a reference to a property?
I am not sure it is relevant as the server seems to be responding correctly to the requests and it is breeze that is creating incorrect requests but on the server side I am using Web API oData controllers with EF as ORM data layer.
Try
var pred = breeze.Predicate.create('name', breeze.FilterQueryOp.Contains,
{ value: searchTerm, isLiteral: true} );
This is described here ( under the explanation of the value parameter):
http://www.breezejs.com/sites/all/apidocs/classes/Predicate.html#method_create
if the value can be interpreted as a property expression it will be, otherwise it will be treated as a literal.
In most cases this works well, but you can also force the interpretation by making the value argument itself an object with a 'value' property and an 'isLiteral' property set to either true or false.
Breeze also tries to infer the dataType of any literal based on context, if this fails you can force this inference by making the value argument an object with a 'value' property and a 'dataType'property set
to one of the breeze.DataType enumeration instances.
The reason for this logic is to allow expressions where both sides of the expression are properties. For example to query for employees with the same first and last name you'd do this:
var q = EntityQuery.from("Employees")
.where("lastName", "==", "firstName");
whereas if you wanted employees with a lastName of 'firstName' you'd do this:
var q = EntityQuery.from("Employees")
.where("lastName", "startsWith", { value: "firstName", isLiteral: true })

DistinctResultList in OpenJPA

I am attempting to get a distinct list of id's back that would be longs... But I am getting back this DistinctResultList... How can one handle this so that they get back results they are expecting... Here is what I am doing...
#NamedQuery(name="getProvidersByResourceIds", query = "SELECT DISTINCT p.resourceId FROM Provider p WHERE p.resourceId `in :resourceIds")`
Out of that I try and get the resourceIds' by doing this...
List<Long> provIDs = (List<Long>) emf.createNamedQuery("getProvidersByResourceIds").setParameter("resourceIds", values).getResultList();
But like I said, I keep getting back a DistinctResultList... Looking through the debugger, I can see the values I am getting back. How can I translate this into something usefull?
javax.ejb.EJBException: See nested exception; nested exception is: java.lang.IllegalArgumentException: Parameter "Parameter<long>('resourceIds')" declared in "SELECT p FROM Provider p WHERE p.resourceId = :resourceIds" is set to value of "org.apache.openjpa.kernel.DistinctResultList#35fb35fb" of type "org.apache.openjpa.kernel.DistinctResultList", but this parameter is bound to a field of type "long".
java.lang.IllegalArgumentException: Parameter "Parameter<long>('resourceIds')" declared in "SELECT p FROM Provider p WHERE p.resourceId = :resourceIds" is set to value of "org.apache.openjpa.kernel.DistinctResultList#35fb35fb" of type "org.apache.openjpa.kernel.DistinctResultList", but this parameter is bound to a field of type "long"
Change your query to :
#NamedQuery(name="getProvidersByResourceIds",
query = "SELECT DISTINCT p.resourceId FROM Provider p WHERE p.resourceId in (:resourceIds)");