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 package org.openmobileis.examples.server.database;
00026
00027 import java.sql.Connection;
00028 import java.sql.DatabaseMetaData;
00029 import java.sql.ResultSet;
00030
00031 import org.openmobileis.common.util.database.AbstractQueryManager;
00032 import org.openmobileis.common.util.exception.DatabaseException;
00033
00041 public final class JDBCBaseDataFactory extends AbstractQueryManager {
00042
00043 private static String queryUpdate =
00044 "UPDATE BASEDATA SET DATA='%0%' " +
00045 "WHERE ID='%1%'";
00046
00047 private static String queryCreate =
00048 "INSERT INTO BASEDATA (ID , DATA) " +
00049 "VALUES ('%0%', '%1%')";
00050
00051
00052 private static String queryCreateTable =
00053 "CREATE TABLE BASEDATA ("
00054 +" ID varchar(30) NOT NULL,"
00055 +" DATA varchar(50),"
00056 +" CONSTRAINT dataid PRIMARY KEY (ID)"
00057 +")";
00058
00059 private static String queryDelete =
00060 "DELETE FROM BASEDATA WHERE ID = '%0%'";
00061
00062
00063
00064
00065 private static String queryGetBaseData =
00066 "SELECT ID, DATA FROM BASEDATA WHERE ID = '%0%' ";
00067
00068 private static String queryGetAllBaseData =
00069 "SELECT ID, DATA FROM BASEDATA ";
00070
00074 public JDBCBaseDataFactory() {
00075 super();
00076 }
00077
00078
00079
00080
00081 public void createSyncTable() throws DatabaseException, java.sql.SQLException {
00082 try {
00083 Connection con = this.getDbManager().getConnection();
00084 DatabaseMetaData dbmd = con.getMetaData();
00085 String[] tableType = {"TABLE"};
00086 ResultSet result = dbmd.getTables (null,null,"BASEDATA", tableType);
00087 if (!result.next()) {
00088 this.executeUpdate(queryCreateTable, null);
00089 }
00090 } finally {
00091 this.getDbManager().garbageOpenedConnection();
00092 }
00093 }
00094
00095 public void create (String parameters[]) throws DatabaseException {
00096 this.executeUpdate(queryCreate, parameters);
00097 }
00098
00099 public void delete (String parameters[]) throws DatabaseException {
00100 this.executeUpdate(queryDelete, parameters);
00101 }
00102
00103 public void update (String parameters[]) throws DatabaseException {
00104 this.executeUpdate(queryUpdate, parameters);
00105 }
00106
00107 public ResultSet getBaseData (String parameters[]) throws DatabaseException {
00108 return (this.executeQuery(queryGetBaseData, parameters));
00109 }
00110
00111 public ResultSet getAllBaseData () throws DatabaseException {
00112 return (this.executeQuery(queryGetAllBaseData, null));
00113 }
00114
00115 }