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.modules.common.database.jdbc;
00029
00030
00031 import java.sql.*;
00032
00033 import org.openmobileis.common.context.ApplicationContext;
00034 import org.openmobileis.common.context.ApplicationContextManager;
00035 import org.openmobileis.common.util.database.AbstractQueryManager;
00036 import org.openmobileis.common.util.database.JdbcPoolManagerDB;
00037 import org.openmobileis.common.util.exception.DatabaseException;
00038 import org.openmobileis.common.util.exception.ServiceException;
00039 import org.openmobileis.modules.common.data.DefaultGlobalProperty;
00040 import org.openmobileis.modules.common.data.GlobalProperty;
00041
00048 public class JDBCGlobalPropertyQueryManager extends AbstractQueryManager {
00049
00050 protected static String queryGetGlobalProperty = "SELECT idservice, propkey, propvalue FROM oooglobalproperties where idservice='%0%' AND propkey='%1%'";
00051 protected static String queryGetPropertiesForService = "SELECT idservice, propkey, propvalue FROM oooglobalproperties where idservice='%0%'";
00052 protected static String queryGetAllGlobalProperties = "SELECT idservice, propkey, propvalue FROM oooglobalproperties";
00053
00054 protected static String queryInsertGlobalProperty = "INSERT INTO oooglobalproperties (idservice, propkey, propvalue)"
00055 +" VALUES ('%0%', '%1%', '%2%')";
00056
00057
00058 protected static String queryUpdateGlobalProperty = "UPDATE oooglobalproperties "
00059 +"SET propvalue='%0%'"
00060 +" WHERE idservice='%1%' AND propkey='%2%'";
00061 protected static String queryDeleteGlobalProperty = "DELETE FROM oooglobalproperties where idservice='%0%' AND propkey='%1%'";
00062
00063
00064 private static String queryCreateTable =
00065 "CREATE TABLE oooglobalproperties ("
00066 +"idservice varchar(25) NOT NULL,"
00067 +"propkey varchar(15) NOT NULL,"
00068 +"propvalue varchar(50) NOT NULL,"
00069 +"CONSTRAINT oooglobalpropertieskey PRIMARY KEY (idservice, propkey)"
00070 +");";
00071
00075 public JDBCGlobalPropertyQueryManager() {
00076 super();
00077 ApplicationContext context = ApplicationContextManager.getManager().getApplicationContext();
00078 JdbcPoolManagerDB pool = (JdbcPoolManagerDB)context.getObject("server.querymanager.dbpool");
00079 this.registerManagerDB(pool);
00080 }
00081
00082
00083
00084
00085 public void createSyncTable() throws ServiceException, java.sql.SQLException, DatabaseException {
00086 try {
00087 Connection con = this.getDbManager().getConnection();
00088 DatabaseMetaData dbmd = con.getMetaData();
00089 String[] tableType = {"TABLE"};
00090 ResultSet result = dbmd.getTables (null,null,"oooglobalproperties", tableType);
00091 if (!result.next()) {
00092 this.executeUpdate(queryCreateTable, null);
00093 }
00094 } finally {
00095 this.getDbManager().garbageOpenedConnection();
00096 }
00097 }
00098
00099
00100 public void create (String parameters[]) throws DatabaseException {
00101 this.executeUpdate(JDBCGlobalPropertyQueryManager.queryInsertGlobalProperty, parameters);
00102 }
00103
00104
00105 public void delete (String parameters[]) throws DatabaseException {
00106 this.executeUpdate(JDBCGlobalPropertyQueryManager.queryDeleteGlobalProperty, parameters);
00107 }
00108
00109
00110
00111 public void update (String parameters[]) throws DatabaseException {
00112 this.executeUpdate(JDBCGlobalPropertyQueryManager.queryUpdateGlobalProperty, parameters);
00113 }
00114
00115
00116 public ResultSet getGlobalProperty (String[] param) throws DatabaseException {
00117 return this.executeQuery(JDBCGlobalPropertyQueryManager.queryGetGlobalProperty, param);
00118 }
00119
00120
00121 public ResultSet getPropertiesForService (String[] param) throws DatabaseException {
00122 return this.executeQuery(JDBCGlobalPropertyQueryManager.queryGetPropertiesForService, param);
00123 }
00124
00125
00126 public ResultSet getAllGlobalProperties () throws DatabaseException {
00127 return this.executeQuery(JDBCGlobalPropertyQueryManager.queryGetAllGlobalProperties, null);
00128 }
00129
00130 public GlobalProperty convertResultSetToProperty (ResultSet result) throws DatabaseException {
00131 try {
00132 GlobalProperty property = new DefaultGlobalProperty(result.getString(1), result.getString(2));
00133
00134 property.setPropertyValue(result.getString(3));
00135 return property;
00136 } catch (Throwable ex) {
00137 throw new DatabaseException(ex);
00138 }
00139 }
00140 public String[] getInsertParamFromProperty(GlobalProperty property) {
00141 String[] param = {
00142 property.getServiceProperty()
00143 , property.getPropertyKey()
00144 , property.getPropertyValue()
00145 };
00146 return param;
00147 }
00148
00149 public String[] getUpdateParamFromProperty(GlobalProperty property) {
00150 String[] param = {
00151 property.getPropertyValue()
00152 , property.getServiceProperty()
00153 , property.getPropertyKey()
00154 };
00155 return param;
00156 }
00157 }