Skip to main content
1-Visitor
March 17, 2015
Solved

Query Soft Types through API

  • March 17, 2015
  • 1 reply
  • 4240 views

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

Best answer by BjoernRueegg

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

1 reply

17-Peridot
March 17, 2015

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

spai-21-VisitorAuthor
1-Visitor
March 17, 2015

Can i provide a custom attribute in search condition??

17-Peridot
March 17, 2015

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.