1 28 29 package com.caucho.amber.type; 30 31 import com.caucho.amber.manager.AmberPersistenceUnit; 32 import com.caucho.bytecode.JClass; 33 import com.caucho.java.JavaWriter; 34 import com.caucho.util.L10N; 35 36 import java.io.IOException ; 37 import java.sql.ResultSet ; 38 import java.sql.SQLException ; 39 import java.sql.Types ; 40 41 44 public class SqlTimeType extends Type { 45 private static final L10N L = new L10N(SqlTimeType.class); 46 47 private static final SqlTimeType SQL_TIME_TYPE = new SqlTimeType(); 48 49 private SqlTimeType() 50 { 51 } 52 53 56 public static SqlTimeType create() 57 { 58 return SQL_TIME_TYPE; 59 } 60 61 64 public String getName() 65 { 66 return "java.sql.Time"; 67 } 68 69 72 @Override 73 public boolean isAssignableTo(JClass javaType) 74 { 75 return javaType.isAssignableFrom(java.sql.Time .class); 76 } 77 78 81 public String generateCreateColumnSQL(AmberPersistenceUnit manager, int length, int precision, int scale) 82 { 83 return manager.getCreateColumnSQL(Types.TIME, length, precision, scale); 84 } 85 86 89 public int generateLoad(JavaWriter out, String rs, 90 String indexVar, int index) 91 throws IOException 92 { 93 out.print(rs + ".getTime(" + indexVar + " + " + index + ")"); 94 95 return index + 1; 96 } 97 98 101 public void generateSet(JavaWriter out, String pstmt, 102 String index, String value) 103 throws IOException 104 { 105 out.println("if (" + value + " == null)"); 106 out.println(" " + pstmt + ".setNull(" + index + "++, java.sql.Types.TIME);"); 107 out.println("else"); 108 out.println(" " + pstmt + ".setTime(" + index + "++, " + value + ");"); 109 } 110 111 114 public Object getObject(ResultSet rs, int index) 115 throws SQLException 116 { 117 return rs.getTime(index); 118 } 119 } 120 | Popular Tags |