Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

JDBCIntlLabelFactory.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2005 Creation F.Salque
00026  * 
00027  */
00028 package org.openmobileis.modules.crm.database.common.jdbc;
00029 
00030 import java.sql.ResultSet;
00031 
00032 import org.openmobileis.common.util.collection.Array;
00033 import org.openmobileis.common.util.exception.ServiceException;
00034 import org.openmobileis.common.util.exception.SynchroException;
00035 import org.openmobileis.common.util.log.LogManager;
00036 import org.openmobileis.database.DatabaseException;
00037 import org.openmobileis.modules.crm.data.common.Label;
00038 import org.openmobileis.modules.crm.data.common.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         /* (non-Javadoc)
00056          * @see org.openmobileis.modules.crm.data.common.LabelFactory#getLabelListForCategorie(java.lang.String)
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         /* (non-Javadoc)
00077          * @see org.openmobileis.modules.crm.data.common.LabelFactory#getCategoriesList()
00078          */
00079         public String[][] getCategoriesList() {
00080                 //cached label list is not used anymore
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         /* (non-Javadoc)
00101          * @see org.openmobileis.modules.crm.data.common.LabelFactory#getLabelWithIds(java.lang.String, java.lang.String)
00102          */
00103         public Label getLabelWithIds(String id, String category) {
00104                 String lang=this.getLanguage();
00105                 return this.getLabelWithIds(id,category,lang);
00106         }
00107 
00108         /* (non-Javadoc)
00109          * @see org.openmobileis.modules.crm.data.common.LabelFactory#storeLabel(org.openmobileis.modules.crm.data.common.Label)
00110          */
00111         public void storeLabel(Label label) throws ServiceException,
00112                         DatabaseException {
00113                 try     {                 
00114                         //test because of trigger PB could not delete that does not exist in db
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         /* (non-Javadoc)
00132          * @see org.openmobileis.modules.crm.data.common.LabelFactory#deleteLabel(java.lang.String, java.lang.String)
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 }

Generated on Wed Dec 14 21:05:34 2005 for OpenMobileIS by  doxygen 1.4.4