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 package org.openmobileis.synchro.algo.syncnumber.impl;
00027
00028 import java.sql.*;
00029
00030 import org.openmobileis.common.util.database.AbstractQueryManager;
00031 import org.openmobileis.common.util.database.JdbcPoolManagerDB;
00032 import org.openmobileis.common.util.exception.DatabaseException;
00033
00044 public class MSSQLSyncNumberQueryManager extends AbstractQueryManager implements SyncNumberQueryManager {
00045
00046
00047 private static String queryUpdate =
00048 "UPDATE SYNC_ID SET SYNCNUMBER=%0% , TIME_STAMP=%1% " +
00049 "WHERE SYNCNUMBER=%2%";
00050
00051 private static String queryCreate =
00052 "INSERT INTO SYNC_ID (SYNCNUMBER , TIME_STAMP) " +
00053 "VALUES (%0%, %1%)";
00054
00055
00056 private static String queryCreateTable =
00057 "CREATE TABLE SYNC_ID ("
00058 +" SYNCNUMBER BIGINT NOT NULL,"
00059 +" TIME_STAMP BIGINT NOT NULL,"
00060 +" CONSTRAINT syncnum PRIMARY KEY (SYNCNUMBER)"
00061 +")";
00062
00063
00064
00065
00066
00067 private static String queryDelete =
00068 "DELETE FROM SYNC_ID WHERE SYNCNUMBER = %0%";
00069
00070
00071
00072
00073
00074 private static String queryGetTimeStamp =
00075 "SELECT TIME_STAMP FROM SYNC_ID WHERE SYNCNUMBER = %0% ";
00076
00077 private static String queryGetMax =
00078 "SELECT Max(SYNCNUMBER) FROM SYNC_ID";
00079
00080 public MSSQLSyncNumberQueryManager(){}
00081
00082 public MSSQLSyncNumberQueryManager(JdbcPoolManagerDB pool){
00083 this.registerManagerDB(pool);
00084 }
00085
00095 public void create (String parameters[]) throws DatabaseException {
00096 this.executeUpdate(queryCreate, parameters);
00097 }
00098
00099
00100
00101
00102 public void createSyncTable() throws DatabaseException, java.sql.SQLException {
00103 try {
00104 Connection con = this.getDbManager().getConnection();
00105 DatabaseMetaData dbmd = con.getMetaData();
00106 String[] tableType = {"TABLE"};
00107 ResultSet result = dbmd.getTables (null,null,"sync_id", tableType);
00108 if (!result.next()) {
00109 this.executeUpdate(queryCreateTable, null);
00110 String[] data = {"0", "0"};
00111 this.create(data);
00112 }
00113 } finally {
00114 this.getDbManager().garbageOpenedConnection();
00115 }
00116 }
00122
00123
00124
00125
00132 public void delete (String parameters[]) throws DatabaseException {
00133 this.executeUpdate(queryDelete, parameters);
00134 }
00135
00142 public void update (String parameters[]) throws DatabaseException {
00143 this.executeUpdate(queryUpdate, parameters);
00144 }
00145
00146
00153 public ResultSet getTimeStampForsn (String parameters[]) throws DatabaseException {
00154 return (this.executeQuery(queryGetTimeStamp, parameters));
00155 }
00156
00162 public ResultSet getLastSyncNumber () throws DatabaseException {
00163 return (this.executeQuery(queryGetMax, null));
00164 }
00165
00172 public ResultSet getSyncNumberbysn (String parameters[]) throws DatabaseException {
00173 return this.getTimeStampForsn(parameters);
00174 }
00175
00176 }
00177
00178