Author: tfischer
Date: Thu Sep 29 13:08:50 2011
New Revision: 1177296
URL: http://svn.apache.org/viewvc?rev=1177296&view=rev
Log:
make selection of target database possible also for write access. This got lost
during the replacement of Criteria by ColumnValues to hold the update values.
Modified:
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/ColumnValues.java
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=1177296&r1=1177295&r2=1177296&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
Thu Sep 29 13:08:50 2011
@@ -396,19 +396,11 @@ public class BasePeerImpl implements Ser
public ObjectKey doInsert(ColumnValues insertValues)
throws TorqueException
{
- String databaseName;
+ String databaseName = insertValues.getDbName();
+ if (databaseName == null)
{
TableMap table = insertValues.getTable();
- if (table == null)
- {
- log.debug("doUpdate(): no Table set in updateValues, "
- + "using default database");
- databaseName = Torque.getDefaultDB();
- }
- else
- {
- databaseName = table.getDatabaseMap().getDatabase().getName();
- }
+ databaseName = table.getDatabaseMap().getDatabase().getName();
}
Connection connection = null;
try
@@ -1103,19 +1095,11 @@ public class BasePeerImpl implements Ser
public int doUpdate(ColumnValues updateValues)
throws TorqueException
{
- String databaseName;
+ String databaseName = updateValues.getDbName();
+ if (databaseName == null)
{
TableMap table = updateValues.getTable();
- if (table == null)
- {
- log.debug("doUpdate(): no Table set in updateValues, "
- + "using default database");
- databaseName = Torque.getDefaultDB();
- }
- else
- {
- databaseName = table.getDatabaseMap().getDatabase().getName();
- }
+ databaseName = table.getDatabaseMap().getDatabase().getName();
}
Connection connection = null;
try
@@ -1203,19 +1187,11 @@ public class BasePeerImpl implements Ser
ColumnValues updateValues)
throws TorqueException
{
- String databaseName;
+ String databaseName = updateValues.getDbName();
+ if (databaseName == null)
{
TableMap table = updateValues.getTable();
- if (table == null)
- {
- log.debug("doUpdate(): no Table set in updateValues, "
- + "using default database");
- databaseName = Torque.getDefaultDB();
- }
- else
- {
- databaseName = table.getDatabaseMap().getDatabase().getName();
- }
+ databaseName = table.getDatabaseMap().getDatabase().getName();
}
Connection connection = null;
try
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/ColumnValues.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/ColumnValues.java?rev=1177296&r1=1177295&r2=1177296&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/ColumnValues.java
(original)
+++
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/ColumnValues.java
Thu Sep 29 13:08:50 2011
@@ -40,26 +40,60 @@ public class ColumnValues implements Map
private Map<String, JdbcTypedValue> columnValues;
/**
- * Constructor.
+ * The name of the database handle to use for connection opening if needed,
+ * or null to use the default database handle for the table.
+ */
+ private String dbName;
+
+ /**
+ * Constructor with no contained column values.
*
- * @param columnValues the column values, or null.
+ * @param table the table to which these values belong, not null.
+ *
+ * @throws NullPointerException if table is null.
*/
public ColumnValues(TableMap table)
{
+ if (table == null)
+ {
+ throw new NullPointerException("table must not be null");
+ }
this.table = table;
this.columnValues = new HashMap<String, JdbcTypedValue>();
}
/**
+ * Constructor with no contained column values.
+ *
+ * @param table the table to which these values belong, not null.
+ * @param dbName the name of the database handle to use for connection
+ * opening if needed, or null to use the default database handle
+ * for the table.
+ *
+ * @throws NullPointerException if table is null.
+ */
+ public ColumnValues(TableMap table, String dbName)
+ {
+ this(table);
+ this.dbName = dbName;
+ }
+
+ /**
* Constructor.
*
* @param columnValues the column values, or null.
- * @param table the table to which these values belong to.
+ * @param table the table to which these values belong, not null.
+ *
+ * @throws NullPointerException if table is null.
*/
public ColumnValues(
Map<String, JdbcTypedValue> columnValues,
TableMap table)
{
+ if (table == null)
+ {
+ throw new NullPointerException("table must not be null");
+ }
this.table = table;
if (columnValues == null)
{
@@ -72,15 +106,47 @@ public class ColumnValues implements Map
}
/**
+ * Constructor.
+ *
+ * @param columnValues the column values, or null.
+ * @param table the table to which these values belong, not null.
+ * @param dbName the name of the database handle to use for connection
+ * opening if needed, or null to use the default database handle
+ * for the table.
+ *
+ * @throws NullPointerException if table is null.
+ */
+ public ColumnValues(
+ Map<String, JdbcTypedValue> columnValues,
+ TableMap table,
+ String dbName)
+ {
+ this(columnValues, table);
+ this.dbName = dbName;
+ }
+
+ /**
* Returns the table to which these columns belong to.
*
- * @return the table to which these columns belong to.
+ * @return the table to which these columns belong to, not null.
*/
public TableMap getTable()
{
return table;
}
+ /**
+ * Returns the name of the database handle to use for connection
+ * opening.
+ *
+ * @return the database name, or null to use the default database handle
+ * for the table.
+ */
+ public String getDbName()
+ {
+ return dbName;
+ }
+
public int size()
{
return columnValues.size();
@@ -145,6 +211,7 @@ public class ColumnValues implements Map
public String toString()
{
return "ColumnValues [table=" + table
+ + ", dbName=" + dbName
+ ", columnValues=" + columnValues + "]";
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]