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.exception.DatabaseException;
00032
00043 public class PostgreSQLSyncNumberQueryManager extends AbstractQueryManager implements SyncNumberQueryManager {
00044
00045
00046 private static String queryUpdate =
00047 "UPDATE SYNC_ID SET SYNCNUMBER=%0% , TIME_STAMP=%1% " +
00048 "WHERE SYNCNUMBER=%2%";
00049
00050 private static String queryCreate =
00051 "INSERT INTO SYNC_ID (SYNCNUMBER , TIME_STAMP) " +
00052 "VALUES (%0%, %1%)";
00053
00054
00055 private static String queryCreateTable =
00056 "CREATE TABLE SYNC_ID ("
00057 +" SYNCNUMBER BIGINT NOT NULL,"
00058 +" TIME_STAMP BIGINT NOT NULL,"
00059 +" CONSTRAINT syncnum PRIMARY KEY (SYNCNUMBER)"
00060 +") WITH OIDS;";
00061
00062
00063
00064
00065
00066 private static String queryDelete =
00067 "DELETE FROM SYNC_ID WHERE SYNCNUMBER = %0%";
00068
00069
00070
00071
00072
00073 private static String queryGetTimeStamp =
00074 "SELECT TIME_STAMP FROM SYNC_ID WHERE SYNCNUMBER = %0% ";
00075
00076 private static String queryGetMax =
00077 "SELECT Max(SYNCNUMBER) FROM SYNC_ID";
00078
00088 public void create (String parameters[]) throws DatabaseException {
00089 this.executeUpdate(queryCreate, parameters);
00090 }
00091
00092
00093
00094
00095 public void createSyncTable() throws DatabaseException, java.sql.SQLException {
00096 try {
00097 Connection con = this.getDbManager().getConnection();
00098 DatabaseMetaData dbmd = con.getMetaData();
00099 String[] tableType = {"TABLE"};
00100 ResultSet result = dbmd.getTables (null,null,"sync_id", tableType);
00101 if (!result.next()) {
00102 this.executeUpdate(queryCreateTable, null);
00103 String[] data = {"0", "0"};
00104 this.create(data);
00105 }
00106 } finally {
00107 this.getDbManager().garbageOpenedConnection();
00108 }
00109 }
00115
00116
00117
00118
00125 public void delete (String parameters[]) throws DatabaseException {
00126 this.executeUpdate(queryDelete, parameters);
00127 }
00128
00135 public void update (String parameters[]) throws DatabaseException {
00136 this.executeUpdate(queryUpdate, parameters);
00137 }
00138
00139
00146 public ResultSet getTimeStampForsn (String parameters[]) throws DatabaseException {
00147 return (this.executeQuery(queryGetTimeStamp, parameters));
00148 }
00149
00155 public ResultSet getLastSyncNumber () throws DatabaseException {
00156 return (this.executeQuery(queryGetMax, null));
00157 }
00158
00165 public ResultSet getSyncNumberbysn (String parameters[]) throws DatabaseException {
00166 return this.getTimeStampForsn(parameters);
00167 }
00168
00169 }
00170
00171