DefaultSynchroAtomicObject.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  *  
00023  *  Modifications :
00024  *  2006 Creation P.Delrieu
00025  * 
00026  */
00027 
00028 package org.openmobileis.synchro.algo.replication.utils;
00029 
00030 import org.openmobileis.common.util.exception.DatabaseException;
00031 import org.openmobileis.synchro.algo.replication.SynchroAtomicObject;
00032 import org.openmobileis.synchro.algo.syncnumber.SyncNumberManager;
00033 
00041 public class DefaultSynchroAtomicObject implements SynchroAtomicObject {
00042   static final long serialVersionUID = 5521257935120563452L;
00043 
00044   private String uid;
00045   private String checksum;
00046   private long syncnumber;
00047   private short modificationType;
00048   private long creationDate;
00049 
00050   public DefaultSynchroAtomicObject(String id, String sum, long syncnumber, short type, long creationdate) {
00051     uid = id;
00052     checksum=sum;
00053     this.syncnumber=syncnumber;
00054     modificationType = type;
00055     creationDate = creationdate;
00056   }
00057   
00058   public DefaultSynchroAtomicObject(String id, String sum) {
00059         this(id, sum, 0, SynchroAtomicObject.ADD, 0);
00060   }
00061   
00062   public DefaultSynchroAtomicObject(String id, long syncnumber) {
00063         this(id, "", syncnumber, SynchroAtomicObject.ADD, 0);
00064   }
00065   
00066   public DefaultSynchroAtomicObject(String id, String sum, long syncnumber) {
00067         this(id, sum, syncnumber, SynchroAtomicObject.ADD, 0);
00068   }
00069 
00070   public long getCreationDate() {
00071     return creationDate;
00072   }
00073 
00074   public String getUID() {
00075     return uid;
00076   }
00077 
00078   public String getCheckSum() {
00079     return checksum;
00080   }
00081   public void setCheckSum(String sum) {
00082     checksum = sum;
00083   }
00084 
00085   public long getModifSyncNumber() {
00086     return syncnumber;
00087   }
00088   public void setModifSyncNumber(long ts)  {
00089     syncnumber = ts;
00090   }
00091 
00092   public short getModificationType() {
00093     return modificationType;
00094   }
00095 
00096   public void setModificationType(short type) throws DatabaseException {
00097     if (this.syncnumber == 0) this.syncnumber = SyncNumberManager.getManager().getNextSynchroNumber().getSynchroNumber();
00098     modificationType = type;
00099   }
00100 
00101   public boolean equals(Object obj) {
00102     if (obj instanceof SynchroAtomicObject) {
00103       if(((SynchroAtomicObject)obj).getUID().equals(uid)) {
00104         return true;
00105       }
00106     }
00107     return false;
00108   }
00109 
00110   public int hashCode() {
00111     return uid.hashCode();
00112   }
00113 }

Generated on Mon Jan 11 21:19:14 2010 for OpenMobileIS by  doxygen 1.5.4