| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
package org.melati.poem.dbms; |
| 46 | |
|
| 47 | |
import java.sql.SQLException; |
| 48 | |
import java.sql.DatabaseMetaData; |
| 49 | |
import java.sql.ResultSet; |
| 50 | |
|
| 51 | |
import org.melati.poem.PoemType; |
| 52 | |
import org.melati.poem.SQLPoemType; |
| 53 | |
import org.melati.poem.DoublePoemType; |
| 54 | |
import org.melati.poem.BinaryPoemType; |
| 55 | |
import org.melati.poem.StringPoemType; |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
public class Mckoi extends AnsiStandard { |
| 61 | |
|
| 62 | |
|
| 63 | |
public static final int mckoiTextHack = 2147483647; |
| 64 | |
|
| 65 | |
|
| 66 | |
public static final int mckoiBinaryHack = 2147483647; |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | 1 | public Mckoi() { |
| 71 | 1 | setDriverClassName("com.mckoi.JDBCDriver"); |
| 72 | 1 | } |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
public String getBinarySqlDefinition(int size) { |
| 79 | |
|
| 80 | 1 | return "LONGVARBINARY"; |
| 81 | |
} |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
public String getStringSqlDefinition(int size) throws SQLException { |
| 88 | 2 | if (size < 0) { |
| 89 | 1 | return "TEXT"; |
| 90 | |
} |
| 91 | 1 | return super.getStringSqlDefinition(size); |
| 92 | |
} |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
public String getQuotedName (String name) { |
| 99 | |
|
| 100 | 26 | if (name.equals("unique")) return super.getQuotedName(name); |
| 101 | 26 | if (name.equals("from")) return super.getQuotedName(name); |
| 102 | 26 | return name; |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public String getSqlDefinition(String sqlTypeName) { |
| 109 | 6 | if (sqlTypeName.equals("INT")) { |
| 110 | 1 | return ("INTEGER"); |
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | 5 | return super.getSqlDefinition(sqlTypeName); |
| 118 | |
} |
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
public <S,O>PoemType<O> canRepresent(PoemType<S> storage, PoemType<O> type) { |
| 125 | 17 | if (storage instanceof StringPoemType && |
| 126 | |
type instanceof StringPoemType) { |
| 127 | |
|
| 128 | 3 | if (((StringPoemType)storage).getSize() == mckoiTextHack && |
| 129 | 1 | ((StringPoemType)type).getSize() == -1 |
| 130 | 1 | && !(!storage.getNullable() && type.getNullable()) |
| 131 | |
) { |
| 132 | 1 | return type; |
| 133 | |
} else { |
| 134 | 2 | return storage.canRepresent(type); |
| 135 | |
} |
| 136 | 14 | } else if (storage instanceof BinaryPoemType && |
| 137 | |
type instanceof BinaryPoemType |
| 138 | 4 | && !(!storage.getNullable() && type.getNullable()) |
| 139 | |
) { |
| 140 | 3 | if (((BinaryPoemType)storage).getSize() == mckoiBinaryHack && |
| 141 | 2 | ((BinaryPoemType)type).getSize() == -1) { |
| 142 | 1 | return type; |
| 143 | |
} else { |
| 144 | 2 | return storage.canRepresent(type); |
| 145 | |
} |
| 146 | |
} else { |
| 147 | 11 | return storage.canRepresent(type); |
| 148 | |
} |
| 149 | |
} |
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
public SQLPoemType<?> defaultPoemTypeOfColumnMetaData(ResultSet md) |
| 156 | |
throws SQLException { |
| 157 | |
|
| 158 | 0 | if(md.getString("TYPE_NAME").equals("NUMERIC")) |
| 159 | 0 | return new DoublePoemType(md.getInt("NULLABLE")== |
| 160 | |
DatabaseMetaData.columnNullable); |
| 161 | |
else |
| 162 | 0 | return super.defaultPoemTypeOfColumnMetaData(md); |
| 163 | |
} |
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
public String givesCapabilitySQL(Integer userTroid, String capabilityExpr) { |
| 171 | 1 | return |
| 172 | 1 | "SELECT " + getQuotedName("groupmembership") + ".* " + |
| 173 | 1 | "FROM " + getQuotedName("groupmembership") + " LEFT JOIN " + |
| 174 | 1 | getQuotedName("groupcapability") + |
| 175 | 1 | " ON " + getQuotedName("groupmembership") + "." + getQuotedName("group") + |
| 176 | 1 | " = " + getQuotedName("groupcapability") + "." + getQuotedName("group") + |
| 177 | 1 | " WHERE " + getQuotedName("user") + " = " + userTroid + " " + |
| 178 | 1 | "AND " + getQuotedName("groupcapability") + "." + getQuotedName("group") + |
| 179 | |
" IS NOT NULL " + |
| 180 | 1 | "AND " + getQuotedName("capability") + " = " + capabilityExpr; |
| 181 | |
} |
| 182 | |
|
| 183 | |
} |
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|