Holger's Java API

## com.antelmann.sql
Class SubSelectCondition

    java.lang.Object
      com.antelmann.sql.SubSelectCondition

All Implemented Interfaces:
  SQLConstraint, Serializable

    public class SubSelectCondition

extends Object
implements SQLConstraint

allows to specify a sub-query with optional parameters and an operator as a condition for a larger SQL-query-statement. This implementation also provides a few convenience methods to instantiate typical constraints.

Since:
  23.01.2009, 17:04:14
Author:
  Holger Antelmann
See Also:
  `SQLMapFilter`, `ConnectionHelper.addWhereClause(Appendable, java.util.List, java.util.Map, boolean)`, Serialized Form

Nested Class Summary
`static class` `SubSelectCondition.Operator`

Field Summary

Fields inherited from interface com.antelmann.sql.SQLConstraint
`IS_NULL, NOT_NULL`

Constructor Summary
`SubSelectCondition(SubSelectCondition.Operator operator, String subQueryString, Object... parameters)`

Method Summary
`static SubSelectCondition` `createDuplicateConstraint(DBClassStore<?> store, String... columns)` creates a constraint to be used with an `SQLMapFilter` that limits the result to entries where values in the given columns exist more than once.
`static SubSelectCondition` `createDuplicateConstraint(String table, String... columns)`
`static SubSelectCondition` `createGroupConstraint(DBClassStore<?> store, String... groups)`
`static SubSelectCondition` `createGroupConstraint(MappingInfo mi, TaggableMapping gm, String... groups)` creates a constraint to be used with an `SQLMapFilter` that limits the result to entries that are part of one of the given groups.
`static SubSelectCondition` `createPropertyConstraint(DBClassStore<?> store, String key, String... values)` creates a constraint that can be used with an `SQLMapFilter` that limits the result to entries that have the given key with any of the given values.
`SubSelectCondition.Operator` `getOperator()`
`Object[]` `getParameters()`
`String` `getSubQueryString()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### SubSelectCondition

    public SubSelectCondition(SubSelectCondition.Operator operator,
                              String subQueryString,
                              Object... parameters)

Method Detail

### getSubQueryString

    public String getSubQueryString()

### getOperator

    public SubSelectCondition.Operator getOperator()

### getParameters

    public Object[] getParameters()

### createDuplicateConstraint

    public static SubSelectCondition createDuplicateConstraint(DBClassStore<?> store,
                                                               String... columns)
                                                        throws IllegalArgumentException

  creates a constraint to be used with an `SQLMapFilter` that limits the result to entries where values in the given columns exist more than once. The return value is to be put into a filter map as a value mapped by the first column given as parameter. This method uses 'group by' and 'having' to find the duplicates; `ConnectionHelper.findDuplicates(String, java.util.Map, String...)` provides an alternative.

  Parameters:
    `store` - the DBClassStore for the entries to be filtered
  Returns:
    a constraint that may be put into an `SQLMapFilter` as a value mapped by the first column given
  Throws:
    `IllegalArgumentException` - if the given store doesn't support the `MappingInfo` interface
  See Also:
    `createDuplicateConstraint(String, String...)`, `ConnectionHelper.findDuplicates(String, java.util.Map, String...)`

### createDuplicateConstraint

    public static SubSelectCondition createDuplicateConstraint(String table,
                                                               String... columns)
                                                        throws IllegalArgumentException

  Throws:
    `IllegalArgumentException`
  See Also:
    `createDuplicateConstraint(DBClassStore, String...)`

### createGroupConstraint

    public static SubSelectCondition createGroupConstraint(DBClassStore<?> store,
                                                           String... groups)
                                                    throws IllegalArgumentException

  Throws:
    `IllegalArgumentException`

### createGroupConstraint

    @Todo(value="actually, this implementation shouldn\'t requre a join; it should suffice to just select the ids from the rows that contain the group")
    public static SubSelectCondition createGroupConstraint(MappingInfo mi,
                                                                     TaggableMapping gm,
                                                                     String... groups)
                                                    throws IllegalArgumentException

  creates a constraint to be used with an `SQLMapFilter` that limits the result to entries that are part of one of the given groups. If no groups are given, the condition limits the result to those that have no group. The return value is to be put into a filter map as a value mapped by the id column of the original store.

  Parameters:
    `mi` - the MappingInfo from the store that is to be queried
    `groups` - the groups that the desired entries are to be part of
  Returns:
    a constraint that may be put into an `SQLMapFilter` as a value mapped by the ID column of the given store
  Throws:
    `IllegalArgumentException` - if the given store doesn't support the `MappingInfo` interface
  See Also:
    `TaggableSQLStore`, `Database.queryStoreForInterface(Class, Class)`, `MappingInfo.getIDColumn()`

### createPropertyConstraint

    @Todo(value="actually, this implementation shouldn\'t requre a join; it should suffice to just select the ids from the rows that contain the property")
    public static SubSelectCondition createPropertyConstraint(DBClassStore<?> store,
                                                                        String key,
                                                                        String... values)
                                                       throws IllegalArgumentException

  creates a constraint that can be used with an `SQLMapFilter` that limits the result to entries that have the given key with any of the given values. The return value is to be put into a filter map as a value mapped by the id column of the original store.

  Parameters:
    `store` - the DBClassStore for the entries to be filtered
    `key` - this key must match a property key of the entry; if null, only the value restriction applies
    `values` - if null or empty array, the key must merely be present; if the array has at least one element, the key value must contain one of the given values (using a like statement)
  Returns:
    a constraint that may be put into an `SQLMapFilter` as a value mapped by the ID column of the given store
  Throws:
    `IllegalArgumentException` - if the given store doesn't support the `MappingInfo` interface
  See Also:
    `PropertyEntryTableStore`, `Database.queryStoreForInterface(Class, Class)`, `MappingInfo.getIDColumn()`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads