001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.server.ls.ejb;
034:
035: import org.libresource.LibresourceResourceBase;
036:
037: import org.libresource.so6.server.ls.util.SynchronizerResourceUtil;
038:
039: import java.sql.Connection;
040: import java.sql.Statement;
041:
042: import javax.ejb.CreateException;
043:
044: /**
045: * A libresource Synchronizer
046: *
047: * @author <a href="mailto:jourdain@loria.fr">Sebastien Jourdain</a> - <a
048: * href="http://www.inria.fr">INRIA Lorraine</a>
049: *
050: * @libresource.resource name="Synchronizer" service="LibresourceSynchronizer"
051: *
052: * @ejb.finder signature= "java.util.Collection findAll()" query ="SELECT
053: * OBJECT(s) FROM SynchronizerResource s"
054: * transaction-type="Supports"
055: */
056: public abstract class SynchronizerResourceBean extends
057: LibresourceResourceBase {
058: /**
059: * @ejb.create-method
060: */
061: public String ejbCreate(String name, String description)
062: throws CreateException {
063: setId(SynchronizerResourceUtil.generateGUID(this ));
064: setName(name);
065: setDescription(description);
066: setFileEncoding("utf-8");
067:
068: return null;
069: }
070:
071: /**
072: * @ejb.create-method
073: */
074: public String ejbCreate(String name, String description,
075: String encoding) throws CreateException {
076: setId(SynchronizerResourceUtil.generateGUID(this ));
077: setName(name);
078: setDescription(description);
079: setFileEncoding(encoding);
080:
081: return null;
082: }
083:
084: public void ejbPostCreate(String name, String description)
085: throws CreateException {
086: try {
087: // Create the patch table
088: Connection conn = LibresourceSynchronizerServiceBean
089: .getConnection();
090: Statement stmt = conn.createStatement();
091: stmt.executeUpdate(LibresourceSynchronizerServiceBean
092: .getCreatePatchTableQuery(getId()));
093: stmt.close();
094: conn.close();
095: } catch (Exception e) {
096: e.printStackTrace();
097: ctx.setRollbackOnly();
098: throw new CreateException("Command table not created : "
099: + e.getMessage());
100: }
101: }
102:
103: public void ejbPostCreate(String name, String description,
104: String encoding) {
105: try {
106: // Create the patch table
107: Connection conn = LibresourceSynchronizerServiceBean
108: .getConnection();
109: Statement stmt = conn.createStatement();
110: stmt.executeUpdate(LibresourceSynchronizerServiceBean
111: .getCreatePatchTableQuery(getId()));
112: stmt.close();
113: conn.close();
114: } catch (Exception e) {
115: e.printStackTrace();
116:
117: //ctx.setRollbackOnly();
118: // throw new CreateException("Command table not created : " +
119: // e.getMessage());
120: }
121: }
122:
123: // persistents fields
124:
125: /**
126: * @ejb.persistent-field
127: * @ejb.interface-method
128: * @ejb.value-object match="libresource"
129: * @ejb.transaction type="Supports"
130: */
131: public abstract String getId();
132:
133: /**
134: * @ejb.persistent-field
135: * @ejb.interface-method
136: * @ejb.transaction type="Mandatory"
137: */
138: public abstract void setId(String id);
139:
140: /**
141: * @ejb.interface-method
142: * @ejb.value-object match="libresource"
143: * @ejb.transaction type="Supports"
144: */
145: public String getShortResourceName() {
146: return getName();
147: }
148:
149: /**
150: * @ejb.persistent-field
151: * @ejb.interface-method
152: * @ejb.value-object match="libresource"
153: * @ejb.transaction type="Supports"
154: */
155: public abstract String getName();
156:
157: /**
158: * @ejb.persistent-field
159: * @ejb.interface-method
160: * @ejb.transaction type="Mandatory"
161: */
162: public abstract void setName(String name);
163:
164: /**
165: * @ejb.persistent-field
166: * @ejb.interface-method
167: * @ejb.value-object match="libresource"
168: * @ejb.transaction type="Supports"
169: */
170: public abstract String getDescription();
171:
172: /**
173: * @ejb.persistent-field
174: * @ejb.interface-method
175: * @ejb.transaction type="Mandatory"
176: */
177: public abstract void setDescription(String description);
178:
179: /**
180: * @ejb.persistent-field
181: * @ejb.interface-method
182: * @ejb.value-object match="libresource"
183: * @ejb.transaction type="Supports"
184: */
185: public abstract long getLastTicket();
186:
187: /**
188: * @ejb.persistent-field
189: * @ejb.interface-method
190: * @ejb.transaction type="Mandatory"
191: */
192: public abstract void setLastTicket(long lastTicket);
193:
194: /**
195: * @ejb.persistent-field
196: * @ejb.interface-method
197: * @ejb.value-object match="libresource"
198: * @ejb.transaction type="Supports"
199: */
200: public abstract String getFileEncoding();
201:
202: /**
203: * @ejb.persistent-field
204: * @ejb.interface-method
205: * @ejb.transaction type="Mandatory"
206: */
207: public abstract void setFileEncoding(String fileEncoding);
208:
209: /**
210: * @ejb.persistent-field
211: * @ejb.interface-method
212: * @ejb.value-object match="libresource"
213: * @ejb.transaction type="Supports"
214: */
215: public abstract String getBinaryExtention();
216:
217: /**
218: * @ejb.persistent-field
219: * @ejb.interface-method
220: * @ejb.transaction type="Mandatory"
221: */
222: public abstract void setBinaryExtention(String binExt);
223:
224: /**
225: * @ejb.interface-method
226: * @ejb.relation name="SynchronizerConnection"
227: * role-name="Synchronizer-of-Connections"
228: * @ejb.transaction type="Supports"
229: *
230: * @ejb.value-object aggregate="org.libresource.so6.server.ls.ejb.model.WsConnectionResourceValue"
231: * aggregate-name="WsConnection"
232: * members="org.libresource.so6.server.ls.interfaces.WsConnectionResourceLocal"
233: * members-name="WsConnectionResource"
234: * type="java.util.Collection" match="libresource"
235: * relation="external"
236: */
237: public abstract java.util.Collection getWsConnections();
238:
239: /**
240: * @ejb.interface-method
241: * @ejb.transaction type="Mandatory"
242: */
243: public abstract void setWsConnections(
244: java.util.Collection wsConnections);
245: }
|