View Javadoc
1   package com.randomnoun.common.jexl.sql;
2   
3   /** An SQL column which represents a transformed value ( the value in the expression is not the stored value ).
4    * 
5    * <p>Examples of TransformedSqlColumns:
6    * <ul>
7    * <li>enum values ( 1-char in database exposed as enum strings )
8    * <li>yes/no values ( 'Y'/'N' in database exposed as booleans )
9    * <li>api-prefixed values ( 1234 in database exposed as "obj-1234" )
10   * </ul>
11   * 
12   * <p>If the transformation is reversible, we can convert some expressions to use the raw column 
13   * which can then leverage indexes on that column.
14   * 
15   */
16  public abstract class TransformedSqlColumn extends SqlColumn {
17  
18  	public TransformedSqlColumn(String name, String table, int dataType) {
19  		super(name, table, dataType);
20  	}
21  
22  	/** If true, we can perform null checks on the source column instead of the transformed value */
23  	public abstract boolean isNullPreserved();        // if nulls are preserved through transformation
24  	
25  	/** If true, we can reverse transformations for equals and not-equals comparisons */
26  	public abstract boolean isReversableEquals();     // if we can convert col == "someValue" to a simplified form
27  	
28  	/** If true, we can reverse transformations for comparison operations; we can only do this if transformations preserve ordering */
29  	public abstract boolean isReversableComparison(); // if we can convert col > "someValue" to a simplified form
30  	
31  	/** The source column */
32  	public abstract SqlColumn getSourceSqlColumn();    // name of column to use for reverse comparisons
33  	
34  	/** Reverse the transformation, i.e. convert a user-supplied value back into a database value.
35  	 * The user-supplied value must be a literal (String, Boolean, Long etc), not an expression. 
36  	 * 
37  	 * @param value literal value in expression
38  	 * 
39  	 * @value the raw value stored in the database
40  	 */
41  	public abstract Object reverseTransformLiteral(Object value) throws CannotReverseTransformationException;
42  	
43  }