|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbiz.c24.io.api.data.DefaultValidationRule
biz.c24.io.api.data.DatabaseLookupValidationRule
public class DatabaseLookupValidationRule
A validator implementation for on-the-fly validation against a database without loading all the data into memory. A select statement is issued to validate each value.
The select query should use '%' (percentage sign) as a place holder for the value that needs validation.
e.g. SELECT * FROM MyCodeTable WHERE MyCodeColumn = '%'
If the query returns a result, then the validation passes.
When used in production it is imperative to handle the connection management / pooling outside of this class. This can
be done either by setting the property 'hibernate.connection.datasource' in the rule definition or via the
useSession(org.hibernate.classic.Session)
method.
NOTE: Please ensure that the Hibernate & required 3rd party libraries added to your classpath (hibernate3.jar etc.).
For more information about the Hibernate please visit:
http://www.hibernate.org/
Constructor Summary | |
---|---|
DatabaseLookupValidationRule(String sqlQuery,
Properties properties)
Creates a new lookup validator which will use the given properties and execute the supplied SQL query. |
Method Summary | |
---|---|
Properties |
getProperties()
Returns the database configuration properties (not used if an external session is specified). |
String |
getSqlQuery()
Returns the SQL query being executed. |
void |
setProperties(Properties properties)
Sets the database configuration properties. |
void |
setSqlQuery(String sqlQuery)
Sets the SQL query to be executed. |
String |
toString()
|
void |
useSession(org.hibernate.classic.Session session)
Specifies an external Hibernate Session to be used to connect to the database. |
boolean |
validate(Object object,
DataComponent component,
ComplexDataObject context,
ValidationManager manager)
Validate the given object. |
Methods inherited from class biz.c24.io.api.data.DefaultValidationRule |
---|
addDependentPredicateCode, getAnnotation, getContextForPredicateChecking, getDependentPredicateCode, getDependentPredicateCodeCount, getErrorCode, getName, getPredicateCode, getSeverity, removeDependentPredicateCode, setAnnotation, setErrorCode, setName, setPredicateCode, setSeverity |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DatabaseLookupValidationRule(String sqlQuery, Properties properties)
sqlQuery
- the query that tests whether the value is valid.properties
- The configuration properties containing database connection details (may be null).Method Detail |
---|
public void useSession(org.hibernate.classic.Session session)
This method should be used to control connection pooling and thereby prevent the default behaviour of reconnecting to the database for every validation.
session
- The session to be used, or null
to use a new session for each validation.public boolean validate(Object object, DataComponent component, ComplexDataObject context, ValidationManager manager) throws ValidationException
Validator
validate
in interface Validator
validate
in class DefaultValidationRule
object
- The object to be validated - commonly a String, Integer, Double, Date etc.component
- The Element
or Attribute
inside context
which defines object
.context
- The parent of object
- could be null
.manager
- The validation manager which is performing this validation.
ValidationException
- If the object is not valid and the validation maanger is operating in exception mode.public String getSqlQuery()
The '%' symbol is replaced with the data to be validated.
public void setSqlQuery(String sqlQuery)
sqlQuery
- The SQL query.public Properties getProperties()
public void setProperties(Properties properties)
properties
- The properties.public String toString()
toString
in class DefaultValidationRule
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |