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 import java.sql.ResultSet;
00031
00032 import org.openmobileis.common.util.collection.Array;
00033 import org.openmobileis.common.util.exception.DatabaseException;
00034 import org.openmobileis.common.util.exception.ServiceException;
00035 import org.openmobileis.common.util.exception.SynchroException;
00036 import org.openmobileis.common.util.log.LogManager;
00037 import org.openmobileis.modules.common.data.Label;
00038 import org.openmobileis.modules.common.data.LabelFactory;
00039
00044 public abstract class JDBCIntlLabelFactory implements LabelFactory {
00045 protected LabelJDBCQuery query;
00049 public JDBCIntlLabelFactory(LabelJDBCQuery q) {
00050 super();
00051 query = q;
00052 this.initLabelDB();
00053 }
00054
00055
00056
00057
00058 public Array getLabelListForCategorie(String categorie) {
00059 Array labelList = new Array();
00060 try {
00061 String language=this.getLanguage();
00062 String[] param = new String[]{categorie,language};
00063 ResultSet result = query.getLabelListForCategorie(param);
00064 while (result.next()) {
00065 labelList.add(query.convertResultSetToLabel(result));
00066 }
00067 result.close();
00068 } catch (Exception ex) {
00069 LogManager.traceError(0, ex);
00070 } finally {
00071 query.getDbManager().garbageOpenedConnection();
00072 }
00073 return labelList;
00074 }
00075
00076
00077
00078
00079 public String[][] getCategoriesList() {
00080
00081 return null;
00082 }
00083
00084 public Label getLabelWithIds(String id,String category,String lang){
00085 Label label = null;
00086 try {
00087 String[] param = new String[]{id, category, lang};
00088 ResultSet result = query.getLabelWithIds(param);
00089 if (result.next()) {
00090 label = query.convertResultSetToLabel(result);
00091 }
00092 result.close();
00093 } catch (Exception ex) {
00094 LogManager.traceError(0, ex);
00095 } finally {
00096 query.getDbManager().garbageOpenedConnection();
00097 }
00098 return label;
00099 }
00100
00101
00102
00103 public Label getLabelWithIds(String id, String category) {
00104 String lang=this.getLanguage();
00105 return this.getLabelWithIds(id,category,lang);
00106 }
00107
00108
00109
00110
00111 public void storeLabel(Label label) throws ServiceException,
00112 DatabaseException {
00113 try {
00114
00115 Label dblabel = this.getLabelWithIds(label.getLabelId(), label.getCategory(),label.getLabelLanguage());
00116 if (dblabel != null) {
00117 String[] param = query.getUpdateParamFromLabel(label);
00118 query.updateLabel(param);
00119 } else {
00120 String[] param = query.getInsertParamFromLabel(label);
00121 query.insertLabel(param);
00122 }
00123 this.notifyLabelUpdate(label);
00124 } catch (Throwable ex) {
00125 throw new ServiceException(ex);
00126 } finally {
00127 query.getDbManager().garbageOpenedConnection();
00128 }
00129 }
00130
00131
00132
00133
00134 public void deleteLabel(String id, String category) throws ServiceException, DatabaseException {
00135 this.deleteLabel(id,category,this.getLanguage());
00136 }
00137
00138 public void deleteLabel(String id, String category,String language) throws ServiceException, DatabaseException {
00139 try {
00140 Label dblabel = this.getLabelWithIds(id, category,language);
00141 if (dblabel != null) {
00142 String[] param = {id, category,language};
00143 query.deleteLabel(param);
00144 this.notifyLabeldelete(id, category,language);
00145 }
00146 } catch (Throwable ex) {
00147 throw new ServiceException(ex);
00148 } finally {
00149 query.getDbManager().garbageOpenedConnection();
00150 }
00151 }
00152 public String convertIdsToLabelObjectIds(String labelid, String category) {
00153 StringBuffer str = new StringBuffer(labelid);
00154 str.append('%');
00155 str.append(category);
00156 String language=this.getLanguage();
00157 if(language!=null){
00158 str.append('%');
00159 str.append(language);
00160 }
00161 return str.toString();
00162 }
00163
00164 public abstract void initLabelDB();
00165 public abstract String getLanguage();
00166
00172 public abstract Array getLabelListForCategorieAdmin(String category);
00173
00174 public abstract void notifyLabelUpdate(Label label) throws SynchroException;
00175 public abstract void notifyLabeldelete(String labelId, String categoryId,String language) throws SynchroException;
00176 }