KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > scheduler > AtomFeeder


1 /*
2   Copyright (C) 2003 Know Gate S.L. All rights reserved.
3                       C/O�a, 107 1�2 28050 Madrid (Spain)
4
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions
7   are met:
8
9   1. Redistributions of source code must retain the above copyright
10      notice, this list of conditions and the following disclaimer.
11
12   2. The end-user documentation included with the redistribution,
13      if any, must include the following acknowledgment:
14      "This product includes software parts from hipergate
15      (http://www.hipergate.org/)."
16      Alternately, this acknowledgment may appear in the software itself,
17      if and wherever such third-party acknowledgments normally appear.
18
19   3. The name hipergate must not be used to endorse or promote products
20      derived from this software without prior written permission.
21      Products derived from this software may not be called hipergate,
22      nor may hipergate appear in their name, without prior written
23      permission.
24
25   This library is distributed in the hope that it will be useful,
26   but WITHOUT ANY WARRANTY; without even the implied warranty of
27   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28
29   You should have received a copy of hipergate License with this code;
30   if not, visit http://www.hipergate.org or mail to info@hipergate.org
31 */

32
33 package com.knowgate.scheduler;
34
35 import java.util.Date JavaDoc;
36
37 import java.sql.Connection JavaDoc;
38 import java.sql.SQLException JavaDoc;
39 import java.sql.Statement JavaDoc;
40 import java.sql.PreparedStatement JavaDoc;
41 import java.sql.ResultSet JavaDoc;
42 import java.sql.ResultSetMetaData JavaDoc;
43
44 import com.knowgate.debug.DebugFile;
45 import com.knowgate.jdc.JDCConnection;
46 import com.knowgate.dataobjs.DB;
47 import com.knowgate.dataobjs.DBBind;
48 import com.knowgate.dataobjs.DBSubset;
49 import com.knowgate.misc.Gadgets;
50 import com.knowgate.hipergate.QueryByForm;
51
52 import com.knowgate.crm.DistributionList;
53
54 import java.util.Properties JavaDoc;
55
56 /**
57  * <p>Feeds atoms to RAM based AtomQueue</p>
58  * @author Sergio Montoro Ten
59  * @version 2.0
60  */

