001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.data;
025:
026: import java.util.HashMap;
027: import java.util.Hashtable;
028: import java.util.Vector;
029:
030: import org.objectweb.salome_tmf.api.Api;
031: import org.objectweb.salome_tmf.api.ApiConstants;
032: import org.objectweb.salome_tmf.api.data.DataSetWrapper;
033: import org.objectweb.salome_tmf.api.data.ValuedParameterWrapper;
034: import org.objectweb.salome_tmf.api.sql.ISQLDataset;
035:
036: public class DataSet extends SimpleData {
037: static ISQLDataset pISQLDataset = null;
038:
039: protected HashMap parametersHashMap;
040:
041: public DataSet(String name, String decription) {
042: super (name, decription);
043: parametersHashMap = new HashMap();
044: if (pISQLDataset == null) {
045: pISQLDataset = Api.getISQLObjectFactory().getISQLDataset();
046: }
047: }
048:
049: public DataSet(DataSetWrapper pDataSet) {
050: super (pDataSet.getName(), pDataSet.getDescription());
051: idBdd = pDataSet.getIdBDD();
052: parametersHashMap = new HashMap();
053: if (pISQLDataset == null) {
054: pISQLDataset = Api.getISQLObjectFactory().getISQLDataset();
055: }
056: }
057:
058: public void reloadBaseFromDB() throws Exception {
059: if (!isInBase()) {
060: throw new Exception("Dataset " + name + " is not in BDD");
061: }
062: DataSetWrapper pDataSet = pISQLDataset.getWrapper(idBdd);
063: name = pDataSet.getName();
064: description = pDataSet.getDescription();
065: }
066:
067: public void reloadFromDB(boolean base, Hashtable paramsInModel)
068: throws Exception {
069: if (!isInBase()) {
070: throw new Exception("Dataset " + name + " is not in BDD");
071: }
072: if (base) {
073: reloadBaseFromDB();
074: }
075: reloadValuedParameters(paramsInModel);
076:
077: }
078:
079: public void clearCache() {
080: /* NOTHING */
081: }
082:
083: /***************************** Basic Operation *********************************/
084:
085: /* call from Campaign */
086: void addInDB(int idCamp) throws Exception {
087: if (isInBase()) {
088: throw new Exception("Dataset " + name
089: + " is already in BDD");
090: }
091: idBdd = pISQLDataset.insert(idCamp, name, description);
092: Project.pCurrentProject.notifyChanged(
093: ApiConstants.INSERT_DATA_SET, this );
094: }
095:
096: /* call from Campaign */
097: void addInModel(Campaign pCampaign) {
098: //pCampaign.addDataSet(this);
099: }
100:
101: void addInDBAndModel(Campaign pCampaign) throws Exception {
102: addInDB(pCampaign.getIdBdd());
103: addInModel(pCampaign);
104: }
105:
106: public void updateInDB(String newName, String newDesc)
107: throws Exception {
108: if (!isInBase()) {
109: throw new Exception("Dataset " + name + " is not in BDD");
110: }
111: pISQLDataset.update(idBdd, newName, newDesc);
112: Project.pCurrentProject.notifyChanged(
113: ApiConstants.UPDATE_DATA_SET, this , new String(name),
114: newName);
115: }
116:
117: public void updateInModel(String newName, String newDesc) {
118: name = newName;
119: description = newDesc;
120: }
121:
122: /*public void updateInBddAndModel(String newName, String newDesc) throws Exception {
123: updateInDB(newName, newDesc);
124: updateInModel(newName, newDesc);
125: }*/
126:
127: public void updateInDBAndModel(String newName, String newDesc)
128: throws Exception {
129: updateInDB(newName, newDesc);
130: updateInModel(newName, newDesc);
131: }
132:
133: void deleteInDB() throws Exception {
134: if (!isInBase()) {
135: throw new Exception("Dataset " + name + " is not in BDD");
136: }
137: pISQLDataset.delete(idBdd);
138: Project.pCurrentProject.notifyChanged(
139: ApiConstants.DELETE_DATA_SET, this );
140: }
141:
142: /* call from Campaign */
143: void deleteInModel() {
144: parametersHashMap.clear();
145: }
146:
147: /* call from Campaign */
148: void deleteInDBAndModel() throws Exception {
149: deleteInDB();
150: deleteInModel();
151: }
152:
153: /****************************** Parameters ********************************/
154:
155: public void reloadValuedParameters(Hashtable paramsInModel)
156: throws Exception {
157: if (!isInBase()) {
158: throw new Exception("Dataset " + name + " is not in BDD");
159: }
160: parametersHashMap.clear();
161: ValuedParameterWrapper[] definedParams = pISQLDataset
162: .getDefinedParameters(idBdd);
163: for (int i = 0; i < definedParams.length; i++) {
164: Parameter param = null;
165: ValuedParameterWrapper pValuedParameterWrapper = definedParams[i];
166: if (paramsInModel == null) {
167: param = new Parameter(pValuedParameterWrapper
168: .getParameterWrapper());
169: } else {
170: param = (Parameter) paramsInModel
171: .get(pValuedParameterWrapper
172: .getParameterWrapper().getName());
173: if (param == null) {
174: param = new Parameter(pValuedParameterWrapper
175: .getParameterWrapper());
176: paramsInModel.put(pValuedParameterWrapper
177: .getParameterWrapper().getName(), param);
178: }
179: }
180: addParameterValueInModel(param.getNameFromModel(),
181: pValuedParameterWrapper.getValue());
182: }
183: }
184:
185: public void addParameterValueInModel(String paramName, String value) {
186: parametersHashMap.put(paramName, value);
187: }
188:
189: //public void addParamValue2DB(String paramName, String value) throws Exception {
190: void addParameterValueInDB(String value, Parameter param)
191: throws Exception {
192: if (!isInBase()) {
193: throw new Exception("Dataset " + name + " is not in BDD");
194: }
195: pISQLDataset.addParamValue(idBdd, param.getIdBdd(), value);
196: }
197:
198: public void addParamValueToDBAndModel(String value, Parameter param)
199: throws Exception {
200: addParameterValueInDB(value, param);
201: addParameterValueInModel(param.getNameFromModel(), value);
202: }
203:
204: void updateParamValueInDB(Parameter param, String value, String desc)
205: throws Exception {
206: if (!isInBase()) {
207: throw new Exception("Dataset " + name + " is not in BDD");
208: }
209: pISQLDataset.updateParamValue(idBdd, param.getIdBdd(), value,
210: desc);
211: }
212:
213: public void updateParamValueInModel(String paramName, String value) {
214: removeParameterInModel(paramName);
215: addParameterValueInModel(paramName, value);
216: }
217:
218: public void updateParamValueInDBAndModel(Parameter param,
219: String value, String desc) throws Exception {
220: updateParamValueInDB(param, value, desc);
221: updateParamValueInModel(param.getNameFromModel(), value);
222: }
223:
224: public void removeParameterInModel(String paramName) {
225: parametersHashMap.remove(paramName);
226: }
227:
228: public HashMap getParametersHashMapFromModel() {
229: return parametersHashMap;
230: }
231:
232: public String getParameterValueFromModel(String paramName) {
233: return (String) parametersHashMap.get(paramName);
234: }
235:
236: public void setParametersHashMapInModel(HashMap map) {
237: parametersHashMap = map;
238: }
239:
240: public static boolean isInBase(Campaign pCamp, String datasetName) {
241: try {
242: int id = pISQLDataset.getID(pCamp.getIdBdd(), datasetName);
243: if (id > 0) {
244: return true;
245: }
246: return false;
247: } catch (Exception e) {
248:
249: }
250: return false;
251: } // Fin de la méthode isInBase/1
252:
253: public boolean existeInBase() throws Exception {
254: if (!isInBase()) {
255: return false;
256: }
257: return pISQLDataset.getWrapper(idBdd) != null;
258: }
259:
260: }
|