1 10 11 package com.triactive.jdo.store; 12 13 import java.sql.Connection ; 14 import java.sql.DatabaseMetaData ; 15 import java.sql.ResultSet ; 16 import java.sql.SQLException ; 17 import java.sql.Types ; 18 import javax.jdo.JDODataStoreException; 19 import javax.jdo.JDOFatalDataStoreException; 20 21 28 29 public class PostgreSQLAdapter extends DatabaseAdapter 30 { 31 public PostgreSQLAdapter(DatabaseMetaData metadata) 32 { 33 super(metadata); 34 35 if (databaseMajorVersion < 7) 36 throw new JDODataStoreException("PostgreSQL version is " + databaseMajorVersion + '.' + databaseMinorVersion + ", 7.0 or later required"); 37 else if (databaseMajorVersion == 7) 38 { 39 if (databaseMinorVersion <= 2) 40 { 41 47 --maxTableNameLength; 48 --maxConstraintNameLength; 49 --maxIndexNameLength; 50 } 51 } 52 } 53 54 public String getVendorID() 55 { 56 return "postgresql"; 57 } 58 59 public SQLState getSQLState(SQLException se) 60 { 61 String state = se.getSQLState(); 62 63 if (state == null) 64 return null; 65 66 try 67 { 68 return new PostgreSQLSQLState(state); 69 } 70 catch (IllegalArgumentException e) 71 { 72 return null; 73 } 74 } 75 76 public TableExpression newTableExpression(QueryStatement qs, Table table, SQLIdentifier rangeVar) 77 { 78 return new TableExprAsSubquery(qs, table, rangeVar); 79 } 80 81 public TypeInfo newTypeInfo(ResultSet rs) 82 { 83 TypeInfo ti = new PostgreSQLTypeInfo(rs); 84 85 92 93 switch (ti.dataType) 94 { 95 case Types.BIT: 96 if (!ti.typeName.equalsIgnoreCase("bool")) 97 return null; 98 break; 99 case Types.CHAR: 100 if (!ti.typeName.equalsIgnoreCase("char")) 101 return null; 102 break; 103 case Types.SMALLINT: 104 if (!ti.typeName.equalsIgnoreCase("int2")) 105 return null; 106 break; 107 case Types.INTEGER: 108 if (!ti.typeName.equalsIgnoreCase("int4")) 109 return null; 110 break; 111 case Types.BIGINT: 112 if (!ti.typeName.equalsIgnoreCase("int8")) 113 return null; 114 break; 115 case Types.REAL: 116 if (!ti.typeName.equalsIgnoreCase("float4")) 117 return null; 118 break; 119 case Types.DOUBLE: 120 if (!ti.typeName.equalsIgnoreCase("float8")) 121 return null; 122 break; 123 case Types.NUMERIC: 124 if (!ti.typeName.equalsIgnoreCase("numeric")) 125 return null; 126 break; 127 case Types.DATE: 128 if (!ti.typeName.equalsIgnoreCase("date")) 129 return null; 130 break; 131 case Types.TIME: 132 if (!ti.typeName.equalsIgnoreCase("time")) 133 return null; 134 break; 135 case Types.TIMESTAMP: 136 if (!ti.typeName.equalsIgnoreCase("timestamptz")) 137 return null; 138 break; 139 case Types.VARCHAR: 140 if (!ti.typeName.equalsIgnoreCase("varchar")) 141 return null; 142 break; 143 case Types.OTHER: 144 145 return null; 146 } 147 148 return ti; 149 } 150 151 public ColumnInfo newColumnInfo(ResultSet rs) 152 { 153 return new PostgreSQLColumnInfo(rs); 154 } 155 156 public ForeignKeyInfo newForeignKeyInfo(ResultSet rs) 157 { 158 return new PostgreSQLForeignKeyInfo(rs); 159 } 160 161 public boolean supportsAlterTableDropConstraint() 162 { 163 return false; 164 } 165 166 public String getDropTableStatement(BaseTable table) 167 { 168 169 if (databaseMajorVersion == 7 && databaseMinorVersion < 3) 170 return "DROP TABLE " + table.getName(); 171 else 172 return "DROP TABLE " + table.getName() + " CASCADE"; 173 } 174 } 175 | Popular Tags |