API v1.0

From TempusServa wiki
Revision as of 19:25, 15 April 2015 by old>Admin (Created page with " == Sessions and security == For interacting with Tempus Serva you need a session Session session = SessionFactory.getSession(this); == Constructing queryies == == Re...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Sessions and security

For interacting with Tempus Serva you need a session

 Session session = SessionFactory.getSession(this);


Constructing queryies

Retrieve data

Change / create data

Code example

       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();
       }