61 public class AtomFeeder {
62   private int iMaxBatchSize;
63
64   public AtomFeeder() {
65     iMaxBatchSize = 10000;
66   }
67
68   // ----------------------------------------------------------
69

70   public void setMaxBatchSize(int iMaxBatch) {
71     iMaxBatchSize = iMaxBatch;
72   }
73
74   // ----------------------------------------------------------
75

76   public int getMaxBatchSize() {
77     return iMaxBatchSize;
78   }
79
80   // ----------------------------------------------------------
81

82   /**
83    * <p>Load a dynamic list of members from k_member_address to k_job_atoms</p>
84    * <p>Registers will be filtered according to the query stored at k_queries table
85    * witch corresponds to the list at k_lists used by Job being loaded.</p>
86    * @param oConn Database Connection
87    * @param sJobGUID Job to be loaded
88    * @param dtExec Scheduled Execution DateTime
89    * @param sListGUID Base List GUID
90    * @param sQueryGUID GUID of Query to be used for member filtering upon retrieval
91    * @param sWorkAreaGUID GUID of WorArea
92    * @throws SQLException
93    */

94
95   private int loadDynamicList(JDCConnection oConn, String JavaDoc sJobGUID, Date JavaDoc dtExec, String JavaDoc sListGUID, String JavaDoc sQueryGUID, String JavaDoc sWorkAreaGUID) throws SQLException JavaDoc {
96     Statement JavaDoc oStmt;
97     QueryByForm oQBF;
98     String JavaDoc sSQL;
99     int iInserted;
100
101     if (DebugFile.trace) {
102        DebugFile.writeln("Begin AtomFeeder.loadDynamicList([Connection] , " + sJobGUID + "," + dtExec.toString() + "," + sQueryGUID + "," + sWorkAreaGUID + " )");
103        DebugFile.incIdent();
104      }
105
106     // Lista de columnas de la table k_member_address
107
String JavaDoc sColumns = "gu_company,gu_contact,tx_email,tx_name,tx_surname,tx_salutation,nm_commercial,tp_street,nm_street,nu_street,tx_addr1,tx_addr2,nm_country,nm_state,mn_city,zipcode,work_phone,direct_phone,home_phone,mov_phone,fax_phone,other_phone,po_box";
108
109     // Componer la sentencia SQL de filtrado de datos a partir de la definici�n de la consulta almacenada en la tabla k_queries
110
oQBF = new QueryByForm(oConn, DB.k_member_address, "ma", sQueryGUID);
111
112     // Insertar los registros a cap�n haciendo un snapshot de k_member_address a k_job_atoms
113
oStmt = oConn.createStatement();
114
115     sSQL = "INSERT INTO " + DB.k_job_atoms +
116            " (gu_job,id_status," + sColumns + ") " +
117            " (SELECT '" + sJobGUID + "'," + String.valueOf(Atom.STATUS_PENDING) +
118            "," + sColumns + " FROM " + DB.k_member_address + " ma WHERE ma.gu_workarea='" + sWorkAreaGUID +
119            "' AND (" + oQBF.composeSQL() + ") AND NOT EXISTS (SELECT x." + DB.tx_email +
120            " FROM " + DB.k_lists + " b, " + DB.k_x_list_members + " x WHERE b." +
121            DB.gu_list + "=x." + DB.gu_list + " AND b." + DB.gu_query + "='" + sListGUID +
122            "' AND b." + DB.tp_list + "=" + String.valueOf(DistributionList.TYPE_BLACK) +
123            " AND x." + DB.tx_email + "=ma." + DB.tx_email + "))";
124
125     if (DebugFile.trace) DebugFile.writeln("Connection.executeUpdate(" + sSQL + ")");
126
127     iInserted = oStmt.executeUpdate(sSQL);
128
129     oStmt.close();
130
131     if (DebugFile.trace) {
132        DebugFile.decIdent();
133
134        DebugFile.writeln("End AtomFeeder.loadDynamicList() : " + String.valueOf(iInserted));
135      }
136      return iInserted;
137   } // loadDynamicList()
138

139   // ----------------------------------------------------------
140

141   /**
142    * <p>Load a static member list from k_x_list_members to k_job_atoms</p>
143    * @param oConn Database Connection
144    * @param sJobGUID GUID of Job to be loaded
145    * @param dtExec Execution date to be assigned to Atoms (inherited from job)
146    * @param sListGUID GUID of list to be loaded
147    * @throws SQLException
148    */

149   private int loadStaticList(JDCConnection oConn, String JavaDoc sJobGUID, Date JavaDoc dtExec, String JavaDoc sListGUID) throws SQLException JavaDoc {
150     Statement JavaDoc oStmt;
151     String JavaDoc sSQL;
152     int iInserted;
153
154     if (DebugFile.trace) {
155        DebugFile.writeln("Begin AtomFeeder.loadStaticList([Connection] , " + sJobGUID + "," + dtExec.toString() + "," + sListGUID + ")");
156        DebugFile.incIdent();
157      }
158
159     // Lista de columnas de la table k_x_list_members
160
// * TO DO: A�adir el resto de columnas que faltan para reemplazar direcciones
161
String JavaDoc sColumns = "id_format,gu_company,gu_contact,tx_email,tx_name,tx_surname,tx_salutation";
162
163     // Insertar los registros a cap�n haciendo un snapshot de k_member_address a k_job_atoms
164
oStmt = oConn.createStatement();
165
166     sSQL = "INSERT INTO " + DB.k_job_atoms +
167            " (gu_job,id_status," + sColumns + ") " +
168            " (SELECT '" + sJobGUID + "'," + String.valueOf(Atom.STATUS_PENDING) +
169            "," + sColumns + " FROM " + DB.k_x_list_members + " m WHERE " +
170            DB.gu_list + "='" + sListGUID + "' AND m." + DB.bo_active + "<>0 AND " +
171            "NOT EXISTS (SELECT x." + DB.tx_email + " FROM " + DB.k_lists + " b, " +
172            DB.k_x_list_members + " x WHERE b." + DB.gu_list + "=x." + DB.gu_list +
173            " AND b." + DB.gu_query + "='" + sListGUID + "' AND b." + DB.tp_list +
174            "=" + String.valueOf(DistributionList.TYPE_BLACK) + " AND x." + DB.tx_email + "=m." + DB.tx_email + "))";
175
176     if (DebugFile.trace) DebugFile.writeln("Connection.executeUpdate(" + sSQL + ")");
177
178     iInserted = oStmt.executeUpdate(sSQL);
179     oStmt.close();
180
181     if (DebugFile.trace) {
182        DebugFile.decIdent();
183        DebugFile.writeln("End AtomFeeder.loadStaticList() : " + String.valueOf(iInserted));
184      }
185
186      return iInserted;
187   } // loadStaticList()
188

189   // ----------------------------------------------------------
190

191   /**
192    * <p>Load direct list into k_job_atoms table</p>
193    * @param oConn Database Connection
194    * @param sJobGUID GUID of Job to be loaded
195    * @param dtExec Execution date to be assigned to Atoms (inherited from job)
196    * @param sListGUID GUID of list to be loaded
197    * @throws SQLException
198    */

199
200   private int loadDirectList(JDCConnection oConn, String JavaDoc sJobGUID, Date JavaDoc dtExec, String JavaDoc sListGUID) throws SQLException JavaDoc {
201
202     // Alimentar una lista directa se hace igual que una est�tica
203
return loadStaticList(oConn, sJobGUID, dtExec, sListGUID);
204   } // loadDirectList()
205

206   // ----------------------------------------------------------
207

208   private Properties JavaDoc parseParameters(String JavaDoc sTxParams) {
209     String JavaDoc aVariable[];
210     String JavaDoc aParams[];
211     Properties JavaDoc oParams = new Properties JavaDoc();
212
213     if (DebugFile.trace) {
214        DebugFile.writeln("Begin AtomFeeder.parseParameters(" + sTxParams + ")");
215        DebugFile.incIdent();
216      }
217
218     if (sTxParams!=null) {
219       if (sTxParams.length()>0) {
220         aParams = Gadgets.split(sTxParams, ",");
221
222         for (int p = 0; p < aParams.length; p++) {
223           aVariable = Gadgets.split(aParams[p], ":");
224           oParams.put(aVariable[0], aVariable[1]);
225         } // next (p)
226
} // fi (sTxParams!="")
227
} // fi (sTxParams!=null)
228

229     if (DebugFile.trace) {
230        DebugFile.decIdent();
231        DebugFile.writeln("End AtomFeeder.parseParameters() : " + String.valueOf(oParams.size()));
232      }
233
234     return oParams;
235   } // parseParameters
236

237   // ----------------------------------------------------------
238

239   /**
240    * <p>Load an Atom batch into k_job_atoms table</p>
241    * <p>Atoms will be taken by looking up pending Jobs by its execution date and extracting Atoms
242    * for nearest Jobs in time.<br>
243    * On each loadAtoms() no more than iWorkerThreads Jobs will be loaded at a time.
244    * @param oConn Database Connection
245    * @param iWorkerThreads Number of worker thread. This parameter will limit the number of loaded Jobs as the program will try to use a one to one ratio between Jobs and WorkerThreads.
246    * @return DBSubset with loaded Jobs
247    * @throws SQLException
248    */

249
250   public DBSubset loadAtoms(JDCConnection oConn, int iWorkerThreads) throws SQLException JavaDoc {
251
252     PreparedStatement JavaDoc oJobStmt;
253     DBSubset oJobsSet;
254     int iJobCount;
255     Properties JavaDoc oParams;
256     DistributionList oDistribList;
257     Date JavaDoc dtNow = new Date JavaDoc();
258     Date JavaDoc dtExec;
259     String JavaDoc sSQL;
260     int iLoaded = 0;
261
262     if (DebugFile.trace) {
263        DebugFile.writeln("Begin AtomFeeder.loadAtoms([Connection], " + String.valueOf(iWorkerThreads) + ")");
264        DebugFile.incIdent();
265      }
266
267     // Crea un DBSubset para recorrer los jobs pendientes de ejecuci�n
268

269     oJobsSet = new DBSubset(DB.k_jobs,
270                             "gu_job,gu_job_group,gu_workarea,id_command,tx_parameters,id_status,dt_execution,dt_finished,dt_created,dt_modified",
271                             DB.id_status + "=" + String.valueOf(Job.STATUS_PENDING) + " ORDER BY " + DB.dt_execution + " DESC", iWorkerThreads);
272
273     oJobsSet.setMaxRows(iWorkerThreads);
274
275     iJobCount = oJobsSet.load(oConn); // Devuelve la cuenta de jobs pendientes
276

277     // Prepara la sentencia para actualizar el estado de los jobs a Running
278
sSQL = "UPDATE " + DB.k_jobs + " SET " + DB.id_status + "=" + String.valueOf(Job.STATUS_RUNNING) + "," + DB.dt_execution + "=" + DBBind.Functions.GETDATE + " WHERE " + DB.gu_job + "=?";
279
280     if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sSQL + ")");
281
282     oJobStmt = oConn.prepareStatement(sSQL);
283
284     // Para cada job, cargar su lista de miembros del tipo que corresponda y
285
// cambiar el estado a Running
286
for (int j=0; j<iJobCount; j++) {
287       // leer los par�metros adicionales del job del campo tx_parameters
288
oParams = parseParameters(oJobsSet.getString(4, j));
289
290       // Generar un objeto temporal de tipo lista de distribuci�n
291
// para leer los valores de la lista de miembros
292
if (oParams.getProperty("gu_list")!=null) {
293         oDistribList = new DistributionList(oConn, oParams.getProperty("gu_list"));
294
295         // Si la fecha de ejecuci�n del job es null,
296
// tomar la fecha actual como fecha de ejecuci�n inmediata
297
if (oDistribList.isNull(DB.dt_execution))
298           dtExec = dtNow;
299         else
300           dtExec = oDistribList.getDate(DB.dt_execution);
301
302         // Para cada tipo de lista usar el m�todo de carga de miembros que corresponda
303
switch (oDistribList.getShort(DB.tp_list)) {
304           case DistributionList.TYPE_DYNAMIC:
305             iLoaded += loadDynamicList(oConn, oJobsSet.getString(0, j), dtExec, oParams.getProperty("gu_list"), oDistribList.getString(DB.gu_query), oDistribList.getString(DB.gu_workarea));
306             break;
307           case DistributionList.TYPE_STATIC:
308             iLoaded += loadStaticList(oConn, oJobsSet.getString(0, j), dtExec, oParams.getProperty("gu_list"));
309             break;
310           case DistributionList.TYPE_DIRECT:
311             iLoaded += loadDirectList(oConn, oJobsSet.getString(0, j), dtExec, oParams.getProperty("gu_list"));
312             break;
313         } // end switch()
314
}
315       else
316         iLoaded = 0;
317
318       // Cambiar el estado del job cargado de Pending a Running
319

320       if (DebugFile.trace) DebugFile.writeln("PrepareStatement.setString(1, '" + oJobsSet.getStringNull(0, j, "") + "')");
321
322       oJobStmt.setString (1, oJobsSet.getString(0, j));
323
324       if (DebugFile.trace) DebugFile.writeln("PrepareStatement.executeUpdate()");
325
326       oJobStmt.executeUpdate();
327     } // next (j)
328

329     if (DebugFile.trace) DebugFile.writeln("PrepareStatement.close()");
330
331     oJobStmt.close();
332
333     if (DebugFile.trace) {
334        DebugFile.decIdent();
335        DebugFile.writeln("End AtomFeeder.loadAtoms() : " + String.valueOf(oJobsSet.getRowCount()));
336      }
337
338      return oJobsSet;
339   } // loadAtoms()
340

