Author: tfischer
Date: Mon Aug 20 04:21:08 2012
New Revision: 1374911
URL: http://svn.apache.org/viewvc?rev=1374911&view=rev
Log:
TORQUE-219
IdGenerator interface should throw TorqueException not Exception
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IdGenerator.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java?rev=1374911&r1=1374910&r2=1374911&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java
(original)
+++
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java
Mon Aug 20 04:21:08 2012
@@ -300,7 +300,7 @@ public class IDBroker implements Runnabl
* @exception Exception Database error.
*/
public int getIdAsInt(Connection connection, Object tableName)
- throws Exception
+ throws TorqueException
{
return getIdAsBigDecimal(connection, tableName).intValue();
}
@@ -319,7 +319,7 @@ public class IDBroker implements Runnabl
* @exception Exception Database error.
*/
public long getIdAsLong(Connection connection, Object tableName)
- throws Exception
+ throws TorqueException
{
return getIdAsBigDecimal(connection, tableName).longValue();
}
@@ -338,7 +338,7 @@ public class IDBroker implements Runnabl
*/
public BigDecimal getIdAsBigDecimal(Connection connection,
Object tableName)
- throws Exception
+ throws TorqueException
{
BigDecimal[] id = getNextIds((String) tableName, 1, connection);
return id[0];
@@ -357,7 +357,7 @@ public class IDBroker implements Runnabl
* @exception Exception Database error.
*/
public String getIdAsString(Connection connection, Object tableName)
- throws Exception
+ throws TorqueException
{
return getIdAsBigDecimal(connection, tableName).toString();
}
@@ -429,16 +429,16 @@ public class IDBroker implements Runnabl
* @param numOfIdsToReturn The desired number of ids.
* @param connection A Connection.
* @return A BigDecimal.
- * @exception Exception Database error.
+ * @exception TorqueException on a database error.
*/
public synchronized BigDecimal[] getNextIds(String tableName,
int numOfIdsToReturn,
Connection connection)
- throws Exception
+ throws TorqueException
{
if (tableName == null)
{
- throw new Exception("getNextIds(): tableName == null");
+ throw new TorqueException("getNextIds(): tableName == null");
}
// A note about the synchronization: I (jmcnally) looked at
@@ -673,12 +673,12 @@ public class IDBroker implements Runnabl
* @param tableName The name of the table for which we want an id.
* @param adjustQuantity True if amount should be adjusted.
* @param connection a Connection
- * @exception Exception a generic exception.
+ * @exception on a database error.
*/
private synchronized void storeIDs(String tableName,
boolean adjustQuantity,
Connection connection)
- throws Exception
+ throws TorqueException
{
BigDecimal nextId = null;
BigDecimal quantity = null;
@@ -724,7 +724,7 @@ public class IDBroker implements Runnabl
Transaction.commit(connection);
}
}
- catch (Exception e)
+ catch (TorqueException e)
{
if (useNewConnection)
{
@@ -820,10 +820,10 @@ public class IDBroker implements Runnabl
* @param tableName The properly escaped name of the table to
* identify the row.
* @return A BigDecimal[].
- * @exception Exception a generic exception.
+ * @exception TorqueException on a database error.
*/
private BigDecimal[] selectRow(Connection con, String tableName)
- throws Exception
+ throws TorqueException
{
StringBuffer stmt = new StringBuffer();
stmt.append("SELECT ")
@@ -867,6 +867,10 @@ public class IDBroker implements Runnabl
statement = null;
}
+ catch (SQLException e)
+ {
+ throw new TorqueException(e);
+ }
finally
{
if (rs != null)
@@ -903,10 +907,10 @@ public class IDBroker implements Runnabl
* @param tableName The properly escaped name of the table to identify the
* row.
* @param id An int with the value to set for the id.
- * @exception Exception Database error.
+ * @exception TorqueException Database error.
*/
private void updateNextId(Connection con, String tableName, String id)
- throws Exception
+ throws TorqueException
{
@@ -934,11 +938,22 @@ public class IDBroker implements Runnabl
statement = con.createStatement();
statement.executeUpdate(stmt.toString());
}
+ catch (SQLException e)
+ {
+ throw new TorqueException(e);
+ }
finally
{
if (statement != null)
{
- statement.close();
+ try
+ {
+ statement.close();
+ }
+ catch (SQLException e)
+ {
+ throw new TorqueException(e);
+ }
}
}
}
@@ -950,11 +965,11 @@ public class IDBroker implements Runnabl
* @param tableName The properly escaped name of the table to identify the
* row.
* @param quantity An int with the value of the quantity.
- * @exception Exception Database error.
+ * @exception TorqueException Database error.
*/
protected void updateQuantity(Connection con, String tableName,
BigDecimal quantity)
- throws Exception
+ throws TorqueException
{
StringBuilder stmt = new StringBuilder();
stmt.append("UPDATE ")
@@ -981,11 +996,22 @@ public class IDBroker implements Runnabl
statement = con.createStatement();
statement.executeUpdate(stmt.toString());
}
+ catch (SQLException e)
+ {
+ throw new TorqueException(e);
+ }
finally
{
if (statement != null)
{
- statement.close();
+ try
+ {
+ statement.close();
+ }
+ catch (SQLException e)
+ {
+ throw new TorqueException(e);
+ }
}
}
}
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IdGenerator.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IdGenerator.java?rev=1374911&r1=1374910&r2=1374911&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IdGenerator.java
(original)
+++
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IdGenerator.java
Mon Aug 20 04:21:08 2012
@@ -19,8 +19,10 @@ package org.apache.torque.oid;
* under the License.
*/
-import java.sql.Connection;
import java.math.BigDecimal;
+import java.sql.Connection;
+
+import org.apache.torque.TorqueException;
/**
* Interface to be implemented by id generators. It is possible
@@ -39,48 +41,56 @@ public interface IdGenerator
* Returns an id as a primitive int. If you use numeric
* identifiers, it's suggested that {@link
* #getIdAsLong(Connection, Object)} be used instead (due to the
- * limitted range of this method).
+ * limited range of this method).
*
- * @param connection A Connection.
+ * @param connection The database connection to use.
* @param keyInfo an Object that contains additional info.
- * @return An int with the value for the id.
- * @exception Exception Database error.
+ *
+ * @return The id as integer.
+ *
+ * @exception TorqueException if a Database error occurs.
*/
int getIdAsInt(Connection connection, Object keyInfo)
- throws Exception;
+ throws TorqueException;
/**
* Returns an id as a primitive long.
*
- * @param connection A Connection.
+ * @param connection The database connection to use.
* @param keyInfo an Object that contains additional info.
- * @return A long with the value for the id.
- * @exception Exception Database error.
+ *
+ * @return The id as long.
+ *
+ * @exception TorqueException if a Database error occurs.
*/
long getIdAsLong(Connection connection, Object keyInfo)
- throws Exception;
+ throws TorqueException;
/**
* Returns an id as a BigDecimal.
*
- * @param connection A Connection.
+ * @param connection The database connection to use.
* @param keyInfo an Object that contains additional info.
- * @return A BigDecimal id.
- * @exception Exception Database error.
+ *
+ * @return The id as BigDecimal.
+ *
+ * @exception TorqueException if a Database error occurs.
*/
BigDecimal getIdAsBigDecimal(Connection connection, Object keyInfo)
- throws Exception;
+ throws TorqueException;
/**
* Returns an id as a String.
*
- * @param connection A Connection.
+ * @param connection The database connection to use.
* @param keyInfo an Object that contains additional info.
- * @return A String id
- * @exception Exception Database error.
+ *
+ * @return The id as String.
+ *
+ * @exception TorqueException if a Database error occurs.
*/
String getIdAsString(Connection connection, Object keyInfo)
- throws Exception;
+ throws TorqueException;
/**
* A flag to determine the timing of the id generation
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=1374911&r1=1374910&r2=1374911&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
Mon Aug 20 04:21:08 2012
@@ -886,30 +886,16 @@ public class BasePeerImpl<T> implements
{
SimpleKey id = null;
- try
- {
- if (pk != null && keyGen != null)
- {
- if (pk.getType() instanceof Number)
- {
- id = new NumberKey(
- keyGen.getIdAsBigDecimal(con, keyInfo));
- }
- else
- {
- id = new StringKey(keyGen.getIdAsString(con, keyInfo));
- }
- }
- }
- catch (Exception e)
+ if (pk != null && keyGen != null)
{
- if (e instanceof TorqueException)
+ if (pk.getType() instanceof Number)
{
- throw (TorqueException) e;
+ id = new NumberKey(
+ keyGen.getIdAsBigDecimal(con, keyInfo));
}
else
{
- throw new TorqueException(e);
+ id = new StringKey(keyGen.getIdAsString(con, keyInfo));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]