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 package org.openmobileis.synchro.algo.syncnumber.impl;
00029
00030 import java.sql.*;
00031
00032 import org.openmobileis.common.util.database.AbstractQueryManager;
00033 import org.openmobileis.common.util.database.JdbcPoolManagerDB;
00034 import org.openmobileis.common.util.exception.ServiceException;
00035
00046 public class MSSQLSyncNumberQueryManager extends AbstractQueryManager implements SyncNumberQueryManager {
00047
00048
00049 private static String queryUpdate =
00050 "UPDATE SYNC_ID SET SYNCNUMBER=%0% , TIME_STAMP=%1% " +
00051 "WHERE SYNCNUMBER=%2%";
00052
00053 private static String queryCreate =
00054 "INSERT INTO SYNC_ID (SYNCNUMBER , TIME_STAMP) " +
00055 "VALUES (%0%, %1%)";
00056
00057
00058 private static String queryCreateTable =
00059 "CREATE TABLE SYNC_ID ("
00060 +" SYNCNUMBER BIGINT NOT NULL,"
00061 +" TIME_STAMP BIGINT NOT NULL,"
00062 +" CONSTRAINT syncnum PRIMARY KEY (SYNCNUMBER)"
00063 +")";
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
00082 public MSSQLSyncNumberQueryManager(){}
00083
00084 public MSSQLSyncNumberQueryManager(JdbcPoolManagerDB pool){
00085 this.registerManagerDB(pool);
00086 }
00087
00097 public void create (String parameters[]) throws ServiceException {
00098 this.executeUpdate(queryCreate, parameters);
00099 }
00100
00101
00102
00103
00104 public void createSyncTable() throws ServiceException, java.sql.SQLException {
00105 try {
00106 Connection con = this.getDbManager().getConnection();
00107 DatabaseMetaData dbmd = con.getMetaData();
00108 String[] tableType = {"TABLE"};
00109 ResultSet result = dbmd.getTables (null,null,"sync_id", tableType);
00110 if (!result.next()) {
00111 this.executeUpdate(queryCreateTable, null);
00112 String[] data = {"0", "0"};
00113 this.create(data);
00114 }
00115 } finally {
00116 this.getDbManager().garbageOpenedConnection();
00117 }
00118 }
00124
00125
00126
00127
00134 public void delete (String parameters[]) throws ServiceException {
00135 this.executeUpdate(queryDelete, parameters);
00136 }
00137
00144 public void update (String parameters[]) throws ServiceException {
00145 this.executeUpdate(queryUpdate, parameters);
00146 }
00147
00148
00155 public ResultSet getTimeStampForsn (String parameters[]) throws ServiceException {
00156 return (this.executeQuery(queryGetTimeStamp, parameters));
00157 }
00158
00164 public ResultSet getLastSyncNumber () throws ServiceException {
00165 return (this.executeQuery(queryGetMax, null));
00166 }
00167
00174 public ResultSet getSyncNumberbysn (String parameters[]) throws ServiceException {
00175 return this.getTimeStampForsn(parameters);
00176 }
00177
00178 }
00179
00180