1 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 ; 37 import java.sql.Types ; 38 39 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 55 public static PrimitiveBooleanType create() 56 { 57 return BOOLEAN_TYPE; 58 } 59 60 63 public String getName() 64 { 65 return "boolean"; 66 } 67 68 71 public Type getForeignType() 72 { 73 return BooleanType.create(); 74 } 75 76 79 public boolean isBoolean() 80 { 81 return true; 82 } 83 84 87 public String generateCreateColumnSQL(AmberPersistenceUnit manager, int length, int precision, int scale) 88 { 89 return manager.getCreateColumnSQL(Types.BOOLEAN, length, precision, scale); 90 } 91 92 95 public int generateLoad(JavaWriter out, String rs, 96 String indexVar, int index) 97 throws IOException 98 { 99 out.print(rs + ".getBoolean(" + indexVar + " + " + index + ")"); 100 101 return index + 1; 102 } 103 104 107 public void generateSet(JavaWriter out, String pstmt, 108 String index, String value) 109 throws IOException 110 { 111 out.println(pstmt + ".setBoolean(" + index + "++, " + value + ");"); 112 } 113 114 117 public void generateSetNull(JavaWriter out, String pstmt, 118 String index) 119 throws IOException 120 { 121 out.println(pstmt + ".setNull(" + index + "++, java.sql.Types.BIT);"); 122 } 123 124 127 public String toObject(String value) 128 { 129 return "((" + value + ") ? Boolean.TRUE : Boolean.FALSE)"; 130 } 131 132 135 public String generateCastFromObject(String value) 136 { 137 return "((Boolean) " + value + ").booleanValue()"; 138 } 139 140 143 public String generateIsNull(String value) 144 { 145 return "! (" + value + ")"; 146 } 147 } 148 | Popular Tags |