1 56 57 package org.objectstyle.cayenne.dba.derby; 58 59 import org.objectstyle.cayenne.CayenneRuntimeException; 60 import org.objectstyle.cayenne.access.trans.QualifierTranslator; 61 import org.objectstyle.cayenne.access.trans.QueryAssembler; 62 import org.objectstyle.cayenne.access.trans.TrimmingQualifierTranslator; 63 import org.objectstyle.cayenne.access.types.ByteType; 64 import org.objectstyle.cayenne.access.types.CharType; 65 import org.objectstyle.cayenne.access.types.ExtendedTypeMap; 66 import org.objectstyle.cayenne.access.types.ShortType; 67 import org.objectstyle.cayenne.dba.JdbcAdapter; 68 import org.objectstyle.cayenne.dba.TypesMapping; 69 import org.objectstyle.cayenne.map.DbAttribute; 70 import org.objectstyle.cayenne.map.DbEntity; 71 72 86 public class DerbyAdapter extends JdbcAdapter { 87 88 92 protected void configureExtendedTypes(ExtendedTypeMap map) { 93 super.configureExtendedTypes(map); 94 95 map.registerType(new CharType(true, false)); 97 98 map.registerType(new ShortType(true)); 100 map.registerType(new ByteType(true)); 101 } 102 103 110 protected void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) { 111 String [] types = externalTypesForJdbcType(column.getType()); 112 if (types == null || types.length == 0) { 113 String entityName = column.getEntity() != null ? ((DbEntity) column.getEntity()) 114 .getFullyQualifiedName() : "<null>"; 115 throw new CayenneRuntimeException("Undefined type for attribute '" + entityName + "." 116 + column.getName() + "': " + column.getType()); 117 } 118 119 String type = types[0]; 120 sqlBuffer.append(column.getName()).append(' ').append(type); 121 122 if (TypesMapping.supportsLength(column.getType())) { 124 int len = column.getMaxLength(); 125 int prec = TypesMapping.isDecimal(column.getType()) ? column.getPrecision() : -1; 126 127 if (prec > len) { 129 prec = -1; 130 } 131 132 if (len > 0) { 133 sqlBuffer.append('(').append(len); 134 135 if (prec >= 0) { 136 sqlBuffer.append(", ").append(prec); 137 } 138 139 sqlBuffer.append(')'); 140 } 141 } 142 143 if (column.isMandatory()) { 145 sqlBuffer.append(" NOT NULL"); 146 } 147 } 148 149 152 public QualifierTranslator getQualifierTranslator(QueryAssembler queryAssembler) { 153 return new TrimmingQualifierTranslator(queryAssembler, "RTRIM"); 154 } 155 156 } | Popular Tags |