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

ObjectDBImportQueryManager.java

00001 /*
00002  *        OpenMobileIS - a free Java Framework for mobile applications
00003  *
00004  *   Copyright (C) 2002  Philippe Delrieu.
00005  *
00006  *   This program is free software; you can redistribute it and/or
00007  *   modify it under the terms of the GNU General Public
00008  *   License as published by the Free Software Foundation; either
00009  *   version 2 of the License, or (at your option) any later version.
00010  *
00011  *   This program is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *   General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU Library General Public
00017  *   License along with this library; if not, write to the Free
00018  *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  * 
00020  * Philippe Delrieu kept the rigth to distribute all code Copyrighted by philippe Delrieu
00021  *  under other licence term even commercial one.
00022  *  
00023  *  Modifications :
00024  *  2002 Creation P.Delrieu
00025  * 
00026  */
00027 
00028 package org.openmobileis.synchro.openmsp.client.db;
00029 
00030 import org.openmobileis.common.util.exception.SynchroException;
00031 import org.openmobileis.common.util.file.FileUtilities;
00032 import org.openmobileis.common.util.log.LogManager;
00033 import org.openmobileis.database.DatabaseException;
00034 
00043 public abstract class ObjectDBImportQueryManager implements ImportQueryManager {
00044 
00046   public ObjectDBImportQueryManager() {
00047   }
00048 
00049         public void importDataFile(String fileName)  {
00050                 ImportDecodedRowListener listener = new ImportDecodedRowListener(this);
00051                 String goodFileName = FileUtilities.convertFileNameToSystem(fileName);
00052                 try {
00053                         this.beginImport();
00054                         DBImportFileCoder.getCoder().decodeFileData(goodFileName, listener);
00055                 } catch (Throwable ex)  {
00056                         LogManager.trace(new SynchroException("DefaultDBImportQueryManager importDataFile Error ", ex));
00057                 } finally {
00058                         try {
00059                                 this.endImport();
00060                         } catch (Throwable ex)  {
00061                                 LogManager.trace(new SynchroException("DefaultDBImportQueryManager importDataFile Error ", ex));
00062                         }
00063                 }
00064         }
00065 
00066 
00067         protected String[] cleanData(String[] data) {
00068 
00069                 for (int i=0; i<data.length; i++) {
00070                         data[i] =  DBImportFileCoder.getCoder().removeAntiSlash(data[i]);
00071                 }
00072                 return data;
00073         }
00074 
00075    
00079   public void executeCreateQuery(String[] data) throws DatabaseException  {
00080     try {
00081       Object obj = DBImportFileCoder.getCoder().unserializeDBObject(data);
00082       this.addObject(data[0], obj);
00083     } catch (Throwable ex)  {
00084       throw new DatabaseException(ex);
00085     }
00086   }
00087 
00091   public void executeUpdateQuery(String[] data) throws DatabaseException  {
00092     try {
00093       Object obj = DBImportFileCoder.getCoder().unserializeDBObject(data);
00094       this.replaceObject(data[0], obj);
00095     } catch (Throwable ex)  {
00096       throw new DatabaseException(ex);
00097     }
00098   }
00099 
00103   public void executeDeleteQuery(String[] data) throws DatabaseException  {
00104     this.deleteObject(data[0]);
00105   }
00106 
00107   public abstract void addObject(String uid, Object object) throws DatabaseException;
00108     
00109   public abstract void replaceObject(String uid, Object object) throws DatabaseException;
00110 
00111   public abstract void deleteObject(String uid) throws DatabaseException;
00112 
00113         protected abstract void beginImport() throws DatabaseException;
00114         protected abstract void endImport() throws DatabaseException;
00115 
00116 }

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