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.io.Serializable;
027:
028: import org.objectweb.salome_tmf.api.Api;
029: import org.objectweb.salome_tmf.api.ApiConstants;
030: import org.objectweb.salome_tmf.api.data.ParameterWrapper;
031: import org.objectweb.salome_tmf.api.data.ProjectWrapper;
032: import org.objectweb.salome_tmf.api.sql.ISQLParameter;
033:
034: public class Parameter extends SimpleData {
035:
036: static ISQLParameter pISQLParameter = null;
037:
038: public Parameter(String name, String description) {
039: super (name, description);
040: if (pISQLParameter == null) {
041: pISQLParameter = Api.getISQLObjectFactory()
042: .getISQLParameter();
043: }
044: }
045:
046: public Parameter(ParameterWrapper pParameterWrapper) {
047: super (pParameterWrapper.getName(), pParameterWrapper
048: .getDescription());
049: idBdd = pParameterWrapper.getIdBDD();
050: if (pISQLParameter == null) {
051: pISQLParameter = Api.getISQLObjectFactory()
052: .getISQLParameter();
053: }
054: }
055:
056: public void clearCache() {
057: /* NOTHING */
058: }
059:
060: public void reloadFromDB() throws Exception {
061: if (isInBase()) {
062: throw new Exception("Parameter " + name
063: + " is already in BDD");
064: }
065: ParameterWrapper pParameterWrapper = pISQLParameter
066: .getParameterWrapper(idBdd);
067: name = pParameterWrapper.getName();
068: description = pParameterWrapper.getDescription();
069: }
070:
071: public boolean equals(Object o) {
072: Parameter testedParameter;
073: boolean test = false;
074: if (!(o instanceof Parameter)) {
075: return false;
076: }
077: testedParameter = (Parameter) o;
078: if (isInBase() && testedParameter.isInBase()) {
079: test = idBdd == testedParameter.idBdd;
080: } else {
081: test = name.equals(testedParameter.getNameFromModel());
082: }
083: return test;
084: }
085:
086: void addInDB(int IdProject) throws Exception {
087: if (isInBase()) {
088: throw new Exception("Parameter " + name
089: + " is already in BDD");
090: }
091: idBdd = pISQLParameter.insert(IdProject, name, description);
092: Project.pCurrentProject.notifyChanged(
093: ApiConstants.INSERT_PARAMETER, this );
094: }
095:
096: public void updateDescriptionInDB(String newDesc) throws Exception {
097: if (!isInBase()) {
098: throw new Exception("Parameter " + name + " is not in BDD");
099: }
100: pISQLParameter.updateDescription(idBdd, newDesc);
101: Project.pCurrentProject.notifyChanged(
102: ApiConstants.UPDATE_PARAMETER, this );
103: }
104:
105: /*public void updateDescriptionInModel(String newDesc) {
106: description = newDesc;
107: }*/
108:
109: public void updateNameInModel(String name) {
110: this .name = name;
111: }
112:
113: public void updateDescriptionInDBAndModel(String newDesc)
114: throws Exception {
115: //BDD
116: updateDescriptionInDB(newDesc);
117:
118: //Model
119: updateDescriptionInModel(newDesc);
120: }
121:
122: public void updateInDBAndModel(String newName, String newDesc)
123: throws Exception {
124: updateDescriptionInDB(newDesc);
125: updateDescriptionInModel(newDesc);
126: }
127:
128: void deleteInDB() throws Exception {
129: pISQLParameter.delete(idBdd);
130: Project.pCurrentProject.notifyChanged(
131: ApiConstants.DELETE_PARAMETER, this );
132: }
133:
134: public static boolean isInBase(Project pProject, String paramName) {
135: try {
136: int id = pISQLParameter.selectID(pProject.getIdBdd(),
137: paramName);
138: if (id > 0) {
139: return true;
140: }
141: return false;
142: } catch (Exception e) {
143:
144: }
145: return false;
146: } // Fin de la méthode isInBase/1
147:
148: public boolean existeInBase() throws Exception {
149: if (!isInBase()) {
150: return false;
151: }
152: return pISQLParameter.getParameterWrapper(idBdd) != null;
153: //return pISQLParameter.selectID(DataLoader.getCurrentProject().getIdBdd(), name) == idBdd;
154: }
155: }
|