341   // ----------------------------------------------------------
342

343   /**
344    * <p>Load Atoms for a given Job into k_job_atoms table</p>
345    * On each loadAtoms() no more than iWorkerThreads Jobs will be loaded at a time.
346    * @param oConn Database Connection
347    * @param sJodId GUID of Job for witch atoms are to be loaded.
348    * @return DBSubset with loaded Job
349    * @throws SQLException
350    */

351
352   public DBSubset loadAtoms(JDCConnection oConn, String JavaDoc sJobId) throws SQLException JavaDoc {
353     PreparedStatement JavaDoc oCmdsStmt;
354     PreparedStatement JavaDoc oJobStmt;
355     ResultSet JavaDoc oCmdsSet;
356     DBSubset oJobsSet;
357     int iJobCount;
358     String JavaDoc aParams[];
359     String JavaDoc aVariable[];
360     Properties JavaDoc oParams;
361     DistributionList oDistribList;
362     Date JavaDoc dtNow = new Date JavaDoc();
363     Date JavaDoc dtExec;
364     String JavaDoc sSQL;
365     int iLoaded = 0;
366
367     if (DebugFile.trace) {
368        DebugFile.writeln("Begin AtomFeeder.loadAtoms([Connection], " + sJobId + ")");
369        DebugFile.incIdent();
370      }
371
372     // Crea un DBSubset para recorrer los jobs pendientes de ejecuci�n
373

374     oJobsSet = new DBSubset(DB.k_jobs,
375                             "gu_job,gu_job_group,gu_workarea,id_command,tx_parameters,id_status,dt_execution,dt_finished,dt_created,dt_modified",
376                             DB.gu_job + "='" + sJobId + "'", 1);
377
378
379     iJobCount = oJobsSet.load(oConn); // Devuelve la cuenta de jobs pendientes
380

381     // Prepara la sentencia para actualizar el estado de los jobs a Running
382
sSQL = "UPDATE " + DB.k_jobs + " SET " + DB.id_status + "=" + String.valueOf(Job.STATUS_RUNNING) + "," + DB.dt_execution + "=" + DBBind.Functions.GETDATE + " WHERE " + DB.gu_job + "=?";
383
384     if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sSQL + ")");
385
386     oJobStmt = oConn.prepareStatement(sSQL);
387
388     // Para cada job, cargar su lista de miembros del tipo que corresponda y
389
// cambiar el estado a Running
390
if (1==iJobCount) {
391       // leer los par�metros adicionales del job del campo tx_parameters
392
oParams = parseParameters(oJobsSet.getString(4, 0));
393
394       // Generar un objeto temporal de tipo lista de distribuci�n
395
// para leer los valores de la lista de miembros
396
if (oParams.getProperty("gu_list")!=null) {
397         oDistribList = new DistributionList(oConn, oParams.getProperty("gu_list"));
398
399         // Si la fecha de ejecuci�n del job es null,
400
// tomar la fecha actual como fecha de ejecuci�n inmediata
401
if (oDistribList.isNull(DB.dt_execution))
402           dtExec = dtNow;
403         else
404           dtExec = oDistribList.getDate(DB.dt_execution);
405
406         // Para cada tipo de lista usar el m�todo de carga de miembros que corresponda
407
switch (oDistribList.getShort(DB.tp_list)) {
408           case DistributionList.TYPE_DYNAMIC:
409             iLoaded += loadDynamicList(oConn, oJobsSet.getString(0, 0), dtExec, oParams.getProperty("gu_list"), oDistribList.getString(DB.gu_query), oDistribList.getString(DB.gu_workarea));
410             break;
411           case DistributionList.TYPE_STATIC:
412             iLoaded += loadStaticList(oConn, oJobsSet.getString(0, 0), dtExec, oParams.getProperty("gu_list"));
413             break;
414           case DistributionList.TYPE_DIRECT:
415             iLoaded += loadDirectList(oConn, oJobsSet.getString(0, 0), dtExec, oParams.getProperty("gu_list"));
416             break;
417         } // end switch()
418
}
419       else
420         iLoaded = 0;
421
422       // Cambiar el estado del job cargado de Pending a Running
423

424       if (DebugFile.trace) DebugFile.writeln("PrepareStatement.setString(1, '" + oJobsSet.getStringNull(0, 0, "") + "')");
425
426       oJobStmt.setString (1, oJobsSet.getString(0, 0));
427
428       if (DebugFile.trace) DebugFile.writeln("PrepareStatement.executeUpdate()");
429
430       oJobStmt.executeUpdate();
431     } // fi
432

