00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
00066
00067
00068
00069 private static String queryDelete =
00070 "DELETE FROM SYNC_ID WHERE SYNCNUMBER = %0%";
00071
00072
00073
00074
00075
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
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
00107
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
00120
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