You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2013/05/22 09:25:03 UTC
svn commit: r1485101 - in /db/torque/torque4/trunk:
torque-runtime/src/main/java/org/apache/torque/sql/
torque-runtime/src/main/java/org/apache/torque/util/
torque-runtime/src/test/java/org/apache/torque/util/
torque-templates/src/main/resources/org/ap...
Author: tfischer
Date: Wed May 22 07:25:03 2013
New Revision: 1485101
URL: http://svn.apache.org/r1485101
Log:
TORQUE-277 make updates possible with verbatim SQL
Changed type of verbatim SQL from String to Column to conform with other API
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/JdbcTypedValue.java
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DoInsertTest.java
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DoUpdateTest.java
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java?rev=1485101&r1=1485100&r2=1485101&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java Wed May 22 07:25:03 2013
@@ -571,14 +571,15 @@ public class Query
stringBuilder.append(",");
}
stringBuilder.append(entry.getKey().getSqlExpression());
- if (entry.getValue().getVerbatimSql() == null)
+ if (entry.getValue().getSqlExpression() == null)
{
stringBuilder.append("=?");
}
else
{
+ Column sqlExpression = entry.getValue().getSqlExpression();
stringBuilder.append("=")
- .append(entry.getValue().getVerbatimSql());
+ .append(sqlExpression.getSqlExpression());
}
first = false;
}
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java?rev=1485101&r1=1485100&r2=1485101&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java Wed May 22 07:25:03 2013
@@ -458,14 +458,16 @@ public class BasePeerImpl<T> implements
{
query.append(",");
}
- if (columnValue.getValue().getVerbatimSql() == null)
+ if (columnValue.getValue().getSqlExpression() == null)
{
query.append("?");
replacementObjects.add(columnValue.getValue());
}
else
{
- query.append(columnValue.getValue().getVerbatimSql());
+ Column sqlExpression
+ = columnValue.getValue().getSqlExpression();
+ query.append(sqlExpression.getSqlExpression());
}
first = false;
}
@@ -1334,7 +1336,7 @@ public class BasePeerImpl<T> implements
: updateValues.entrySet())
{
JdbcTypedValue replacementObject = updateValue.getValue();
- if (replacementObject.getVerbatimSql() != null)
+ if (replacementObject.getSqlExpression() != null)
{
// replacementObject is no real value but contains
// a sql snippet which was (hopefully) processed earlier.
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/JdbcTypedValue.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/JdbcTypedValue.java?rev=1485101&r1=1485100&r2=1485101&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/JdbcTypedValue.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/JdbcTypedValue.java Wed May 22 07:25:03 2013
@@ -19,12 +19,12 @@ package org.apache.torque.util;
* under the License.
*/
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.torque.Column;
/**
- * A value plus its JDBC type.
+ * A value for a column, with the JDBC type if it is an explicit value.
*
* @version $Id$
*/
@@ -36,8 +36,8 @@ public class JdbcTypedValue
/** The value; may be null. */
private Object value;
- /** A verbatim SQL to use instead of the value. */
- private String verbatimSql;
+ /** A database expression to use instead of the value. */
+ private Column sqlExpression;
/**
* Constructs a JdbcTypedValue with a value and a type.
@@ -54,16 +54,16 @@ public class JdbcTypedValue
/**
* Constructs a JdbcTypedValue with a verbatim SQL.
*
- * @param verbatimSql The verbatim sql to use instead of the value.
+ * @param sqlExpression The sql expression to use instead of the value.
*/
- public JdbcTypedValue(final String verbatimSql)
+ public JdbcTypedValue(final Column sqlExpression)
{
- if (StringUtils.isBlank(verbatimSql))
+ if (sqlExpression == null)
{
throw new IllegalArgumentException(
- "verbatimSql must not be null or blank");
+ "sqlExpression must not be null");
}
- this.verbatimSql = verbatimSql;
+ this.sqlExpression = sqlExpression;
}
/**
@@ -81,14 +81,14 @@ public class JdbcTypedValue
*
* @param jdbcType the JDBC type of the value.
*
- * @throws IllegalStateException if verbatimSql is set.
+ * @throws IllegalStateException if sqlExpression is set.
*/
public void setJdbcType(final int jdbcType)
{
- if (verbatimSql != null)
+ if (sqlExpression != null)
{
throw new IllegalStateException(
- "jdbcType may not be set if verbatimSql is set");
+ "jdbcType may not be set if sqlExpression is set");
}
this.jdbcType = jdbcType;
}
@@ -104,13 +104,13 @@ public class JdbcTypedValue
}
/**
- * Returns the verbatimSql to use instead of the value.
+ * Returns the sqlExpression to use instead of the value.
*
- * @return value the verbatimSql, or null if not set.
+ * @return value the sqlExpression, or null if not set.
*/
- public String getVerbatimSql()
+ public Column getSqlExpression()
{
- return verbatimSql;
+ return sqlExpression;
}
/**
@@ -118,14 +118,14 @@ public class JdbcTypedValue
*
* @param value the value, may be null.
*
- * @throws IllegalStateException if verbatimSql is set.
+ * @throws IllegalStateException if sqlExpression is set.
*/
public void setValue(final Object value)
{
- if (verbatimSql != null)
+ if (sqlExpression != null)
{
throw new IllegalStateException(
- "value may not be set if verbatimSql is set");
+ "value may not be set if sqlExpression is set");
}
this.value = value;
}
@@ -136,7 +136,7 @@ public class JdbcTypedValue
HashCodeBuilder hashCodeBuilder = new HashCodeBuilder()
.append(jdbcType)
.append(value)
- .append(verbatimSql);
+ .append(sqlExpression);
return hashCodeBuilder.toHashCode();
}
@@ -159,21 +159,21 @@ public class JdbcTypedValue
EqualsBuilder equalsBuilder = new EqualsBuilder()
.append(jdbcType, other.jdbcType)
.append(value, other.value)
- .append(verbatimSql, other.verbatimSql);
+ .append(sqlExpression, other.sqlExpression);
return equalsBuilder.isEquals();
}
@Override
public String toString()
{
- if (verbatimSql == null)
+ if (sqlExpression == null)
{
return "JdbcTypedValue [jdbcType=" + jdbcType
+ ", value=" + value + "]";
}
else
{
- return "JdbcTypedValue [verbatimSql=" + verbatimSql + "]";
+ return "JdbcTypedValue [sqlExpression=" + sqlExpression + "]";
}
}
}
Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java?rev=1485101&r1=1485100&r2=1485101&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java Wed May 22 07:25:03 2013
@@ -34,6 +34,7 @@ import java.sql.Types;
import java.util.List;
import org.apache.torque.BaseTestCase;
+import org.apache.torque.ColumnImpl;
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import org.apache.torque.adapter.IDMethod;
@@ -302,7 +303,7 @@ public class BasePeerImplTest extends Ba
// prepare
ColumnValues insertValues = new ColumnValues(databaseMap.getName());
insertValues.put(stringColumnMap, new JdbcTypedValue("value", Types.VARCHAR));
- insertValues.put(stringColumnMap2, new JdbcTypedValue("someDbFunction"));
+ insertValues.put(stringColumnMap2, new JdbcTypedValue(new ColumnImpl("someDbFunction")));
insertValues.put(stringColumnMap3, new JdbcTypedValue(null, Types.VARCHAR));
insertValues.put(integerColumnMap, new JdbcTypedValue(42, Types.INTEGER));
@@ -427,7 +428,7 @@ public class BasePeerImplTest extends Ba
ColumnValues updateValues = new ColumnValues(databaseMap.getName());
updateValues.put(stringColumnMap, new JdbcTypedValue("value", Types.VARCHAR));
- updateValues.put(stringColumnMap2, new JdbcTypedValue("someDbFunction"));
+ updateValues.put(stringColumnMap2, new JdbcTypedValue(stringColumnMap3));
updateValues.put(stringColumnMap3, new JdbcTypedValue(null, Types.VARCHAR));
updateValues.put(integerColumnMap, new JdbcTypedValue(42, Types.INTEGER));
@@ -436,7 +437,7 @@ public class BasePeerImplTest extends Ba
// verify mock (verification order not relevant)
verify(connection).prepareStatement(
"UPDATE TABLE SET TABLE.COLUMN1=?,"
- + "TABLE.COLUMN2=someDbFunction,"
+ + "TABLE.COLUMN2=TABLE.COLUMN3,"
+ "TABLE.COLUMN3=?,"
+ "TABLE.COLUMN4=? "
+ "WHERE TABLE.COLUMN4=?");
@@ -471,7 +472,7 @@ public class BasePeerImplTest extends Ba
{
ColumnValues updateValues = new ColumnValues(databaseMap.getName());
updateValues.put(stringColumnMap, new JdbcTypedValue("value", Types.VARCHAR));
- updateValues.put(stringColumnMap2, new JdbcTypedValue("someDbFunction"));
+ updateValues.put(stringColumnMap2, new JdbcTypedValue(new ColumnImpl("someDbFunction")));
updateValues.put(stringColumnMap3, new JdbcTypedValue(null, Types.VARCHAR));
updateValues.put(integerColumnMap, new JdbcTypedValue(42, Types.INTEGER));
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm?rev=1485101&r1=1485100&r2=1485101&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm Wed May 22 07:25:03 2013
@@ -92,7 +92,7 @@
+ "${peerClassName}.${peerColumnName}"
+ " must be set");
}
- if (pkValue.getVerbatimSql() == null)
+ if (pkValue.getSqlExpression() == null)
{
selectCriteria.where(
${peerClassName}.${peerColumnName},
@@ -102,7 +102,7 @@
{
selectCriteria.where(
${peerClassName}.${peerColumnName},
- new ColumnImpl(pkValue.getVerbatimSql()));
+ pkValue.getSqlExpression());
}
}
#end
Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DoInsertTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DoInsertTest.java?rev=1485101&r1=1485100&r2=1485101&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DoInsertTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DoInsertTest.java Wed May 22 07:25:03 2013
@@ -24,6 +24,7 @@ import java.sql.Types;
import java.util.List;
import org.apache.torque.BaseDatabaseTestCase;
+import org.apache.torque.ColumnImpl;
import org.apache.torque.criteria.Criteria;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.test.dbobject.Author;
@@ -115,7 +116,7 @@ public class DoInsertTest extends BaseDa
new JdbcTypedValue(5, Types.INTEGER));
columnValues.put(
IntegerTypePeer.INTEGER_OBJECT_VALUE,
- new JdbcTypedValue("ABS(-3)"));
+ new JdbcTypedValue(new ColumnImpl("3")));
// execute
ObjectKey objectKey = IntegerTypePeer.doInsert(columnValues);
Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DoUpdateTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DoUpdateTest.java?rev=1485101&r1=1485100&r2=1485101&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DoUpdateTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DoUpdateTest.java Wed May 22 07:25:03 2013
@@ -23,6 +23,7 @@ import java.sql.Types;
import java.util.List;
import org.apache.torque.BaseDatabaseTestCase;
+import org.apache.torque.ColumnImpl;
import org.apache.torque.criteria.Criteria;
import org.apache.torque.test.dbobject.Author;
import org.apache.torque.test.dbobject.IntegerType;
@@ -137,8 +138,8 @@ public class DoUpdateTest extends BaseDa
new JdbcTypedValue("newName", Types.VARCHAR));
columnValues.put(
AuthorPeer.AUTHOR_ID,
- new JdbcTypedValue(
- Integer.toString(authorList.get(1).getAuthorId())));
+ new JdbcTypedValue(new ColumnImpl(
+ Integer.toString(authorList.get(1).getAuthorId()))));
// execute
int numberOfRows = AuthorPeer.doUpdate(columnValues);
@@ -171,7 +172,7 @@ public class DoUpdateTest extends BaseDa
new JdbcTypedValue(5, Types.INTEGER));
columnValues.put(
IntegerTypePeer.INTEGER_OBJECT_VALUE,
- new JdbcTypedValue("ABS(-3)"));
+ new JdbcTypedValue(new ColumnImpl("3")));
columnValues.put(
IntegerTypePeer.ID,
new JdbcTypedValue(integerType.getId(), Types.INTEGER));
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org