From: Alexey L. <lou...@us...> - 2004-04-07 13:18:59
|
User: loubyansky Date: 04/04/07 06:06:03 Modified: src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema Tag: Branch_3_2 EntityTable.java Log: use hash map to check get cached rows by pk, check the cache before executing find by primary key, check whether debug is enabled before logging. Revision Changes Path No revision No revision 1.1.2.5 +24 -3 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/Attic/EntityTable.java Index: EntityTable.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/Attic/EntityTable.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- EntityTable.java 6 Apr 2004 17:01:13 -0000 1.1.2.4 +++ EntityTable.java 7 Apr 2004 13:06:02 -0000 1.1.2.5 @@ -23,11 +23,13 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.ResultSet; +import java.util.Map; +import java.util.HashMap; /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.1.2.4 $</tt> + * @version <tt>$Revision: 1.1.2.5 $</tt> */ public class EntityTable implements Table @@ -227,6 +229,11 @@ return getView().getRow(id); } + public boolean hasRow(Object id) + { + return getView().hasRow(id); + } + public Object getFieldValue(Object pk, int i) { Row row = getView().getRowByPk(pk, true); @@ -521,6 +528,7 @@ public class View implements Table.View { + private Map rowByPk = new HashMap(); private Row created; private Row deleted; private Row dirty; @@ -546,6 +554,7 @@ public Row getRowByPk(Object pk, boolean required) { + /* Row cursor = clean; while(cursor != null) { @@ -575,13 +584,15 @@ } cursor = cursor.next; } + */ - if(required) + Row row = (Row)rowByPk.get(pk); + if(row == null && required) { throw new IllegalStateException("row not found: pk=" + pk); } - return null; + return row; } public void addClean(Row row) @@ -601,6 +612,8 @@ clean = row; row.state = CLEAN; + + rowByPk.put(row.pk, row); } public void addCreated(Row row) throws DuplicateKeyException @@ -618,6 +631,8 @@ created = row; row.state = CREATED; + + rowByPk.put(row.pk, row); } public Row loadRow(ResultSet rs, Object pk) @@ -664,6 +679,11 @@ return pk; } + public boolean hasRow(Object id) + { + return rowByPk.containsKey(id); + } + private Row createCleanRow(Object pk) { Row row = new Row(this); @@ -744,6 +764,7 @@ { dereference(); state = DELETED; + view.rowByPk.remove(pk); } else if(state == DELETED) { |