cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Query Soft Types through API

SOLVED
Highlighted
Newbie

Query Soft Types through API

Hi Everyone,

I want to know, if we can use Queryspec API to query soft types.

If yes, can you please give me a simple example of how to do it.

I have been using Info engine till now.

Thanks

Sudeep

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Query Soft Types through API

You can try to do something like this:

final IdentifierFactory IDENTIFIER_FACTORY = (IdentifierFactory) DefaultServiceProvider.getService(IdentifierFactory.class, "logical");

TypeIdentifier tid = (TypeIdentifier) IDENTIFIER_FACTORY.get(subtype); // Example: subtype=’com.ptc.ElectricalPart’

Class qc = WTPart.class;

QuerySpec qs = new QuerySpec();

int idx = qs.addClassList(qc, true);

SearchCondition sc = TypedUtilityServiceHelper.service.getSearchCondition(tid, true);

qs.appendWhere(sc, new int[]{idx});

System.out.println(qs);

QueryResult qr = PersistenceHelper.manager.find((StatementSpec) qs);

WTPart part;

while (qr.hasMoreElements()) {

Persistable[] ar = (Persistable[]) qr.nextElement();

part = (WTPart) ar[idx];

System.out.println(part + " - " + part.getName() + " - " + TypedUtilityServiceHelper.service.getExternalTypeIdentifier(part));

}

Regards Björn

View solution in original post

4 REPLIES 4

Re: Query Soft Types through API

You can try to do something like this:

final IdentifierFactory IDENTIFIER_FACTORY = (IdentifierFactory) DefaultServiceProvider.getService(IdentifierFactory.class, "logical");

TypeIdentifier tid = (TypeIdentifier) IDENTIFIER_FACTORY.get(subtype); // Example: subtype=’com.ptc.ElectricalPart’

Class qc = WTPart.class;

QuerySpec qs = new QuerySpec();

int idx = qs.addClassList(qc, true);

SearchCondition sc = TypedUtilityServiceHelper.service.getSearchCondition(tid, true);

qs.appendWhere(sc, new int[]{idx});

System.out.println(qs);

QueryResult qr = PersistenceHelper.manager.find((StatementSpec) qs);

WTPart part;

while (qr.hasMoreElements()) {

Persistable[] ar = (Persistable[]) qr.nextElement();

part = (WTPart) ar[idx];

System.out.println(part + " - " + part.getName() + " - " + TypedUtilityServiceHelper.service.getExternalTypeIdentifier(part));

}

Regards Björn

View solution in original post

Re: Query Soft Types through API

Can i provide a custom attribute in search condition??

Re: Query Soft Types through API

No, you can't. Have a look at the case CS125877

Because the IBA's are not stored in the same table as the object itself.

Probably you can query the standard attributes... I never tried it.

Re: Query Soft Types through API

Thanks a lot !!!