Hi every one.
I want your advice to realize sequenced primary id.
(like SERIAL data type in Postgres)
Follow is my idea.But I think it is not samrt way.
It use many memory space and CPU power.
-------------------------------------------------------
public class TUser extends _TUser {
public Integer nextId() {
int maxId = 0;
DataContext ctx = DataContext.createDataContext();
SelectQuery query = new SelectQuery(TUser.class);
List list = ctx.performQuery(query);
Iterator i = list.iterator();
while(i.hasNext()) {
TUser user = (TUser)i.next();
int tempId = user.getId().intValue();
if(tempId > maxId){
maxId = tempId;
}
}
return new Integer(maxId + 1);
}
}
--------------------------------------------------------------
//insert the data
tUser.setId(tUser.nextId());
tUser.setAccount(userForm.getAccount());
tUser.setPass(userForm.getPass());
ctx.commitChanges(org.apache.log4j.Level.WARN);
--------------------------------------------------------------
If some one has realized that. Please tell me the way to realize.
Ken Yasue.
This archive was generated by hypermail 2.0.0 : Thu Oct 14 2004 - 09:22:36 EDT