OQL all instances from a package - jvm

Is it possible in OQL to retrieve all the objects that belongs to a package? Or can I query with wildcards?
As #haridsv suggested I tried:
SELECT * from "com.example.*"
and
SELECT a from "com\.example\..*"
but in VisualVM it complaints that no such package exists.
Even
SELECT a from "java.io.File" a
Fails.
Thanks!
ssedano.

You can use regular expression like this:
SELECT * from "<packagename>.*"
If the package name is "java.io" you would use:
SELECT * from "java\.io\..*"
Note the quotes around the regex and how the dots in the path are protected.

I found the answer in VisualVM OQL help.
select filter(heap.classes(), "/com.example./(it.name)")

From VisualVM limited documentation:
select all classes that have name pattern java.net.*
select filter(heap.classes(), "/java.net./.test(it.name)")
https://visualvm.github.io/documentation.html
The trick is in the "test(it.name)"

Related

AEM JCR SQL2 query to find all pages contains specific component

I wish to build a sql2 jcr query to find all pages under /content that contains this component, e.g /apps/platform/aem-core/components/content/form/form
I read https://wiki.magnolia-cms.com/display/WIKI/JCR+Query+Cheat+Sheet and tried something like below
My current attempt is something like SELECT * from [cq:Page] AS t WHERE t.contains('/apps/platform/aem-core/components/content/form/form')
But it won't work. Please suggest me a example to find all pages contains this component. Thanks
As #awd has mentioned in the comments, QueryBuilder provides better capabilities.
SQL2 however is not that bad, especially for someone with an inclination towards RDBMS !
The below query should fetch all the page paths using the component resourceType.
SELECT * FROM [cq:PageContent] AS s WHERE
ISDESCENDANTNODE(s,'/content') AND CONTAINS(s.[sling:resourceType],
'foundation/components/text')
You've got to use square brackets for properties with namespaces in them, for e.g: cq:template, sling:resourceType, etc
SELECT page.* FROM [cq:Page] AS page INNER JOIN [nt:base] AS component ON ISDESCENDANTNODE(component,page) WHERE ISDESCENDANTNODE(page, '/content') AND component.[sling:resourceType] = '/apps/platform/aem-core/components/content/form/form'
select * from nt:base where jcr:path like '/content/%' and [sling:resourceType] ='/apps/platform/aem-core/components/content/form/form'

How to locate the node in JCR using uuid from query

This is the error I get.
16.03.2016 12:02:16.413 WARN [xxx.xxx.xx.xxx [1458147736268] GET /en/employees-leaders/employee-s-toolkit2/epd-update/epd-update-archives/caterpillar-news/upcoming-brand-webinarfocusonmarketing.html HTTP/1.1] com.day.cq.wcm.core.impl.LanguageManagerImpl Error while
retrieving language property. javax.jcr.AccessDeniedException: cannot
read item xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (alpha-numeric)
I am trying to locate the node in JCR using the xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, which I believe is uuid, using a query in AEM.
Is the xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx actually a uuid?
How do I locate the source i.e node, causing the issue?
I tried running a sql with the above id in the jcr, but it returned no result.
//*[jcr:contains(., '91186155-45ad-474-9ad9-d5156a398629')] order by #jcr:score descending
Any other insights would be much appreciated.
You don't need a query if you know the Node's UUID, just use the Session.getNodeByIdentifier(String id) method.
Your query is not SQL as you stated, it's XPATH. Is that a typo or did you run the query incorrectly?
It certainly looks like a UUID. You can query for the jcr:uuid property or you can continue doing a full text search.
XPATH:
/jcr:root//*[jcr:contains(., '91186155-45ad-474-9ad9-d5156a398629')]
/jcr:root//*[#jcr:uuid='91186155-45ad-474-9ad9-d5156a398629']
JCR-SQL2:
SELECT * FROM [nt:base] AS s WHERE contains(s.*, '91186155-45ad-474-9ad9-d5156a398629')
SELECT * FROM [nt:base] WHERE [jcr:uuid] = '91186155-45ad-474-9ad9-d5156a398629'
What read permissions does your account have? You're going to find a lot of results for a jcr:uuid query will be under /jcr:system/jcr:versionStorage.
Use QueryBuilderDebugger, (localhost:4502/libs/cq/search/content/querydebug.html) and run similar query as below to get the node for a given uuid:
property=jcr:uuid
property.value=e69b256e-a466-3730-866b-de22c82ab8ck
path=/home
type=rep:Group
p.limit=10

