MentaBean

Compare Revisions

Ignore whitespace Rev 207 → Rev 208

/trunk/src/test/java/org/mentabean/jdbc/AnsiSQLBeanSessionTest.java
59,7 → 59,7
private long id;
private String username;
private Date birthdate;
private Status status = Status.BASIC;
private Status status;
private boolean deleted;
private Date insertTime;
 
73,6 → 73,7
public User(String username, String birthdate) {
this.username = username;
this.birthdate = fromString(birthdate);
this.status = Status.BASIC;
}
 
private static Date fromString(String date) {
150,12 → 151,12
User userProps = PropertiesProxy.create(User.class);
config.pk(userProps.getId(), DBTypes.AUTOINCREMENT);
config.field(userProps.getUsername(), DBTypes.STRING);
config.field(userProps.getBirthdate(), "bd", DBTypes.DATE); // note that the database column name is different
config.field(userProps.getStatus(), DBTypes.ENUMVALUE.from(User.Status.class));
config.field(userProps.isDeleted(), DBTypes.BOOLEANINT);
config.field(userProps.getInsertTime(), "insert_time", DBTypes.NOW_ON_INSERT_TIMESTAMP);
config.pk(userProps.getId(), DBTypes.AUTOINCREMENT)
.field(userProps.getUsername(), DBTypes.STRING)
.field(userProps.getBirthdate(), "bd", DBTypes.DATE) // note that the database column name is different
.field(userProps.getStatus(), DBTypes.ENUMVALUE.from(User.Status.class))
.field(userProps.isDeleted(), DBTypes.BOOLEANINT)
.field(userProps.getInsertTime(), "insert_time", DBTypes.NOW_ON_INSERT_TIMESTAMP);
 
return config;
}
1094,6 → 1095,30
}
 
Assert.assertEquals(false, ok);
//loadUnique specifying properties
u = new User();
u.setBirthdate("1967-01-03");
User proxy = PropertiesProxy.create(User.class);
u = session.loadUnique(u, proxy.getUsername()); //only username
Assert.assertNull(u.getBirthdate());
Assert.assertNull(u.getInsertTime());
Assert.assertNull(u.getStatus());
Assert.assertEquals(2, u.getId()); //always load the pk
Assert.assertNotNull(u.getUsername());
//loadUnique specifying 'minus' properties
u = new User();
u.setBirthdate("1967-01-03");
u = session.loadUniqueMinus(u, proxy.getUsername(), proxy.getId()); //not load username nor pk (mentabean must ignore this)
Assert.assertNotNull(u.getBirthdate());
Assert.assertNotNull(u.getInsertTime());
Assert.assertNotNull(u.getStatus());
Assert.assertEquals(2, u.getId()); //always load the pk... I mean, always
Assert.assertNull(u.getUsername());
 
} finally {
close(conn);
1129,6 → 1154,7
 
// load all non-deleted users...
User u = new User();
u.setStatus(User.Status.BASIC);
u.setDeleted(false);
List<User> nonDeletedUsers = session.loadList(u);
Assert.assertFalse(nonDeletedUsers.size() == 1); // THIS DOES NOT WORK because isDeleted() returns a boolean primitive
/trunk/src/main/java/org/mentabean/jdbc/AnsiSQLBeanSession.java
2249,7 → 2249,7
E o = checkUnique(loadListImpl(bean, null, new Limit(2), properties, minus));
 
if (o != null) {
load(o); // load twice to attach to session so dynamic update is by default!
loadImpl(o, properties, minus); // load twice to attach to session so dynamic update is by default!
}
return o;