Difference between revisions of "API v1.0"
Jump to navigation
Jump to search
old>Admin |
old>Admin |
||
Line 23: | Line 23: | ||
myQuery.addWhereCriterion("StatusID", "In progress"); | myQuery.addWhereCriterion("StatusID", "In progress"); | ||
Note that lookup values etc. will be translated silently | Note that lookup values etc. will be translated silently. | ||
Finally execute the query and return the results | |||
SolutionQueryResultSet records = myQuery.executeQuery(); | |||
== Retrieve data == | == Retrieve data == |
Revision as of 19:35, 15 April 2015
Sessions and security
For interacting with Tempus Serva you need a session
Session session = SessionFactory.getSession(this);
All sessions need to be terminated after use (releasing DB connections etc.)
session.close();
Constructing queryies
First of create a query object
SolutionQuery myQuery = session.getSolutionQuery( "mynewsolution" );
A query is built much like an SQL query by appending different fields to be SELECT'ed
myQuery.addSelectField("MYNUMBER");
Additionally WHERE components are added
myQuery.addWhereCriterion("StatusID", "In progress");
Note that lookup values etc. will be translated silently.
Finally execute the query and return the results
SolutionQueryResultSet records = myQuery.executeQuery();
Retrieve data
Change / create data
Code example
The following example shows how data is retrieved from af collection of templates and used to create a collection of records (with values copied from the template).
int parentTemplateDataID = Parser.getInteger( c.fields.getElementByFieldName(thisKeyToParentTemplate).FieldValue ); Session session = SessionFactory.getSession(this); try { //Get data SolutionQuery opsaetning = session.getSolutionQuery(templateSolutionName); for(int i=0; i<fieldsTemplate.size(); i++ ) opsaetning.addSelectField(fieldsTemplate.get(i)); opsaetning.addWhereCriterion(templateKeyToParentTemplate, parentTemplateDataID); SolutionQueryResultSet recordsToCopy = opsaetning.executeQuery(); int recordCount = recordsToCopy.size(); for( int i=0; i<recordCount; i++ ) { SolutionRecordNew instance = session.getSolutionRecordNew(instanceSolutionName); for(int fi=0; fi<fieldsTemplate.size(); fi++ ) { String value = recordsToCopy.getRecordValue( i, fieldsTemplate.get(fi)); instance.setValue( fieldsInstance.get(fi), value ); } instance.setValueInteger( instanceKeyToParent, c.DataID ); if( ! Parser.isEmpty(instanceKeyToTemplate) ) instance.setValueInteger( instanceKeyToTemplate, recordsToCopy.getReference(i) ); instance.persistChanges(); } } catch(Exception e) { e.printStackTrace(); } finally { session.close(); }