com.irisel.oms.olapi
Class QuerySave

java.lang.Object
  extended by com.irisel.oms.olapi.QuerySave

public class QuerySave
extends java.lang.Object

This class is used to make relational queries in 3-tier mode, using a CLBrowser. It is based upon the deprecated class InstanceRetrieval, which was designed for working in 2-tier mode (requiring connectivity with the database server). In contrast, QuerySave uses a CLBrowser (connection-less browser) so it can be used by the J2EE clients too. The intended use is the following: 1) Initialization. The constructor without arguments will use CLGuiomBrowser.getGuiomBrowser() in order to get the browser. Otherwise you can specify an existing CLBrowser. 2A) Adding/Updating Records Add the instances to be saved. You can add individual instances (addInstance) or a set (addInstanceSet). If the OID is zero a new OID will be generated and the record will be inserted. If the OID is different from zero, the record will be updated if exists, otherwise the record will be inserted using that OID. Provide a different branch id (integer type) to identify that instance or instance set that is being added. 2B) Relating Records You can relate records using relateInstances method. To relate to records that you don't want to modify, you need to add those instances in read-only mode (addInstanceRO, addInstanceSetRO). To relate two instances or instance sets you need to provide the branch ids used when calling addInstance(Set) method, you can provide a single integer or an array of integers, and the name of the relation. For OMS-M2M relationships you must specify role names (can be null) and the sense of the relationship (note it is equivalent to use the inverse relationship if you change that boolean too). When relating a set (array) of branches, the behavior for O2O relationship will be to link by pairs, when the relationship is O2M, every element in source list will be linked with all elements in destination array. 3) Performing the operation To perform the operation use the method save(). Alternatively, you can invoke prepareStatements() first, then save(), in order to manage possible exceptions at this point separately from the possible exceptions occuring during the actual save.

Author:
Jose Manuel Gomez, Irisel Consulting SL

Constructor Summary
QuerySave()
           
QuerySave(CLBrowser clb)
           
 
Method Summary
 void addInstance(int id, Instance i)
          Adds a new instance to be created or updated.
 void addInstanceRO(int id, Instance i)
          Adds an instance to be referenced by other instances.
 void addInstanceSet(int id, InstanceSet is)
          Adds a new InstanceSet to be created or updated The instances will be created or updated in a case-per-case basis, depending on whether the instance's primary key is null or not.
 void addInstanceSetRO(int id, InstanceSet iii)
          Adds an instance set to be referenced by other instances.
 void clear()
          Adds a new instance to be created or updated.
 CLBrowser getBrowser()
          Getter for property browser.
 void prepareStatements()
          Set up the instance set to be saved.
 void relateInstancesM2O(int[] id1, int[] id2, java.lang.String relationName)
          Relates two instances or sets by id and relation name.
 void relateInstancesM2O(int id1, int id2, java.lang.String relationName)
           
 void relateInstancesO2O(int[] id1, int[] id2, java.lang.String relationName)
          Relates in a one-to-one basis each instance/set of id1[i] to each instance/set of id2[i].
 void relateInstancesO2O(int id1, int id2, java.lang.String relationName)
           
 void relateInstancesOMS(int[] id1, int[] id2, java.lang.String relationName, java.lang.String role1, java.lang.String role2, boolean forward)
          Relates two instances or sets by id and relation name (which must be OMS-managed)
 void relateInstancesOMS(int id1, int id2, java.lang.String relationName, java.lang.String role1, java.lang.String role2, boolean forward)
           
 int save()
           
 void setBrowser(CLBrowser browser)
          Setter for property browser.
 void unrelateInstances(int srcBranchId, int dstBranchId, RelationVO rel)
           
 void unrelateInstances(int srcBranchId, int dstBranchId, java.lang.String relname)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuerySave

public QuerySave()
          throws QuerySaveException
Throws:
QuerySaveException

QuerySave

public QuerySave(CLBrowser clb)
          throws QuerySaveException
Throws:
QuerySaveException
Method Detail

clear

public void clear()
Adds a new instance to be created or updated. The instance will be created if its primary key is null, otherwise it will be updated