System.Linq.Dynamic library - need Count() example

I need most elegant solution for dynamic selecting/grouping/ordering via Linq2Entities (VB.NET/VS2012).
And I'm trying to use System.Linq.Dynamic library (http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx)
This construсtion works fine
Dim testQuery= testDB.testTable.Select("New(Field1)").GroupBy("New(Field1)", "it")
But this one (found this example somewhere on blogs/SO) generates error:
Dim testQuery= testDB.testTable.Select("New(Field1, Count())").GroupBy("New(Field1, Count())", "it")
The error is "No applicable method 'Count' exists in type 'testTable'"
I know that this library was born dead, but official MS solution for dynamic queries with expressions-trees is kinda scary. :-)
If your aim is to retrieve the count of rows in testTable for each value of Field1, then I would have thought you want to firstly GroupBy Field1, then Select afterwards. So basically reverse the order of your Select and GroupBy and remove the Count() from the GroupBy.

string search using OQL

I am using VisualVM to analyze a core dump. I suspect some XML objects to be causing the leak but there are way too many String objects to go through one by one.
Can I use OQL to search String that begin with 'GH' ?
thanks for any help.
under JDK 1.8.20 a more simple variant works:
select s from java.lang.String s where s.toString().startsWith("GH")
Try this:
select {instance: s, content: s.toString()} from java.lang.String s where s.count>2 && s.toString().substring(0,2)=="GH"
heap.objects('java.lang.String', false, "it.toString().startsWith('GH')")
select c.attr_name.toString() from a.b.c.MyClass c where c.attr_name.toString().startsWith("GH")

IFNULL in Symfony2 Doctrine query builder

How is the IFNULL of SQL implemented in Symfony2 Doctrine Query Builder?
Let's say I have this query:
select * from ticket order by IFNULL(modified_date, '2000-01-01') DESC, created_date DESC
I have this DQL:
$this->qb->select("t, c.name")
->from("Ticket", "t");
$this->qb->orderBy("t.modifiedDate", "DESC");
$this->qb->addOrderBy("t.createdDate", "DESC");
Now how to add the IFNULL part?
Ok, done some research and found that there is no such implementation.
Googled a little more, and got that this kind of missing features can be added to Doctrine as own functions.
Found this extension on GitHub I think this will work. But wonder if ther would be any problems or conflicts with Doctrine versions...
This is the valid link with the DQL Extension
Edit with the solution explained:
Create the following directory under your project src path: /src/DoctrineExtensions/Query/Mysql
Put there the DQL Extension file (IfNull.php in this case)
Edit your src/config/packages/doctrine.yaml and insert this new lines:
doctrine:
...
orm:
...
dql:
numeric_functions:
IFNULL: App\DoctrineExtensions\Query\Mysql\IfNull
In your entity repository you can call this function like this:
$qb = $this->createQueryBuilder('tl')
->andWhere('IFNULL(tl.app,0) = 1');
Depending on your usecase you may be able to use the builtin "COALESCE" expression instead of installing the "IFNULL" extension.
The usage then is basically the same as with the IFNULL expression.
Just replace IFNULL with COALESCE in the example in https://stackoverflow.com/a/68827681/1707003.
Note: COALESCE might behave slightly different than IFNULL depending on your database. https://stackoverflow.com/a/18528590/1707003 contains some great explanations.
List of builtin case-expressions: https://www.doctrine-project.org/projects/doctrine-orm/en/2.13/reference/dql-doctrine-query-language.html#case-expressions