Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

OracleSafeServerSyncNumberQueryManager.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  * 
00027  */
00028 
00029 package org.openmobileis.synchro.algo.syncnumber.impl;
00030 
00031 import org.openmobileis.common.util.database.AbstractQueryManager;
00032 import org.openmobileis.common.util.exception.ServiceException;
00033 
00034 import java.sql.ResultSet;
00035 import java.sql.Connection;
00036 import java.sql.DatabaseMetaData;
00037 
00038 
00049 public class OracleSafeServerSyncNumberQueryManager  extends AbstractQueryManager  implements SyncNumberQueryManager {
00050 
00051    private static String queryCreate  =
00052      "INSERT INTO SYNC_ID (SYNCNUMBER , TIME_STAMP) " +
00053       "VALUES (%0%, sysdate)";
00054 
00055   // query pattern used to create syncNB table
00056   private static String queryCreateTable  =
00057                 "CREATE TABLE SYNC_ID ("
00058                 +" SYNCNUMBER NUMBER(16) NOT NULL,"
00059                 +" TIME_STAMP DATE,"
00060                 +" CONSTRAINT SYNCNUM PRIMARY KEY (SYNCNUMBER)"
00061                 +") pctfree 10 tablespace datacbc " +
00062                         "storage (initial 768K next 50K maxextents 249 " +
00063                         "pctincrease 0)";
00064 
00065  /* private static String existsTable  =
00066    "select count(*) from SYSTEM_COLUMNS where TABLE_NAME like 'SYNC_ID'";*/
00067 
00068   // query pattern used to delete a user and its version number
00069   private static String queryDelete =
00070     "DELETE FROM SYNC_ID WHERE SYNCNUMBER = %0%";
00071 
00072 
00073   /********  SELECT QUERIES ********************/
00074 
00075   // query pattern used to get the current version number
00076   private static String queryGetTimeStamp  =
00077     "SELECT TIME_STAMP  FROM SYNC_ID WHERE SYNCNUMBER = %0% ";
00078 
00079   private static String queryGetMax  =
00080     "SELECT Max(SYNCNUMBER)  FROM SYNC_ID";
00081   
00091   public void create (String parameters[]) throws ServiceException {
00092     this.executeUpdate(queryCreate, parameters);
00093   }
00094 
00095   /*
00096   * check if the sync table exists. IF it does not exist, create it
00097   */
00098   public void createSyncTable() throws ServiceException, java.sql.SQLException {
00099     try {
00100       Connection con = this.getDbManager().getConnection();
00101       DatabaseMetaData dbmd = con.getMetaData();
00102       String[] tableType = {"TABLE"};
00103       ResultSet result = dbmd.getTables (null,null,"SYNC_ID", tableType);
00104       if (!result.next()) {
00105         this.executeUpdate(queryCreateTable, null);
00106 //        String[] data = {"0", "0"};
00107 //        this.create(data);
00108         this.executeUpdate("INSERT INTO SYNC_ID (SYNCNUMBER , TIME_STAMP) VALUES (0, "+OracleUtils.getDateFromLong(0)+")", null);
00109       }
00110     } finally {
00111                         this.getDbManager().garbageOpenedConnection();
00112     }
00113   }
00119  // public void createTable() throws ServiceException {
00120 //    this.executeUpdate(queryCreateTable, new String[0]);
00121 //  }
00122 
00129  public void delete (String parameters[]) throws ServiceException {
00130     this.executeUpdate(queryDelete, parameters);
00131     }
00132 
00139  public void update (String parameters[]) throws ServiceException {};
00140 
00141 
00148  public ResultSet getTimeStampForsn (String parameters[]) throws ServiceException {
00149     return (this.executeQuery(queryGetTimeStamp, parameters));
00150   }
00151 
00157    public ResultSet getLastSyncNumber () throws ServiceException {
00158       return (this.executeQuery(queryGetMax, null));
00159   }
00160 
00167   public ResultSet getSyncNumberbysn (String parameters[]) throws ServiceException  {
00168     return this.getTimeStampForsn(parameters);
00169   }
00170 
00171 }
00172 
00173 

Generated on Wed Dec 14 21:05:34 2005 for OpenMobileIS by  doxygen 1.4.4