00001 00021 package org.openmobileis.examples.mycrm.data.jdbc; 00022 00023 00024 import java.sql.ResultSet; 00025 00026 00027 00028 import org.openmobileis.common.context.ApplicationContext; 00029 import org.openmobileis.common.context.ApplicationContextManager; 00030 import org.openmobileis.common.context.SessionContext; 00031 import org.openmobileis.common.context.SessionContextManager; 00032 import org.openmobileis.common.user.UserNotFoundException; 00033 import org.openmobileis.common.util.collection.Array; 00034 import org.openmobileis.common.util.database.JdbcPoolManagerDB; 00035 import org.openmobileis.common.util.exception.ServiceException; 00036 import org.openmobileis.database.fastobjectdb.FastObjectDB; 00037 import org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget; 00038 00039 import org.openmobileis.modules.crm.data.common.Label; 00040 import org.openmobileis.modules.crm.database.common.fodb.FODBLabel; 00041 import org.openmobileis.synchro.algo.replication.AlwaysUpdateServerSynchroConflicResolver; 00042 import org.openmobileis.synchro.algo.replication.SynchroAtomicObject; 00043 import org.openmobileis.synchro.algo.replication.SynchroConflicResolver; 00044 import org.openmobileis.synchro.algo.replication.utils.DefaultSynchroAtomicObject; 00045 import org.openmobileis.synchro.openmsp.OpenMSPException; 00046 import org.openmobileis.synchro.security.auth.Credential; 00047 00048 00049 00056 public class MyCrmLabelSynchroTarget implements FODBSyncTarget { 00057 00058 // public static final String LABEL_ATOMIC_OBJECT_UID="%labeluid1%"; 00059 00060 private MyCrmLabelQuery query = null; 00061 00062 public MyCrmLabelSynchroTarget() { 00063 super(); 00064 query = new MyCrmLabelQuery(); 00065 00066 } 00067 00068 /* (non-Javadoc) 00069 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncService#getCollectionName() 00070 */ 00071 public String getCollectionName() { 00072 return "label"; 00073 } 00074 00075 /* (non-Javadoc) 00076 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncService#getCollectionObjectWithId(java.lang.String) 00077 */ 00078 public Object getCollectionObjectWithId(String id) throws OpenMSPException { 00079 00080 Label label = null; 00081 try { 00082 String[] param = FODBLabel.getLabelIdAndCatIdFromId(id); 00083 ResultSet result = query.getLabel(param); 00084 while (result.next()) { 00085 label = query.convertLabelFromResult(result); 00086 } 00087 } catch (Throwable ex) { 00088 throw new OpenMSPException(ex); 00089 } finally { 00090 query.getDbManager().garbageOpenedConnection(); 00091 } 00092 return label; 00093 } 00094 00095 /* (non-Javadoc) 00096 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncService#updateCollectionObject(java.lang.Object) 00097 */ 00098 public void updateCollectionObject(Object obj) throws OpenMSPException { 00099 } 00100 00101 /* (non-Javadoc) 00102 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncService#deleteCollectionObject(java.lang.String) 00103 */ 00104 public void deleteCollectionObject(String id) throws OpenMSPException { 00105 } 00106 00107 /* (non-Javadoc) 00108 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncService#getConflicResolver() 00109 */ 00110 public SynchroConflicResolver getConflicResolver() { 00111 return new AlwaysUpdateServerSynchroConflicResolver(); 00112 } 00113 00114 /* (non-Javadoc) 00115 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncService#getAllCollectionObject() 00116 */ 00117 public Array getAllCollectionObject() throws OpenMSPException { 00118 00119 Array list = new Array(); 00120 try { 00121 ResultSet result = query.getAllLabel(); 00122 while (result.next()) { 00123 list.add(query.convertLabelFromResult(result)); 00124 } 00125 } catch (Throwable ex) { 00126 throw new OpenMSPException(ex); 00127 } finally { 00128 query.getDbManager().garbageOpenedConnection(); 00129 } 00130 return list; 00131 } 00132 00133 /* (non-Javadoc) 00134 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncService#getCollectionObjectId(java.lang.Object) 00135 */ 00136 public String getCollectionObjectId(Object obj) { 00137 return ((FODBLabel)obj).getLabelCategoryId(); 00138 } 00139 00140 /* (non-Javadoc) 00141 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncService#getAllModifiedAtomicObjectForServiceSince(java.lang.String, long) 00142 */ 00143 public SynchroAtomicObject[] getAllModifiedAtomicObjectSince(long date) throws OpenMSPException { 00144 if (date == 0) { //synchronize only during complete synchro 00145 SynchroAtomicObject[] sync = new SynchroAtomicObject[1]; 00146 sync[0] = new DefaultSynchroAtomicObject("", ""); 00147 return sync; 00148 } 00149 return new SynchroAtomicObject[0]; 00150 } 00151 00152 /* (non-Javadoc) 00153 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncService#getUpdateMaxNbRow() 00154 */ 00155 public int getUpdateMaxNbRow() { 00156 return 0; 00157 } 00158 00159 /* (non-Javadoc) 00160 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncService#updateSynchroDB(org.openmobileis.database.fastobjectdb.FastObjectDB) 00161 */ 00162 public void updateSynchroDB(FastObjectDB db) throws OpenMSPException { 00163 } 00164 00165 /* (non-Javadoc) 00166 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#connect(org.openmobileis.synchro.security.auth.Credential) 00167 */ 00168 public void connect(Credential cred) throws UserNotFoundException, ServiceException { 00169 // do nothing 00170 } 00171 00172 /* (non-Javadoc) 00173 * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#disconnect() 00174 */ 00175 public void disconnect() { 00176 // do nothing 00177 } 00178 }