01: /*
02: * SalomeTMF is a Test Management Framework
03: * Copyright (C) 2005 France Telecom R&D
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * @author Marche Mikael
20: *
21: * Contact: mikael.marche@rd.francetelecom.com
22: */
23:
24: package org.objectweb.salome_tmf.databaseSQL;
25:
26: import java.sql.Date;
27: import java.sql.PreparedStatement;
28:
29: import org.objectweb.salome_tmf.api.Api;
30: import org.objectweb.salome_tmf.api.ApiConstants;
31: import org.objectweb.salome_tmf.api.Util;
32: import org.objectweb.salome_tmf.api.sql.ISQLUrlAttachment;
33:
34: public class SQLUrlAttachment extends SQLAttachment implements
35: ISQLUrlAttachment {
36:
37: /**
38: * Insert an Url attchement in table ATTACHEMENT
39: * @param url
40: * @param description
41: * @return the id of the attachment
42: * @throws Exception
43: * no permission needed
44: */
45: public int insert(String url, String description) throws Exception {
46: int idAttach = -1;
47: int transNumber = -1;
48: try {
49: transNumber = SQLEngine.beginTransaction(0,
50: ApiConstants.INSERT_ATTACHMENT);
51:
52: Date pDate = Util.getCurrentDate();
53:
54: PreparedStatement prep = SQLEngine
55: .getSQLAddQuery("insertUrlAttachIntoDB"); //ok
56: prep.setString(1, url);
57: prep.setString(2, description);
58: prep.setDate(3, pDate);
59: SQLEngine.runAddQuery(prep);
60:
61: idAttach = getLastIdAttach();
62: SQLEngine.commitTrans(transNumber);
63: } catch (Exception e) {
64: Util.log("[SQLUrlAttachment->insert]" + e);
65: if (Api.isDEBUG()) {
66: e.printStackTrace();
67: }
68: SQLEngine.rollBackTrans(transNumber);
69: throw e;
70: }
71: return idAttach;
72: }
73: }
|