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 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 }