db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carl Manaster (JIRA)" <j...@apache.org>
Subject [jira] Commented: (TORQUE-113) doDelete with invalid column should throw exception, not delete all rows
Date Fri, 18 Apr 2008 15:48:21 GMT

    [ https://issues.apache.org/jira/browse/TORQUE-113?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12590490#action_12590490

Carl Manaster commented on TORQUE-113:

I should have mentioned that the code that was generating the wrong-case string constants
was doing so generically, with a mix of introspection and "manual" string manipulation - building
"table.TABLE_ID" from "table", basically.  I'm not sure why it was doing the case conversion,
but it was and it used to work.  I don't think I know of a way to get the PK from a table
via introspection; for more direct (non-generic) queries we of course use the Peer class constants.

... OK, saying I don't know how made me think, and of course it's pretty simple:

	 * @param table
	 * @return the name of the primary key field
	 * @throws Exception
	public static String getIdField(String table) throws Exception {
		String idFieldName = table.toUpperCase() + "_ID";
		Class<?> peer = getPeerClass(table);
		Field field = peer.getField(idFieldName);
		return (String) field.get(null);

Which perhaps suggests where that whole toUpperCase() business came from in the first place.
 In case anyone missed it, this function of course relies on the primary key being named table.table_id,
but that's a common enough convention.

> doDelete with invalid column should throw exception, not delete all rows
> ------------------------------------------------------------------------
>                 Key: TORQUE-113
>                 URL: https://issues.apache.org/jira/browse/TORQUE-113
>             Project: Torque
>          Issue Type: Bug
>          Components: Runtime
>    Affects Versions: 3.3
>            Reporter: Julian Zinn
>             Fix For: 3.3, 4.0
> The following (incorrect) client code should cause an exception to be thrown.  Instead
of an exception, all rows in table T1 are deleted.
> {code}
> T1Peer.doDelete(new Criteria().add(T2Peer.COL, 2));
> {code}
> This code appeared in a project I am working on.  The intent was to delete rows from
table T2.
> Before the fix for TORQUE-93, this code had the intended effect becaue {{T1Peer.doDelete(criteria)}}
just passed the criteria object to {{BasePeer.doDelete(criteria)}}.  Since the only reference
BasePeer had to a table was table T2 in the criteria, only rows in table T2 were deleted.
> Now that {{T1Peer.doDelete(criteria)}} calls {{BasePeer.doDelete(criteria, TABLE_NAME)}}
instead, the test {{if (crit.containsKey(key))}} in {{BasePeer.processTables()}} always fails.
 This leads to an empty where clause, causing all rows in table T1 to be deleted.
> *Expect*: All Criterion objects in a Criteria should be used in the final where clause.
 If not, an exception should be thrown.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org

View raw message