Return-Path: Delivered-To: apmail-incubator-open-jpa-dev-archive@locus.apache.org Received: (qmail 38296 invoked from network); 20 Feb 2007 11:43:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Feb 2007 11:43:03 -0000 Received: (qmail 72858 invoked by uid 500); 20 Feb 2007 11:43:10 -0000 Delivered-To: apmail-incubator-open-jpa-dev-archive@incubator.apache.org Received: (qmail 72827 invoked by uid 500); 20 Feb 2007 11:43:10 -0000 Mailing-List: contact open-jpa-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: open-jpa-dev@incubator.apache.org Delivered-To: mailing list open-jpa-dev@incubator.apache.org Received: (qmail 72816 invoked by uid 99); 20 Feb 2007 11:43:10 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Feb 2007 03:43:10 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of kwsutter@gmail.com designates 64.233.184.225 as permitted sender) Received: from [64.233.184.225] (HELO wr-out-0506.google.com) (64.233.184.225) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Feb 2007 03:42:59 -0800 Received: by wr-out-0506.google.com with SMTP id i7so2456031wra for ; Tue, 20 Feb 2007 03:42:38 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=dI+38lfRlyMpI8DSzt5v1pqjdDnx/IamzhoFVSI1HCLn2UgMSZolbTid7QBA45BHG6x6we3XlHjZ1qVTki+g6xYZGzoQQaZsajuBb1TqCPG1b1hRqCQQw3x+k0J/BkWj8gJj2mbb+5NBZsvxvyb10M3I/YwkgCTOfppyBcbUodA= Received: by 10.114.46.1 with SMTP id t1mr3305107wat.1171971756561; Tue, 20 Feb 2007 03:42:36 -0800 (PST) Received: by 10.115.55.10 with HTTP; Tue, 20 Feb 2007 03:42:35 -0800 (PST) Message-ID: <89c0c52c0702200342v5f6fbe29jadc7f8fee4526ea7@mail.gmail.com> Date: Tue, 20 Feb 2007 05:42:35 -0600 From: "Kevin Sutter" To: open-jpa-dev@incubator.apache.org Subject: Re: svn commit: r509473 - in /incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc: meta/strats/StateComparisonVersionStrategy.java sql/PrimaryRow.java sql/RowImpl.java sql/SecondaryRow.java In-Reply-To: <20070220085915.50B4C1A981A@eris.apache.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_55953_1329110.1171971755738" References: <20070220085915.50B4C1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_55953_1329110.1171971755738 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Segu, In the future, could you please reference the JIRA Issue in your commit message? Just a simple "OPENJPA-155. Capturing reference to the Column[]..." would automatically put the SVN changed lines into the Jira Issue for easy reference. Thanks. Kevin On 2/20/07, ssegu@apache.org wrote: > > Author: ssegu > Date: Tue Feb 20 00:59:10 2007 > New Revision: 509473 > > URL: http://svn.apache.org/viewvc?view=rev&rev=509473 > Log: > Capturing reference to the Column[] at the creation time in the RowImpl > instead of the Table, to work with DynamicSchemaFactory where the Table's > columns can get modified after the creation of the RowImpl before the flush. > > Modified: > > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StateComparisonVersionStrategy.java > > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java > > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java > > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SecondaryRow.java > > Modified: > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StateComparisonVersionStrategy.java > URL: > http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StateComparisonVersionStrategy.java?view=diff&rev=509473&r1=509472&r2=509473 > > ============================================================================== > --- > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StateComparisonVersionStrategy.java > (original) > +++ > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StateComparisonVersionStrategy.java > Tue Feb 20 00:59:10 2007 > @@ -223,7 +223,11 @@ > implements RowManager { > > private CustomUpdate(Table table) { > - super(table, Row.ACTION_UPDATE); > + this(table.getColumns()); > + } > + > + private CustomUpdate(Column[] cols) { > + super(cols, Row.ACTION_UPDATE); > } > > /** > @@ -252,8 +256,8 @@ > return buf.toString(); > } > > - protected RowImpl newInstance(Table table, int action) { > - return new CustomUpdate(table); > + protected RowImpl newInstance(Column[] cols, int action) { > + return new CustomUpdate(cols); > } > > ///////////////////////////// > > Modified: > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java > URL: > http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java?view=diff&rev=509473&r1=509472&r2=509473 > > ============================================================================== > --- > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java > (original) > +++ > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java > Tue Feb 20 00:59:10 2007 > @@ -59,7 +59,11 @@ > * Constructor; supply table and action. > */ > public PrimaryRow(Table table, int action, OpenJPAStateManager owner) > { > - super(table, action); > + this(table.getColumns(), action, owner); > + } > + > + protected PrimaryRow(Column[] cols, int action, OpenJPAStateManager > owner) { > + super(cols, action); > _pk = owner; > } > > @@ -385,8 +389,8 @@ > return super.generateSQL(dict); > } > > - protected RowImpl newInstance(Table table, int action) { > - return new PrimaryRow(table, action, _pk); > + protected RowImpl newInstance(Column[] cols, int action) { > + return new PrimaryRow(cols, action, _pk); > } > > public void copyInto(RowImpl row, boolean whereOnly) { > > Modified: > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java > URL: > http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java?view=diff&rev=509473&r1=509472&r2=509473 > > ============================================================================== > --- > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java > (original) > +++ > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java > Tue Feb 20 00:59:10 2007 > @@ -59,7 +59,7 @@ > private static final int RAW = Integer.MIN_VALUE; > > protected byte flags = 0; > - private final Table _table; > + private final Column[] _cols; > private final int _action; > private final Object[] _vals; > private final int[] _types; > @@ -73,12 +73,16 @@ > * @param action the action on the row > */ > public RowImpl(Table table, int action) { > - _table = table; > + this(table.getColumns(), action); > + } > + > + protected RowImpl(Column[] cols, int action) { > + _cols = cols; > _action = action; > > // we need room for values and types for all columns; if an > update or > // delete, then we need to double that for where column > conditions > - int len = table.getColumns().length; > + int len = _cols.length; > if (action != ACTION_INSERT) > len *= 2; > _vals = new Object[len]; > @@ -86,7 +90,11 @@ > } > > public Table getTable() { > - return _table; > + return _cols[0].getTable(); > + } > + > + public Column[] getColumns() { > + return _cols; > } > > public int getAction() { > @@ -168,7 +176,7 @@ > boolean set) > throws SQLException { > ClassMapping mapping = (ClassMapping) sm.getMetaData(); > - while (mapping.getTable() != _table) > + while (mapping.getTable() != getTable()) > mapping = mapping.getPCSuperclassMapping(); > Column[] cols = mapping.getPrimaryKeyColumns(); > flushJoinValues(sm, cols, cols, io, set); > @@ -730,15 +738,14 @@ > buf.append("UPDATE ").append(dict.getFullName(getTable(), > false)). > append(" SET "); > > - Column[] cols = getTable().getColumns(); > boolean hasVal = false; > - for (int i = 0; i < cols.length; i++) { > + for (int i = 0; i < _cols.length; i++) { > if (_vals[i] == null) > continue; > > if (hasVal) > buf.append(", "); > - buf.append(cols[i]); > + buf.append(_cols[i]); > if (_types[i] == RAW) > buf.append(" = ").append(_vals[i]); > else > @@ -759,9 +766,8 @@ > buf.append("INSERT INTO "). > append(dict.getFullName(getTable(), false)).append(" ("); > > - Column[] cols = getTable().getColumns(); > boolean hasVal = false; > - for (int i = 0; i < cols.length; i++) { > + for (int i = 0; i < _cols.length; i++) { > if (_vals[i] == null) > continue; > > @@ -769,7 +775,7 @@ > buf.append(", "); > vals.append(", "); > } > - buf.append(cols[i]); > + buf.append(_cols[i]); > if (_types[i] == RAW) > vals.append(_vals[i]); > else > @@ -796,10 +802,9 @@ > * Appends the where clause onto the given sql buffer. > */ > private void appendWhere(StringBuffer buf) { > - Column[] cols = getTable().getColumns(); > boolean hasWhere = false; > - for (int i = 0; i < cols.length; i++) { > - if (_vals[getWhereIndex(cols[i])] == null) > + for (int i = 0; i < _cols.length; i++) { > + if (_vals[getWhereIndex(_cols[i])] == null) > continue; > > if (!hasWhere) > @@ -809,12 +814,12 @@ > > // sqlserver seems to have problems using null parameters in > the > // where clause > - if (_vals[getWhereIndex(cols[i])] == NULL) > - buf.append(cols[i]).append(" IS NULL"); > + if (_vals[getWhereIndex(_cols[i])] == NULL) > + buf.append(_cols[i]).append(" IS NULL"); > else if (_types[i] == RAW) > - buf.append(cols[i]).append(" = ").append(_vals[i]); > + buf.append(_cols[i]).append(" = ").append(_vals[i]); > else > - buf.append(cols[i]).append(" = ?"); > + buf.append(_cols[i]).append(" = ?"); > hasWhere = true; > } > } > @@ -841,14 +846,13 @@ > public void flush(PreparedStatement stmnt, int idx, DBDictionary > dict, > JDBCStore store) > throws SQLException { > - Column[] cols = getTable().getColumns(); > > // this simple method works because the SQL is always prepared > // based on the indexing of the columns in the table object -- > the > // same ordering we use when storing values and meta types. skip > // updates when setting params for DELETEs; the updates are just > there > // to let us eval fk constraints > - int i = (getAction() == ACTION_DELETE) ? cols.length : 0; > + int i = (getAction() == ACTION_DELETE) ? _cols.length: 0; > Column col; > Object val; > int half = _vals.length / 2; > @@ -863,10 +867,10 @@ > > // if this is an update the vals array will be 2 x the cols > // array length; it repeats for where values > - if (i < cols.length) > - col = cols[i]; > + if (i < _cols.length) > + col = _cols[i]; > else > - col = cols[i - cols.length]; > + col = _cols[i - _cols.length]; > > val = _vals[i]; > if (val == NULL) > @@ -890,14 +894,14 @@ > * The array value array index for the given column's value. > */ > private int getWhereIndex(Column col) { > - return col.getIndex() + getTable().getColumns().length; > + return col.getIndex() + _cols.length; > } > > /** > * Performs a proper deep clone. > */ > public Object clone() { > - RowImpl clone = newInstance(getTable(), getAction()); > + RowImpl clone = newInstance(getColumns(), getAction()); > copyInto(clone, false); > return clone; > } > @@ -905,8 +909,8 @@ > /** > * Return a new row. > */ > - protected RowImpl newInstance(Table table, int action) { > - return new RowImpl(table, action); > + protected RowImpl newInstance(Column[] cols, int action) { > + return new RowImpl(cols, action); > } > > /** > @@ -939,4 +943,3 @@ > row.setValid(true); > } > } > - > > Modified: > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SecondaryRow.java > URL: > http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SecondaryRow.java?view=diff&rev=509473&r1=509472&r2=509473 > > ============================================================================== > --- > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SecondaryRow.java > (original) > +++ > incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SecondaryRow.java > Tue Feb 20 00:59:10 2007 > @@ -43,7 +43,11 @@ > * Constructor; supply table and action. > */ > public SecondaryRow(Table table, int action) { > - super(table, action); > + this(table.getColumns(), action); > + } > + > + protected SecondaryRow(Column[] cols, int action) { > + super(cols, action); > } > > public void setForeignKey(ForeignKey fk, OpenJPAStateManager sm) > @@ -161,8 +165,8 @@ > return super.generateSQL(dict); > } > > - protected RowImpl newInstance(Table table, int action) { > - return new SecondaryRow(table, action); > + protected RowImpl newInstance(Column[] cols, int action) { > + return new SecondaryRow(cols, action); > } > > public void copyInto(RowImpl row, boolean whereOnly) { > > > ------=_Part_55953_1329110.1171971755738--