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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Query Soft Types through API

spai-2
1-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

1 ACCEPTED SOLUTION

Accepted Solutions

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

5 REPLIES 5

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

Can i provide a custom attribute in search condition??

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.

Thanks a lot !!!

VR_10417596
5-Regular Member
(To:spai-2)

Hi ,

 

without using below API' how we can get soft type ?

SearchCondition sc = TypedUtility.getSearchCondition(softype, true);

 

Thanks,

Vishvanatha

Top Tags