Parameters:
id - is the internal index of the instance to be saved, start numbering schema at 0, then 1, 2, etc.
i - is the instance to be saved.

addInstance

public void addInstance(int id,
                        Instance i)
                 throws QuerySaveException
Adds a new instance to be created or updated. The instance will be created if its primary key is null, otherwise it will be updated

Parameters:
id - is the internal index of the instance to be saved, start numbering schema at 0, then 1, 2, etc.
i - is the instance to be saved.
Throws:
QuerySaveException

addInstanceRO

public void addInstanceRO(int id,
                          Instance i)
                   throws QuerySaveException
Adds an instance to be referenced by other instances. This instance will not be updated.

Parameters:
id - is the internal index of the instance to be saved, start numbering schema at 0, then 1, 2, etc.
i - is the instance to be saved.
Throws:
QuerySaveException

addInstanceSet

public void addInstanceSet(int id,
                           InstanceSet is)
                    throws QuerySaveException
Adds a new InstanceSet to be created or updated The instances will be created or updated in a case-per-case basis, depending on whether the instance's primary key is null or not.

Parameters:
id - is the internal index of the instance to be saved, start numbering schema at 0, then 1, 2, etc.
is - is the InstanceSet to be saved.
Throws:
QuerySaveException

addInstanceSetRO

public void addInstanceSetRO(int id,
                             InstanceSet iii)
                      throws QuerySaveException
Adds an instance set to be referenced by other instances. This instance set will not be updated.

Parameters:
id - is the internal index of the instance to be saved, start numbering schema at 0, then 1, 2, etc.
iii -
is - is the InstanceSet to be saved.
Throws:
QuerySaveException

relateInstancesO2O

public void relateInstancesO2O(int[] id1,
                               int[] id2,
                               java.lang.String relationName)
Relates in a one-to-one basis each instance/set of id1[i] to each instance/set of id2[i]. Only One-to-One, One-to-Many, and Many-to-One relations can be used, and the size of both arrays of indexes must be equal.

Parameters:
id1 -
id2 -
relationName -

relateInstancesO2O

public void relateInstancesO2O(int id1,
                               int id2,
                               java.lang.String relationName)

relateInstancesM2O

public void relateInstancesM2O(int[] id1,
                               int[] id2,
                               java.lang.String relationName)
Relates two instances or sets by id and relation name. If relation is One-to-One, use QuerySave.relateInstancesO2O. If relation is One-to-Many, every instance/set of id1 will be related to all instances/sets on id2. If relation is Many-to-One, every instance/set of id2 will be related to all instances/sets in id1. If relation is Many-To-Many relationships, use QuerySave.relateInstancesOMS.

Parameters:
id1 -
id2 -
relationName -

relateInstancesM2O

public void relateInstancesM2O(int id1,
                               int id2,
                               java.lang.String relationName)

relateInstancesOMS

public void relateInstancesOMS(int[] id1,
                               int[] id2,
                               java.lang.String relationName,
                               java.lang.String role1,
                               java.lang.String role2,
                               boolean forward)
Relates two instances or sets by id and relation name (which must be OMS-managed)

Parameters:
id1 -
id2 -
relationName -
role1 -
role2 -
forward -

relateInstancesOMS

public void relateInstancesOMS(int id1,
                               int id2,
                               java.lang.String relationName,
                               java.lang.String role1,
                               java.lang.String role2,
                               boolean forward)

unrelateInstances

public void unrelateInstances(int srcBranchId,
                              int dstBranchId,
                              java.lang.String relname)

unrelateInstances

public void unrelateInstances(int srcBranchId,
                              int dstBranchId,
                              RelationVO rel)

prepareStatements

public void prepareStatements()
                       throws QuerySaveException
Set up the instance set to be saved. Primary keys are reserved and foreign keys updated. It is not necessary but it may help debugging to invoke this method prior to save().

Throws:
QuerySaveException

save

public int save()
         throws QuerySaveException
Throws:
QuerySaveException

getBrowser

public CLBrowser getBrowser()
Getter for property browser.

Returns:
Value of property browser.

setBrowser

public void setBrowser(CLBrowser browser)
Setter for property browser.

Parameters:
browser - New value of property browser.