1 56 package org.objectstyle.cayenne.dba.mysql; 57 58 import java.sql.Types ; 59 60 import org.objectstyle.cayenne.CayenneRuntimeException; 61 import org.objectstyle.cayenne.access.types.CharType; 62 import org.objectstyle.cayenne.access.types.ExtendedTypeMap; 63 import org.objectstyle.cayenne.dba.JdbcAdapter; 64 import org.objectstyle.cayenne.dba.PkGenerator; 65 import org.objectstyle.cayenne.map.DbAttribute; 66 import org.objectstyle.cayenne.map.DbRelationship; 67 68 83 public class MySQLAdapter extends JdbcAdapter { 84 85 public MySQLAdapter() { 86 this.setSupportsFkConstraints(false); 88 this.setSupportsUniqueConstraints(true); 89 this.setSupportsGeneratedKeys(true); 90 } 91 92 96 protected void configureExtendedTypes(ExtendedTypeMap map) { 97 super.configureExtendedTypes(map); 98 99 map.registerType(new CharType(false, false)); 104 } 105 106 public DbAttribute buildAttribute( 107 String name, 108 String typeName, 109 int type, 110 int size, 111 int precision, 112 boolean allowNulls) { 113 114 if (type == Types.OTHER) { 117 if ("longblob".equalsIgnoreCase(typeName)) { 118 type = Types.BLOB; 119 } 120 else if ("mediumblob".equalsIgnoreCase(typeName)) { 121 type = Types.BLOB; 122 } 123 else if ("blob".equalsIgnoreCase(typeName)) { 124 type = Types.BLOB; 125 } 126 else if ("tinyblob".equalsIgnoreCase(typeName)) { 127 type = Types.VARBINARY; 128 } 129 else if ("longtext".equalsIgnoreCase(typeName)) { 130 type = Types.CLOB; 131 } 132 else if ("mediumtext".equalsIgnoreCase(typeName)) { 133 type = Types.CLOB; 134 } 135 else if ("text".equalsIgnoreCase(typeName)) { 136 type = Types.CLOB; 137 } 138 else if ("tinytext".equalsIgnoreCase(typeName)) { 139 type = Types.VARCHAR; 140 } 141 } 142 143 return super.buildAttribute(name, typeName, type, size, precision, allowNulls); 144 } 145 146 147 public String createFkConstraint(DbRelationship rel) { 148 throw new CayenneRuntimeException("FK constraints are not supported."); 149 } 150 151 155 public String tableTypeForView() { 156 return null; 157 } 158 159 164 protected PkGenerator createPkGenerator() { 165 return new MySQLPkGenerator(); 166 } 167 168 protected void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) { 169 super.createTableAppendColumn(sqlBuffer, column); 170 171 if(column.isGenerated()) { 172 sqlBuffer.append(" AUTO_INCREMENT"); 173 } 174 } 175 } 176 | Popular Tags |