OrientDB: Filter select on super class - orientdb

Using the OrientDB console there is a command to show all records with a class that extends a base class.
browse class Asset
This returns all records that have a class (Object1, Object2) that extends Asset.
I'm looking for a SQL command that can do the same.
Currently this query does not return the same set of records.
SELECT * V where #class = 'Asset'

you can also use instanceof operator,
eg.
select from V where #this instanceof 'Asset'
This makes sense especially in v. 2.1 where you have multiple inheritance, in cases when you want to retrieve documents that are subclasses of two different parent classes

To retrieve all the records from Object1 and Object2, a simple select query from the superclass name should work :
select from Asset

If you are looking for all superclasses of a given class, this worked for me:
select superClasses from (select expand(classes) from metadata:schema) where name = "myClassName"

Related

How do I filter a reference field of an inherited mongoengine class

Let's say I have model A, Model B and Model C
class ModelA(ModelB):
data = mongoengine.ReferenceField()
class ModelB(Document):
customer = mongoengine.ReferenceField(ModelC)
class ModelC(Document):
name = mongoengine.stringField()
I'm able to access this.
models.ModelA.objects(customer=customer)
Now I'm trying to filter where customer.name is equal to a name I pass in. Is this possible with mongoengine filters?
I tried using this method but it wont work
models.ModelA.objects(customer__name=name)
No this is not possible since joins dont exist in mongodb, you need do this in 2 step, first querying the customer based on the name, then query ModelA based on the outcome of the first query.
customer = ModelC.objects.get(name=your_name)
ModelA.objects(customer=customer)

How to traverse linked records in orientdb using fetch plans?

I created a hierarchical graph with 2 classes (Class A and Class B). Class A has embedded property "address" which links to class B. I'm trying to traverse both graphs to print the data using following queries, but it only returned class A data.
select name from A fetchplan address:-1;
select name from A fetchplan *:-1;
Could please tell me why class B graph data is not shown? how to traverse both classes ?

JPA createQuery()

When using JPA createQuery(), I found that we can use both class name and entity name to get the DB data.
This is by class name
em.createQuery("from com.model.Stuff s",
Stuff.class).getResultList();
And this is from entity name
em.createQuery("from Stuff s",
Stuff.class).getResultList();
This is in orm.xml
<entity class="com.model.Stuff" name="Stuff">
No matter which one i use, JPA can get the specific class that i am using from the orm.xml or from the annotation that i put in class.
So why i have to put Stuff.class in the parameter?
Because it can only put at most two parameters in createQuery(), What if i have to select two Class to do some join?
i cannot do this
em.createQuery("from Stuff s, Thing t where s.id = t.stuff_id", Stuff.class, Thing.class).getResultList();
Is
em.createQuery("from Stuff s",
Stuff.class).getResultList();
equal
em.createQuery("select s from Stuff s",
Stuff.class).getResultList();
Thanks to give me some help.
Stuff.class goes into the parameter to determine what type of query result object. A query can be infinitely complicated with dozens of nested types, but it must return one type of object in the end.
Then you must create a third Java type that will be result of join. Think about it, what type SHOULD the result be after a join?
As far as I know, yes

Spring data find by "_class " value

We are using spring data mongo repositories to store/retrieve documents. Following is the Java structure of classes we have got:
Abstract class A -> Concrete Classes B and C
We are writing the documents using save() method. when a document is saved, "_class" variable is saved which stores the classPath.
Now, when we try and query the data, we are getting the documents of both B and C classes. Following is the example:
public List<B> findByName (String name);
When we call this method, the list (surprisingly) contains the objects of C as well. It may be because B and C have one property which has same name.
My question is, if we want to restrict the result to specific class, is it possible using Mongo repository?
We tried with findBy_Class, findByClass but it threw an exception saying it was not able to find "class" member in "B".
Shouldn't the return type (e.g. List<B>) help filtering the objects? Any ideas?
Thanks in advance.
On the query object there's a "restrict" method which returns only objects of a given type.
http://docs.spring.io/spring-data/mongodb/docs/current/api/index.html?org/springframework/data/mongodb/core/MongoOperations.html
I suppose you could do something like that :
query.restrict(B.class).findByName(...)

How to get two class objects from on PFQuery in ios sdk?

In my application i am using parse sdk. In parse sdk databrowser i have two classes.
ClassA and ClassB .
Both classes are independent. they dont have any relation. I want to write a single query which gets objects from both classes in one array.
The current version of Parse SDK (1.2.12) does not provide such feature right out of the box.
The PFQuery Class only provides methods such as queryWithClassName: limited to one Class at a time.
You have to create and execute two separate PFQuery.
DBar is right. You can not download two different classes with the same query.
My solution was to make one universal class with a "type" field that I could use to parse out which class it should belong to on the user end. That way I could combine the two queries and sort out which belongs to which class on the user end.
You can have a Join Table
Class C which includes both Class A and Class B
so with just one query you can fetch both Class A and Class B
using includeKey.
PFQuery *query = [PFQuery queryWithClassName:#"ClassC"];
[query includeKey:#"classAObject"];
[query includeKey:#"classBObject"];
NSArray * results = [query find];