001package co.codewizards.cloudstore.local.persistence; 002 003import static co.codewizards.cloudstore.core.util.Util.*; 004 005import javax.jdo.annotations.Discriminator; 006import javax.jdo.annotations.DiscriminatorStrategy; 007import javax.jdo.annotations.Index; 008import javax.jdo.annotations.Indices; 009import javax.jdo.annotations.Inheritance; 010import javax.jdo.annotations.InheritanceStrategy; 011import javax.jdo.annotations.NullValue; 012import javax.jdo.annotations.PersistenceCapable; 013import javax.jdo.annotations.Persistent; 014import javax.jdo.annotations.Queries; 015import javax.jdo.annotations.Query; 016 017@PersistenceCapable 018@Inheritance(strategy=InheritanceStrategy.NEW_TABLE) 019@Discriminator(strategy=DiscriminatorStrategy.VALUE_MAP) 020@Indices({ 021 @Index(name="Modification_remoteRepository_localRevision", members={"remoteRepository", "localRevision"}), 022}) 023@Queries({ 024 @Query(name="getModificationsAfter_remoteRepository_localRevision", value="SELECT WHERE this.remoteRepository == :remoteRepository && this.localRevision > :localRevision"), 025 @Query(name="getModificationsBeforeOrEqual_remoteRepository_localRevision", value="SELECT WHERE this.remoteRepository == :remoteRepository && this.localRevision <= :localRevision") 026}) 027/** 028 * @deprecated Storing one Modification per remote-repository is highly inefficient and not necessary. We should replace 029 * Modification (and its subclasses) by a new class (with appropriate sub-classes) that is *not* remote-repository-dependent! 030 * We could call it 'Modification2' or better simply 'Mod' (with 'DeleteMod' and 'CopyMod' etc.). 031 * A 'Mod' can be deleted, if it was replicated to all remote-repositories. We can track this easily: It is the case, if 032 * for all remote-repositories, the condition 'Mod.localRevision <= LastCryptoKeySyncToRemoteRepo.localRepositoryRevisionSynced' is met. 033 * Note, that the ChangeSet should only contain a 'Mod', if 'Mod.localRevision > LastCryptoKeySyncToRemoteRepo.localRepositoryRevisionSynced', 034 * just like it is done for RepoFiles. 035 * TODO Refactor per-remote-repo 'Modification' to global 'Mod'! Keep downward-compatibility!!! Upgrading existing repos should work fine! 036 */ 037@Deprecated 038public abstract class Modification extends Entity implements AutoTrackLocalRevision { 039 040 @Persistent(nullValue=NullValue.EXCEPTION) 041 private RemoteRepository remoteRepository; 042 043 private long localRevision; 044 045 /** 046 * Gets the remote repository to which this modification must be synced. 047 * @return the remote repository to which this modification must be synced. 048 */ 049 public RemoteRepository getRemoteRepository() { 050 return remoteRepository; 051 } 052 053 public void setRemoteRepository(RemoteRepository remoteRepository) { 054 if (! equal(this.remoteRepository, remoteRepository)) 055 this.remoteRepository = remoteRepository; 056 } 057 058 @Override 059 public long getLocalRevision() { 060 return localRevision; 061 } 062 @Override 063 public void setLocalRevision(long revision) { 064 if (! equal(this.localRevision, revision)) 065 this.localRevision = revision; 066 } 067}