ObjectDBImportQueryManager.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
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  */
00025 
00026 package org.openmobileis.synchro.openmsp.client.db;
00027 
00028 import org.openmobileis.common.util.exception.DatabaseException;
00029 import org.openmobileis.common.util.exception.SynchroException;
00030 import org.openmobileis.common.util.file.FileUtilities;
00031 import org.openmobileis.common.util.log.LogManager;
00032 
00041 public abstract class ObjectDBImportQueryManager implements ImportQueryManager {
00042 
00044   public ObjectDBImportQueryManager() {
00045   }
00046 
00047         public void importDataFile(String fileName)  {
00048                 ImportDecodedRowListener listener = new ImportDecodedRowListener(this);
00049                 String goodFileName = FileUtilities.convertFileNameToSystem(fileName);
00050                 try {
00051                         this.beginImport();
00052                         DBImportFileCoder.getCoder().decodeFileData(goodFileName, listener);
00053                 } catch (Throwable ex)  {
00054                         LogManager.trace(new SynchroException("DefaultDBImportQueryManager importDataFile Error ", ex));
00055                 } finally {
00056                         try {
00057                                 this.endImport();
00058                         } catch (Throwable ex)  {
00059                                 LogManager.trace(new SynchroException("DefaultDBImportQueryManager importDataFile Error ", ex));
00060                         }
00061                 }
00062         }
00063 
00064 
00065         protected String[] cleanData(String[] data) {
00066 
00067                 for (int i=0; i<data.length; i++) {
00068                         data[i] =  DBImportFileCoder.getCoder().removeAntiSlash(data[i]);
00069                 }
00070                 return data;
00071         }
00072 
00073    
00077   public void executeCreateQuery(String[] data) throws DatabaseException  {
00078     try {
00079       Object obj = DBImportFileCoder.getCoder().unserializeDBObject(data);
00080       this.addObject(data[0], obj);
00081     } catch (Throwable ex)  {
00082       throw new DatabaseException(ex);
00083     }
00084   }
00085 
00089   public void executeUpdateQuery(String[] data) throws DatabaseException  {
00090     try {
00091       Object obj = DBImportFileCoder.getCoder().unserializeDBObject(data);
00092       this.replaceObject(data[0], obj);
00093     } catch (Throwable ex)  {
00094       throw new DatabaseException(ex);
00095     }
00096   }
00097 
00101   public void executeDeleteQuery(String[] data) throws DatabaseException  {
00102     this.deleteObject(data[0]);
00103   }
00104 
00105   public abstract void addObject(String uid, Object object) throws DatabaseException;
00106     
00107   public abstract void replaceObject(String uid, Object object) throws DatabaseException;
00108 
00109   public abstract void deleteObject(String uid) throws DatabaseException;
00110 
00111         protected abstract void beginImport() throws DatabaseException;
00112         protected abstract void endImport() throws DatabaseException;
00113 
00114 }

Generated on Mon Dec 4 11:03:28 2006 for OpenMobileIS by  doxygen 1.5.1-p1