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