db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Kemper <wkem...@franchise.com>
Subject Re: Subqueries in Torque
Date Thu, 24 Jun 2004 21:55:06 GMT
Make your self a little subclass of criteria, and then put this method in it :

public SimpleCriteria addIn(String columnname, Criteria criteria ) {
	try {
		String query = getSubQueryString(criteria);
		// you might have to adapt this to your adapter.
		add( columnname, (Object)(columnname + " in ( " + query + " )"), CUSTOM );
	}
	catch (Exception e) {
		Log.error( "Couldn't create sub select.", e);
	}
	return this;
}

and then put this method in there too:

private String getSubQueryString(Criteria criteria) throws TorqueException {
	if ( criteria.getSelectColumns().size() != 1 ) {
		Log.error("Only one column allowed in subselect.");
		throw new TorqueException("Only one column allowed in subselect.");
	}

	if ( criteria.getBaseTableName() == null ) {
		String fullName = criteria.getSelectColumns().get(0);
	}
		
	return BasePeer.createQueryString(criteria);
}

then use it like this:

searchCriteria.addIn( SomePeer.SOME_COLUMN, 
	new Criteria()
       		.addSelectColumn(SomeOtherPeer.SOME_OTHER_COLUMN)
       		.add(SomeOtherPeer.YET_SOME_OTHER_COLUMN,"'SOME KNOWN VALUE")
);

Hope that helps.

On Thursday 24 June 2004 8:23 am, Michael.Kashambuzi@bmwna.com wrote:
> Basically what I am trying to do is avoiding listing all teh columns in the
> select clause a a result of needing to add a group by clause.
>
> -----Original Message-----
> From: Michael.Kashambuzi@bmwna.com [mailto:Michael.Kashambuzi@bmwna.com]
> Sent: Tuesday, June 22, 2004 7:33 PM
> To: torque-user@db.apache.org
> Subject: Subqueries in Torque
>
>
> Hi-
>
> I have searched the archives and have not been able to find a solution to a
> problem I have.
>
> Is anyone familiar with how to produce a subquery in Torque 3.1?
>
> I am trying to achieve the following:
>
> 	select *
> 	from table1 as a
> 	where a.col1 in
> 	(
> 		select *
> 		from table2 as b
> 		where b.col1 = 'SOME KNOWN VALUE'
> 	)
>
> Thanks.
>
> Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org

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


Mime
View raw message