#118 - ENH: Add support for for Soft Deletes (Logical Deletion) ... - initial

This commit is contained in:
Robin Bygrave
2015-12-01 23:21:11 +13:00
parent 51bee836d4
commit 0ad52cf6a7
24 changed files with 531 additions and 105 deletions
@@ -0,0 +1,45 @@
package com.avaje.tests.model.softdelete;
import com.avaje.ebean.annotation.SoftDelete;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
@MappedSuperclass
public class BaseSoftDelete {
@Id
Long id;
@Version
Long version;
@SoftDelete
boolean deleted;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
public boolean isDeleted() {
return deleted;
}
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
}
@@ -0,0 +1,27 @@
package com.avaje.tests.model.softdelete;
import javax.persistence.Entity;
@Entity
public class EBasicSoftDelete extends BaseSoftDelete {
String name;
String description;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
@@ -0,0 +1,43 @@
package com.avaje.tests.softdelete;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.SqlQuery;
import com.avaje.ebean.SqlRow;
import com.avaje.tests.model.softdelete.EBasicSoftDelete;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class TestSoftDeleteBasic extends BaseTestCase {
@Test
public void test() {
EBasicSoftDelete bean = new EBasicSoftDelete();
bean.setName("one");
Ebean.save(bean);
Ebean.delete(bean);
SqlQuery sqlQuery = Ebean.createSqlQuery("select * from ebasic_soft_delete where id=?");
sqlQuery.setParameter(1, bean.getId());
SqlRow sqlRow = sqlQuery.findUnique();
assertThat(sqlRow).isNotNull();
EBasicSoftDelete findNormal = Ebean.find(EBasicSoftDelete.class)
.setId(bean.getId())
.findUnique();
assertThat(findNormal).isNull();
EBasicSoftDelete findInclude = Ebean.find(EBasicSoftDelete.class)
.setId(bean.getId())
.includeSoftDeletes()
.findUnique();
assertThat(findInclude).isNotNull();
}
}