mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#837 - ENH: Support using @HistoryExclude on normal properties (other than @ManyToMany)
This commit is contained in:
@@ -19,16 +19,14 @@ public class TestHistoryInsert extends BaseTestCase {
|
||||
@Test
|
||||
public void test() throws InterruptedException {
|
||||
|
||||
SpiEbeanServer defaultServer = (SpiEbeanServer)Ebean.getDefaultServer();
|
||||
if (!"h2".equals(defaultServer.getDatabasePlatform().getName())) {
|
||||
// Oracle for example uses total recall so we can select the explicit
|
||||
// history tables as we do in this test
|
||||
if (!isH2() && !isPostgres()) {
|
||||
return;
|
||||
}
|
||||
|
||||
User user = new User();
|
||||
user.setName("Jim");
|
||||
user.setEmail("one@email.com");
|
||||
user.setPasswordHash("someHash");
|
||||
|
||||
Ebean.save(user);
|
||||
|
||||
@@ -41,6 +39,7 @@ public class TestHistoryInsert extends BaseTestCase {
|
||||
assertThat(versions).hasSize(1);
|
||||
|
||||
user.setName("Jim v2");
|
||||
user.setPasswordHash("anotherHash");
|
||||
Thread.sleep(10); // wait, to ensure that whenModified differs
|
||||
Ebean.save(user);
|
||||
|
||||
@@ -88,7 +87,7 @@ public class TestHistoryInsert extends BaseTestCase {
|
||||
* Use SqlQuery to query the history table directly.
|
||||
*/
|
||||
private List<SqlRow> fetchHistory(User user) {
|
||||
SqlQuery sqlQuery = Ebean.createSqlQuery("select * from c_user_history where id = :id order by sys_period_start");
|
||||
SqlQuery sqlQuery = Ebean.createSqlQuery("select * from c_user_history where id = :id order by when_modified");
|
||||
sqlQuery.setParameter("id", user.getId());
|
||||
return sqlQuery.findList();
|
||||
}
|
||||
|
||||
@@ -5,8 +5,12 @@ import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.avaje.ebean.annotation.History;
|
||||
import com.avaje.ebean.annotation.HistoryExclude;
|
||||
import com.avaje.ebean.annotation.WhenModified;
|
||||
import com.avaje.tests.model.BaseModel;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@History
|
||||
@Entity
|
||||
@Table(name="c_user")
|
||||
@@ -18,9 +22,17 @@ public class User extends BaseModel {
|
||||
|
||||
String email;
|
||||
|
||||
@HistoryExclude
|
||||
String passwordHash;
|
||||
|
||||
@ManyToOne
|
||||
Group group;
|
||||
|
||||
|
||||
@WhenModified
|
||||
Timestamp whenModified;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public boolean isInactive() {
|
||||
return inactive;
|
||||
@@ -53,5 +65,22 @@ public class User extends BaseModel {
|
||||
public void setGroup(Group group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
|
||||
public String getPasswordHash() {
|
||||
return passwordHash;
|
||||
}
|
||||
|
||||
public void setPasswordHash(String passwordHash) {
|
||||
this.passwordHash = passwordHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp getWhenModified() {
|
||||
return whenModified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhenModified(Timestamp whenModified) {
|
||||
this.whenModified = whenModified;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user