AccountPersistencepublic class AccountPersistence extends com.imaginary.lwp.jdbc.JDBCSupport
Fields Summary |
---|
private static final String | CREATE | private static final String | SELECT | private static final String | REMOVE | private static final String | UPDATE |
Methods Summary |
---|
public void | create(com.imaginary.lwp.Transaction trans, com.imaginary.lwp.Memento mem)
PreparedStatement stmt = null;
try {
Connection conn = ((JDBCTransaction)trans).getConnection();
stmt = conn.prepareStatement(CREATE);
{
Long l = (Long)mem.get(BaseEntity.class, "objectID");
stmt.setLong(1, l.longValue());
}
{
CustomerFacade cust;
cust = (CustomerFacade)mem.get(AccountEntity.class,
Account.CUSTOMER);
stmt.setLong(2, cust.getObjectID());
}
{
AccountType type;
type = (AccountType)mem.get(AccountEntity.class, Account.TYPE);
stmt.setString(3, type.getCode());
}
{
Double d = (Double)mem.get(AccountEntity.class, Account.BALANCE);
stmt.setDouble(4, d.doubleValue());
}
{
Integer num = (Integer)mem.get(AccountEntity.class, Account.NUMBER);
stmt.setInt(5, num.intValue());
}
{
stmt.setString(6, "com.imaginary.bank.AccountEntity");
}
{
String luid = trans.getIdentifier().getUserID();
stmt.setString(7, luid);
}
{
stmt.setLong(8, trans.getTimestamp());
}
if( stmt.executeUpdate() != 1 ) {
throw new PersistenceException("No row added!");
}
}
catch( SQLException e ) {
throw new PersistenceException("Database error: " +
e.getMessage());
}
finally {
if( stmt != null ) {
try { stmt.close(); }
catch( SQLException e ) { }
}
}
| protected com.imaginary.lwp.jdbc.JDBCJoin | getJoin(java.lang.String tbl)
if( tbl.equals("CUSTOMER") ) {
return new JDBCJoin("ACCOUNT.CUSTOMER_ID",
"CUSTOMER.CUSTOMER_ID");
}
else {
return null;
}
| protected java.lang.String | getPrimaryTable()
return "ACCOUNT";
| public void | load(com.imaginary.lwp.Transaction trans, com.imaginary.lwp.Memento mem, long oid)
PreparedStatement stmt = null;
ResultSet rs = null;
mem.put(BaseEntity.class, "objectID", new Long(oid));
try {
Connection conn = ((JDBCTransaction)trans).getConnection();
stmt = conn.prepareStatement(SELECT);
stmt.setLong(1, oid);
rs = stmt.executeQuery();
if( !rs.next() ) {
throw new PersistenceException("No such objectID: " + oid);
}
{
String str = rs.getString(1);
AccountType t;
if( rs.wasNull() ) {
t = null;
}
else {
if( str.trim().equals("CHK") ) {
t = AccountType.CHECKING;
}
else {
t = AccountType.SAVINGS;
}
}
mem.put(AccountEntity.class, Account.TYPE, t);
}
{
long l = rs.getLong(2);
CustomerFacade cust;
if( rs.wasNull() ) {
cust = null;
}
else {
cust = new CustomerFacade(rs.getLong(2));
}
mem.put(AccountEntity.class, Account.CUSTOMER, cust);
}
{
int num = rs.getInt(3);
if( rs.wasNull() ) {
mem.put(AccountEntity.class, Account.NUMBER, null);
}
else {
mem.put(AccountEntity.class, Account.NUMBER,
new Integer(num));
}
}
{
double bal = rs.getDouble(4);
Double d = null;
if( !rs.wasNull() ) {
d = new Double(bal);
}
mem.put(AccountEntity.class, Account.BALANCE, d);
}
{
String luid = rs.getString(5);
mem.put(BaseEntity.class, "lastUpdateID", luid);
}
{
long l = rs.getLong(6);
mem.put(BaseEntity.class, "lastUpdateTime", new Long(l));
}
if( rs.next() ) {
throw new PersistenceException("Multiple rows matching: "
+ oid);
}
}
catch( SQLException e ) {
throw new PersistenceException("Database error: " +
e.getMessage());
}
finally {
if( rs != null ) {
try { rs.close(); }
catch( SQLException e ) { }
}
if( stmt != null ) {
try { stmt.close(); }
catch( SQLException e ) { }
}
}
| protected java.lang.String | mapField(java.lang.String fld)
if( fld.equals("objectID") ) {
return "ACCOUNT_ID";
}
else if( fld.equals(Account.CUSTOMER) ) {
return "CUSTOMER_ID";
}
else if( fld.equals(Account.TYPE) ) {
return "ACCT_TYPE";
}
else if( fld.equals(Account.NUMBER) ) {
return "ACCT_NUMBER";
}
else if( fld.equals(Account.BALANCE) ) {
return "BALANCE";
}
else {
return fld;
}
| public void | remove(com.imaginary.lwp.Transaction trans, long oid)
PreparedStatement stmt = null;
try {
Connection conn = ((JDBCTransaction)trans).getConnection();
int count;
stmt = conn.prepareStatement(REMOVE);
stmt.setLong(1, oid);
count = stmt.executeUpdate();
if( count < 1 ) {
throw new PersistenceException("No rows removed!");
}
else if( count > 1 ) {
throw new PersistenceException("Too many rows removed!");
}
}
catch( SQLException e ) {
throw new PersistenceException("Database error: " +
e.getMessage());
}
finally {
if( stmt != null ) {
try { stmt.close(); }
catch( SQLException e ) { }
}
}
| public void | store(com.imaginary.lwp.Transaction trans, com.imaginary.lwp.Memento mem)
PreparedStatement stmt = null;
try {
Connection conn = ((JDBCTransaction)trans).getConnection();
int count;
stmt = conn.prepareStatement(UPDATE);
{
CustomerFacade cust;
cust = (CustomerFacade)mem.get(AccountEntity.class,Account.CUSTOMER);
stmt.setLong(1, cust.getObjectID());
}
{
AccountType type;
type = (AccountType)mem.get(AccountEntity.class, Account.TYPE);
stmt.setString(2, type.getCode());
}
{
Integer num = (Integer)mem.get(AccountEntity.class, Account.NUMBER);
stmt.setInt(3, num.intValue());
}
{
Double d = (Double)mem.get(AccountEntity.class, Account.BALANCE);
stmt.setDouble(4, d.doubleValue());
}
stmt.setString(5, trans.getIdentifier().getUserID());
stmt.setLong(6, trans.getTimestamp());
{
Long l = (Long)mem.get(BaseEntity.class, "objectID");
stmt.setLong(7, l.longValue());
}
{
String luid = (String)mem.get(BaseEntity.class,
"lastUpdateID");
stmt.setString(8, luid);
}
{
Long l = (Long)mem.get(BaseEntity.class, "lastUpdateTime");
stmt.setLong(9, l.longValue());
}
count = stmt.executeUpdate();
if( count < 1 ) {
throw new PersistenceException("No rows matching object.");
}
else if( count > 1 ) {
throw new PersistenceException("Too many rows updated: " +
count);
}
}
catch( SQLException e ) {
throw new PersistenceException("Database error: " +
e.getMessage());
}
finally {
if( stmt != null ) {
try { stmt.close(); }
catch( SQLException e ) { }
}
}
|
|