433     if (DebugFile.trace) DebugFile.writeln("PrepareStatement.close()");
434
435     oJobStmt.close();
436
437     if (DebugFile.trace) {
438        DebugFile.decIdent();
439        DebugFile.writeln("End AtomFeeder.loadAtoms() : " + sJobId);
440      }
441
442      return oJobsSet;
443   } // loadAtoms()
444

445   // ----------------------------------------------------------
446

447   /**
448    * <p>Feed RAM queue with pending Atoms from k_job_atoms table</p>
449    * @param oConn Database Connection
450    * @param oQueue AtomQueue
451    * @throws SQLException
452    */

453
454   public void feedQueue(JDCConnection oConn, AtomQueue oQueue) throws SQLException JavaDoc {
455     Statement JavaDoc oStmt;
456     PreparedStatement JavaDoc oUpdt;
457     PreparedStatement JavaDoc oPgSt;
458     ResultSet JavaDoc oRSet;
459     ResultSetMetaData JavaDoc oMDat;
460     String JavaDoc sJobId;
461     int iAtomId;
462     int iJobCol;
463     int iAtmCol;
464     int iProcessed;
465     String JavaDoc sSQL;
466     Atom oAtm;
467     boolean bNext;
468
469     if (DebugFile.trace) {
470        DebugFile.writeln("Begin AtomFeeder.feedQueue([Connection], [AtomQueue])");
471        DebugFile.incIdent();
472      }
473
474     // Crear un cursor actualizable para recorrer los �tomos y cargarlos en la cola
475
// al mismo tiempo que se cambia en la base de datos su estado de Pending a Running
476
oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
477
478     sSQL = "SELECT a.*, j." + DB.tx_parameters + " FROM " + DB.k_job_atoms + " a, " + DB.k_jobs + " j WHERE a." + DB.id_status + "=" + String.valueOf(Atom.STATUS_PENDING) + " AND j." + DB.gu_job + "=a." + DB.gu_job + " ORDER BY j." + DB.dt_execution;
479
480     if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(" + sSQL + ")");
481
482     oRSet = oStmt.executeQuery(sSQL);
483
484     try {
485       oRSet.setFetchSize (getMaxBatchSize());
486     } catch (SQLException JavaDoc e) { /* Si el driver no soporta setFetchSize da igual */ }
487
488     oMDat = oRSet.getMetaData();
489     iJobCol = oRSet.findColumn(DB.gu_job);
490     iAtmCol = oRSet.findColumn(DB.pg_atom);
491
492     // Bucle de carga y actualizaci�n de estado de job_atoms
493

494     sSQL = "UPDATE " + DB.k_job_atoms + " SET " + DB.id_status + "=" + Atom.STATUS_RUNNING + " WHERE " + DB.gu_job + "=? AND " + DB.pg_atom + "=?";
495     if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sSQL + ")");
496     oUpdt = oConn.prepareStatement(sSQL);
497
498     iProcessed = 0;
499
500     bNext = oRSet.next();
501
502     while (bNext && iProcessed<iMaxBatchSize) {
503       oAtm = new Atom(oRSet, oMDat);
504
505       oQueue.push (oAtm);
506
507       sJobId = oRSet.getString(iJobCol);
508       iAtomId = oRSet.getInt(iAtmCol);
509
510       bNext = oRSet.next();
511
512       oUpdt.setString(1, sJobId);
513       oUpdt.setInt (2, iAtomId);
514
515       if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate(UPDATE " + DB.k_job_atoms + " SET " + DB.id_status + "=" + Atom.STATUS_RUNNING + " WHERE " + DB.gu_job + "='" + sJobId + "' AND " + DB.pg_atom + "=" + String.valueOf(iAtomId) +")");
516       oUpdt.executeUpdate();
517
518       iProcessed++;
519     } // wend
520

