KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > mapping > Formula


1 //$Id: Formula.java,v 1.9 2005/07/19 18:28:35 maxcsaucdk Exp $
2
package org.hibernate.mapping;
3
4 import java.io.Serializable JavaDoc;
5
6 import org.hibernate.dialect.Dialect;
7 import org.hibernate.sql.Template;
8
9 /**
10  * A formula is a derived column value
11  * @author Gavin King
12  */

13 public class Formula implements Selectable, Serializable JavaDoc {
14     private static int formulaUniqueInteger=0;
15
16     private String JavaDoc formula;
17     private int uniqueInteger;
18
19     public Formula() {
20         uniqueInteger = formulaUniqueInteger++;
21     }
22
23     public String JavaDoc getTemplate(Dialect dialect) {
24         return Template.renderWhereStringTemplate(formula, dialect);
25     }
26     public String JavaDoc getText(Dialect dialect) {
27         return getFormula();
28     }
29     public String JavaDoc getText() {
30         return getFormula();
31     }
32     public String JavaDoc getAlias(Dialect dialect) {
33         return "formula" + Integer.toString(uniqueInteger) + '_';
34     }
35     public String JavaDoc getAlias(Dialect dialect, Table table) {
36         return getAlias(dialect);
37     }
38     public String JavaDoc getFormula() {
39         return formula;
40     }
41     public void setFormula(String JavaDoc string) {
42         formula = string;
43     }
44     public boolean isFormula() {
45         return true;
46     }
47
48     public String JavaDoc toString() {
49         return this.getClass().getName() + "( " + formula + " )";
50     }
51 }
52
Popular Tags