Salome HOME
Update copyrights 2014.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / SimulationContext.java
index a91d0af5ef4c6ff602d6b6931d9d7a513bdcf399..057dbd32a3de1eb7506f51351f76ed76d056d226 100644 (file)
@@ -2,16 +2,12 @@ package org.splat.dal.bo.som;
 /**
  * 
  * @author    Daniel Brunier-Coulin
- * @copyright OPEN CASCADE 2012
+ * @copyright OPEN CASCADE 2012-2014
  */
 
 import java.io.Serializable;
-import java.util.List;
-
-import org.hibernate.Session;
 
 import org.splat.dal.bo.kernel.Persistent;
-import org.splat.dal.dao.som.Database;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
@@ -24,7 +20,7 @@ public class SimulationContext extends Persistent implements Serializable {
        private SimulationContextType  type;     // User extendable types
     private int                    step;
     private ProgressState          state;
-    private String                 value;
+       private String                 value;
     private int                    counter;
 
     private static final long serialVersionUID = 422889133378471949L;
@@ -92,8 +88,7 @@ public class SimulationContext extends Persistent implements Serializable {
       {
         if (type == null)  throw new MissedPropertyException("type");
         if (step == null)  throw new MissedPropertyException("step");
-        if (value == null) throw new MissedPropertyException("value");        
-        if (!type.isAttachedTo(step)) throw new InvalidPropertyException("step");
+        if (value == null) throw new MissedPropertyException("value");
       }
     }
 //  Database fetch constructor
@@ -114,14 +109,6 @@ public class SimulationContext extends Persistent implements Serializable {
 //  Public member functions
 //  ==============================================================================================================================
 
-    public boolean approve () {
-//  -------------------------
-      if  (state != ProgressState.inCHECK) return false;      
-      this.state =  ProgressState.APPROVED;     // The type name is supposed being localized
-      Database.getSession().update(this);
-         return true;
-    }
-
     public boolean equals (SimulationContext given) {
 //  -----------------------------------------------
       if (isSaved()) return (this.getIndex() == given.getIndex());
@@ -140,6 +127,14 @@ public class SimulationContext extends Persistent implements Serializable {
       return state;
     }
 
+    /**
+        * Set the state.
+        * @param state the state to set
+        */
+       public void setProgressState(ProgressState state) {
+               this.state = state;
+       }
+       
     public SimulationContextType getType () {
 //  ---------------------------------------
       return type;
@@ -154,91 +149,18 @@ public class SimulationContext extends Persistent implements Serializable {
 //  --------------------------
       return (counter > 1);
     }
-
-//  ==============================================================================================================================
-//  Public services
-//  ==============================================================================================================================
-
-    public static SimulationContextType createType (String name, ProjectSettingsService.Step step) throws InvalidPropertyException, RuntimeException {
-//  ---------------------------------------------------------------------------------------
-//TODO: Check for duplicate definition
-      SimulationContextType type    = new SimulationContextType(name, step);
-      Session               session = Database.getSession();
-      session.save(type);
-          
-      return type;
-    }
-
-    @SuppressWarnings("unchecked")
-       public static List<SimulationContextType> selectAllTypes () {
-//  -----------------------------------------------------------
-         StringBuffer  query = new StringBuffer("from SimulationContextType");  // Useless to order by names as the result mixes localized and non localized types
-                       query = query.append(" order by step asc");
-      return  Database.getSession().createQuery(query.toString()).list();
-    }
-
-    @SuppressWarnings("unchecked")
-       public static List<SimulationContextType> selectTypesOf (ProjectSettingsService.Step... step) {
-//  --------------------------------------------------------------------------------------
-         StringBuffer  query = new StringBuffer("from SimulationContextType where step='").append(step[0].getNumber()).append("'");      
-         for (int i=1; i<step.length; i++) {           // Useless to order as the result mixes localized and non localized types
-        query = query.append(" or step='").append(step[i].getNumber()).append("'");
-         }
-         query = query.append(" order by step asc");
-      return  Database.getSession().createQuery(query.toString()).list();
-    }
-
-       @SuppressWarnings("unchecked")
-       public static List<SimulationContextType> selectTypesWhere (SimulationContextType.Properties sprop) {
-//  ---------------------------------------------------------------------------------------------------
-      StringBuffer         query     = new StringBuffer("from SimulationContextType");
-      String               separator = " where";
-      ProjectSettingsService.Step step      = sprop.getStep();
-      ProgressState        state     = sprop.getProgressState();
-      String               order     = " order by step asc";
-
-      if (step != null) {
-        query     = query.append(separator).append(" step='").append(step.getNumber()).append("'");
-        separator = " and";
-        order     = " order by state desc";         // APPROVED (upper case A) is grater than inCHECK (lower case i)
-      }
-      if (state != null) {
-        query     = query.append(separator).append(" state='").append(state.toString()).append("'");
-//      separator = " and";
-        if (step != null) {
-          if (state != ProgressState.APPROVED) order = " order by name asc";
-          else  order = "";                         // Approved types are localized
-        }
-      }
-      query = query.append(order);
-      return  Database.getSession().createQuery(query.toString()).list();
-    }
-
-    public static SimulationContextType selectType (String name) {
-//  ------------------------------------------------------------
-         StringBuffer  query = new StringBuffer("from SimulationContextType where name='").append(name).append("'");     
-         return (SimulationContextType)Database.getSession().createQuery(query.toString()).uniqueResult();
-    }
-    
-    public static SimulationContextType selectType (int index) {
-//  ----------------------------------------------------------
-         StringBuffer  query = new StringBuffer("from SimulationContextType where rid='").append(index).append("'");     
-         return (SimulationContextType)Database.getSession().createQuery(query.toString()).uniqueResult();
-    }
-    
-//  ==============================================================================================================================
-//  Protected services
-//  ==============================================================================================================================
-
-    public void hold () {
-//  ----------------------
-      counter += 1;
-      if (this.isSaved()) Database.getSession().update(this);
-    }
-
-    public void release () {
-//  -------------------------
-      counter -= 1;
-      if (this.isSaved()) Database.getSession().update(this);
-    }
+       /**
+        * Get counter.
+        * @return counter
+        */
+       public int getCounter() {
+               return counter;
+       }
+       /**
+        * Set counter.
+        * @param aValue a counter value to set
+        */
+       public void setCounter(int aValue) {
+               counter = aValue;
+       }
 }
\ No newline at end of file