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.exception.ServiceException;
00034
00045 public class PostgreSQLSyncNumberQueryManager extends AbstractQueryManager implements SyncNumberQueryManager {
00046
00047
00048 private static String queryUpdate =
00049 "UPDATE SYNC_ID SET SYNCNUMBER=%0% , TIME_STAMP=%1% " +
00050 "WHERE SYNCNUMBER=%2%";
00051
00052 private static String queryCreate =
00053 "INSERT INTO SYNC_ID (SYNCNUMBER , TIME_STAMP) " +
00054 "VALUES (%0%, %1%)";
00055
00056
00057 private static String queryCreateTable =
00058 "CREATE TABLE SYNC_ID ("
00059 +" SYNCNUMBER BIGINT NOT NULL,"
00060 +" TIME_STAMP BIGINT NOT NULL,"
00061 +" CONSTRAINT syncnum PRIMARY KEY (SYNCNUMBER)"
00062 +") WITH OIDS;";
00063
00064
00065
00066
00067
00068 private static String queryDelete =
00069 "DELETE FROM SYNC_ID WHERE SYNCNUMBER = %0%";
00070
00071
00072
00073
00074
00075 private static String queryGetTimeStamp =
00076 "SELECT TIME_STAMP FROM SYNC_ID WHERE SYNCNUMBER = %0% ";
00077
00078 private static String queryGetMax =
00079 "SELECT Max(SYNCNUMBER) FROM SYNC_ID";
00080
00090 public void create (String parameters[]) throws ServiceException {
00091 this.executeUpdate(queryCreate, parameters);
00092 }
00093
00094
00095
00096
00097 public void createSyncTable() throws ServiceException, java.sql.SQLException {
00098 try {
00099 Connection con = this.getDbManager().getConnection();
00100 DatabaseMetaData dbmd = con.getMetaData();
00101 String[] tableType = {"TABLE"};
00102 ResultSet result = dbmd.getTables (null,null,"sync_id", tableType);
00103 if (!result.next()) {
00104 this.executeUpdate(queryCreateTable, null);
00105 String[] data = {"0", "0"};
00106 this.create(data);
00107 }
00108 } finally {
00109 this.getDbManager().garbageOpenedConnection();
00110 }
00111 }
00117
00118
00119
00120
00127 public void delete (String parameters[]) throws ServiceException {
00128 this.executeUpdate(queryDelete, parameters);
00129 }
00130
00137 public void update (String parameters[]) throws ServiceException {
00138 this.executeUpdate(queryUpdate, parameters);
00139 }
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