521     oUpdt.close();
522     oRSet.close();
523     oStmt.close();
524
525     if (DebugFile.trace) {
526        DebugFile.decIdent();
527        DebugFile.writeln("End AtomFeeder.feedQueue() : " + String.valueOf(iProcessed));
528      }
529   } // feedQueue
530

531   /**
532    * Formatea una fecha en formato escape ODBC
533    * @param dt Fecha a formatear
534    * @param sFormat tipo de formato {d=yyyy-mm-dd, ts=yyyy-mm-dd hh:nn:ss}
535    * @return Fecha formateada como una cadena
536    */

537
538   private static String JavaDoc escape(java.util.Date JavaDoc dt) {
539       String JavaDoc str;
540       String JavaDoc sMonth, sDay, sHour, sMin, sSec;
541
542       str = "{ ts '";
543
544       sMonth = (dt.getMonth()+1<10 ? "0" + String.valueOf((dt.getMonth()+1)) : String.valueOf(dt.getMonth()+1));
545       sDay = (dt.getDate()<10 ? "0" + String.valueOf(dt.getDate()) : String.valueOf(dt.getDate()));
546
547       str += String.valueOf(dt.getYear()+1900) + "-" + sMonth + "-" + sDay + " ";
548
549       sHour = (dt.getHours()<10 ? "0" + String.valueOf(dt.getHours()) : String.valueOf(dt.getHours()));
550       sMin = (dt.getMinutes()<10 ? "0" + String.valueOf(dt.getMinutes()) : String.valueOf(dt.getMinutes()));
551       sSec = (dt.getSeconds()<10 ? "0" + String.valueOf(dt.getSeconds()) : String.valueOf(dt.getSeconds()));
552
553       str += " " + sHour + ":" + sMin + ":" + sSec;
554
555       str = str.trim() + "'}";
556
557       return str;
558   } // escape()
559

560   // ----------------------------------------------------------
561

562 } // AtomFeeder
563
Free Books   Free Magazines  
Popular Tags