KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > type > PrimitiveBooleanType


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.amber.type;
31
32 import com.caucho.amber.manager.AmberPersistenceUnit;
33 import com.caucho.java.JavaWriter;
34 import com.caucho.util.L10N;
35
36 import java.io.IOException JavaDoc;
37 import java.sql.Types JavaDoc;
38
39 /**
40  * The type of a property.
41  */

42 public class PrimitiveBooleanType extends PrimitiveType {
43   private static final L10N L = new L10N(PrimitiveBooleanType.class);
44
45   private static final PrimitiveBooleanType BOOLEAN_TYPE =
46     new PrimitiveBooleanType();
47
48   private PrimitiveBooleanType()
49   {
50   }
51
52   /**
53    * Returns the boolean type.
54    */

55   public static PrimitiveBooleanType create()
56   {
57     return BOOLEAN_TYPE;
58   }
59
60   /**
61    * Returns the type name.
62    */

63   public String JavaDoc getName()
64   {
65     return "boolean";
66   }
67
68   /**
69    * Returns the foreign key type.
70    */

71   public Type getForeignType()
72   {
73     return BooleanType.create();
74   }
75
76   /**
77    * Returns true for a boolean type.
78    */

79   public boolean isBoolean()
80   {
81     return true;
82   }
83
84   /**
85    * Generates the type for the table.
86    */

87   public String JavaDoc generateCreateColumnSQL(AmberPersistenceUnit manager, int length, int precision, int scale)
88   {
89     return manager.getCreateColumnSQL(Types.BOOLEAN, length, precision, scale);
90   }
91
92   /**
93    * Generates a string to load the property.
94    */

95   public int generateLoad(JavaWriter out, String JavaDoc rs,
96               String JavaDoc indexVar, int index)
97     throws IOException JavaDoc
98   {
99     out.print(rs + ".getBoolean(" + indexVar + " + " + index + ")");
100
101     return index + 1;
102   }
103
104   /**
105    * Generates a string to set the property.
106    */

107   public void generateSet(JavaWriter out, String JavaDoc pstmt,
108               String JavaDoc index, String JavaDoc value)
109     throws IOException JavaDoc
110   {
111     out.println(pstmt + ".setBoolean(" + index + "++, " + value + ");");
112   }
113
114   /**
115    * Generates a string to set the property.
116    */

117   public void generateSetNull(JavaWriter out, String JavaDoc pstmt,
118                   String JavaDoc index)
119     throws IOException JavaDoc
120   {
121     out.println(pstmt + ".setNull(" + index + "++, java.sql.Types.BIT);");
122   }
123
124   /**
125    * Converts to an object.
126    */

127   public String JavaDoc toObject(String JavaDoc value)
128   {
129     return "((" + value + ") ? Boolean.TRUE : Boolean.FALSE)";
130   }
131   
132   /**
133    * Converts the value.
134    */

135   public String JavaDoc generateCastFromObject(String JavaDoc value)
136   {
137     return "((Boolean) " + value + ").booleanValue()";
138   }
139
140   /**
141    * Returns a test for null.
142    */

143   public String JavaDoc generateIsNull(String JavaDoc value)
144   {
145     return "! (" + value + ")";
146   }
147 }
148
Popular Tags