00001
00002
00003
00004
00005
00006
00007 package org.openmobileis.modules.crm.database.common.jdbc;
00008
00009
00010 import java.sql.*;
00011
00012 import org.openmobileis.common.context.ApplicationContext;
00013 import org.openmobileis.common.context.ApplicationContextManager;
00014 import org.openmobileis.common.util.database.AbstractQueryManager;
00015 import org.openmobileis.common.util.database.JdbcPoolManagerDB;
00016 import org.openmobileis.common.util.exception.ServiceException;
00017 import org.openmobileis.database.DatabaseException;
00018 import org.openmobileis.modules.crm.data.common.DefaultGlobalProperty;
00019 import org.openmobileis.modules.crm.data.common.GlobalProperty;
00020
00027 public class JDBCGlobalPropertyQueryManager extends AbstractQueryManager {
00028
00029 protected static String queryGetGlobalProperty = "SELECT idservice, propkey, propvalue FROM oooglobalproperties where idservice='%0%' AND propkey='%1%'";
00030 protected static String queryGetPropertiesForService = "SELECT idservice, propkey, propvalue FROM oooglobalproperties where idservice='%0%'";
00031 protected static String queryGetAllGlobalProperties = "SELECT idservice, propkey, propvalue FROM oooglobalproperties";
00032
00033 protected static String queryInsertGlobalProperty = "INSERT INTO oooglobalproperties (idservice, propkey, propvalue)"
00034 +" VALUES ('%0%', '%1%', '%2%')";
00035
00036
00037 protected static String queryUpdateGlobalProperty = "UPDATE oooglobalproperties "
00038 +"SET propvalue='%0%'"
00039 +" WHERE idservice='%1%' AND propkey='%2%'";
00040 protected static String queryDeleteGlobalProperty = "DELETE FROM oooglobalproperties where idservice='%0%' AND propkey='%1%'";
00041
00042
00043 private static String queryCreateTable =
00044 "CREATE TABLE oooglobalproperties ("
00045 +"idservice varchar(25) NOT NULL,"
00046 +"propkey varchar(15) NOT NULL,"
00047 +"propvalue varchar(50) NOT NULL,"
00048 +"CONSTRAINT oooglobalpropertieskey PRIMARY KEY (idservice, propkey)"
00049 +");";
00050
00054 public JDBCGlobalPropertyQueryManager() {
00055 super();
00056 ApplicationContext context = ApplicationContextManager.getManager().getApplicationContext();
00057 JdbcPoolManagerDB pool = (JdbcPoolManagerDB)context.getObject("server.querymanager.dbpool");
00058 this.registerManagerDB(pool);
00059 }
00060
00061
00062
00063
00064 public void createSyncTable() throws ServiceException, java.sql.SQLException {
00065 try {
00066 Connection con = this.getDbManager().getConnection();
00067 DatabaseMetaData dbmd = con.getMetaData();
00068 String[] tableType = {"TABLE"};
00069 ResultSet result = dbmd.getTables (null,null,"oooglobalproperties", tableType);
00070 if (!result.next()) {
00071 this.executeUpdate(queryCreateTable, null);
00072 }
00073 } finally {
00074 this.getDbManager().garbageOpenedConnection();
00075 }
00076 }
00077
00078
00079 public void create (String parameters[]) throws ServiceException {
00080 this.executeUpdate(JDBCGlobalPropertyQueryManager.queryInsertGlobalProperty, parameters);
00081 }
00082
00083
00084 public void delete (String parameters[]) throws ServiceException {
00085 this.executeUpdate(JDBCGlobalPropertyQueryManager.queryDeleteGlobalProperty, parameters);
00086 }
00087
00088
00089
00090 public void update (String parameters[]) throws ServiceException {
00091 this.executeUpdate(JDBCGlobalPropertyQueryManager.queryUpdateGlobalProperty, parameters);
00092 }
00093
00094
00095 public ResultSet getGlobalProperty (String[] param) throws SQLException {
00096 return this.executeQuery(JDBCGlobalPropertyQueryManager.queryGetGlobalProperty, param);
00097 }
00098
00099
00100 public ResultSet getPropertiesForService (String[] param) throws SQLException {
00101 return this.executeQuery(JDBCGlobalPropertyQueryManager.queryGetPropertiesForService, param);
00102 }
00103
00104
00105 public ResultSet getAllGlobalProperties () throws SQLException {
00106 return this.executeQuery(JDBCGlobalPropertyQueryManager.queryGetAllGlobalProperties, null);
00107 }
00108
00109 public GlobalProperty convertResultSetToProperty (ResultSet result) throws DatabaseException {
00110 try {
00111 GlobalProperty property = new DefaultGlobalProperty(result.getString(1), result.getString(2));
00112
00113 property.setPropertyValue(result.getString(3));
00114 return property;
00115 } catch (Throwable ex) {
00116 throw new DatabaseException(ex);
00117 }
00118 }
00119 public String[] getInsertParamFromProperty(GlobalProperty property) {
00120 String[] param = {
00121 property.getServiceProperty()
00122 , property.getPropertyKey()
00123 , property.getPropertyValue()
00124 };
00125 return param;
00126 }
00127
00128 public String[] getUpdateParamFromProperty(GlobalProperty property) {
00129 String[] param = {
00130 property.getPropertyValue()
00131 , property.getServiceProperty()
00132 , property.getPropertyKey()
00133 };
00134 return param;
00135 }
00136 }