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.PreparedStatement ; 38 import java.sql.ResultSet ; 39 import java.sql.SQLException ; 40 41 44 public class StringType extends Type { 45 private static final L10N L = new L10N(StringType.class); 46 47 private static final StringType STRING_TYPE = new StringType(); 48 49 private StringType() 50 { 51 } 52 53 56 public static StringType create() 57 { 58 return STRING_TYPE; 59 } 60 61 64 public String getName() 65 { 66 return "java.lang.String"; 67 } 68 69 72 public String generateCreateColumnSQL(AmberPersistenceUnit manager, int length, int precision, int scale) 73 { 74 if (length == 0) 75 length = 255; 76 77 return "varchar(" + length + ")"; 78 } 80 81 84 public int generateLoad(JavaWriter out, String rs, 85 String indexVar, int index) 86 throws IOException 87 { 88 out.print(rs + ".getString(" + indexVar + " + " + index + ")"); 89 90 return index + 1; 91 } 92 93 96 public void generateSet(JavaWriter out, String pstmt, 97 String index, String value) 98 throws IOException 99 { 100 if (pstmt.startsWith("query")) 101 out.println(pstmt + ".setString(" + index + "++, " + value + ");"); 102 else 103 out.println("__caucho_setInternalString(" + pstmt + ", " + index + "++, " + value + ");"); 104 } 105 106 109 public void setParameter(PreparedStatement pstmt, int index, Object value) 110 throws SQLException 111 { 112 if (value == null) { 113 pstmt.setString(index, null); 116 } 117 else if (value instanceof String ) 118 pstmt.setString(index, (String ) value); 119 else pstmt.setObject(index, value); 121 } 122 123 126 public Object getObject(ResultSet rs, int index) 127 throws SQLException 128 { 129 return rs.getString(index); 130 } 131 } 132 | Popular Tags |