/**
*
* @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;
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;
{
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
// 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());
return state;
}
+ /**
+ * Set the state.
+ * @param state the state to set
+ */
+ public void setProgressState(ProgressState state) {
+ this.state = state;
+ }
+
public SimulationContextType getType () {
// ---------------------------------------
return type;
// --------------------------
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