1 19 20 package org.netbeans.modules.db.api.explorer; 21 22 import java.awt.datatransfer.DataFlavor ; 23 import org.netbeans.api.db.explorer.DatabaseConnection; 24 import org.netbeans.api.db.explorer.JDBCDriver; 25 import org.netbeans.modules.db.explorer.DbMetaDataTransferProvider; 26 27 37 public final class DatabaseMetaDataTransfer { 38 39 42 public static DataFlavor CONNECTION_FLAVOR; 43 44 47 public static DataFlavor TABLE_FLAVOR; 48 49 52 public static DataFlavor VIEW_FLAVOR; 53 54 57 public static DataFlavor COLUMN_FLAVOR; 58 59 63 private static DbMetaDataTransferProvider PROVIDER; 64 65 static { 66 try { 67 CONNECTION_FLAVOR = new DataFlavor ("application/x-java-netbeans-dbexplorer-connection;class=org.netbeans.modules.db.api.explorer.DatabaseMetaDataTransfer$Connection"); TABLE_FLAVOR = new DataFlavor ("application/x-java-netbeans-dbexplorer-table;class=org.netbeans.modules.db.api.explorer.DatabaseMetaDataTransfer$Table"); VIEW_FLAVOR = new DataFlavor ("application/x-java-netbeans-dbexplorer-view;class=org.netbeans.modules.db.api.explorer.DatabaseMetaDataTransfer$View"); COLUMN_FLAVOR = new DataFlavor ("application/x-java-netbeans-dbexplorer-column;class=org.netbeans.modules.db.api.explorer.DatabaseMetaDataTransfer$Column"); } catch (ClassNotFoundException e) { 72 throw new AssertionError (e); 73 } 74 } 75 76 80 private static synchronized DbMetaDataTransferProvider getProvider() { 81 if (PROVIDER == null) { 82 PROVIDER = new DbMetaDataTransferProviderImpl(); 83 } 84 return PROVIDER; 85 } 86 87 90 public static final class Connection { 91 92 private final DatabaseConnection dbconn; 93 private final JDBCDriver jdbcDriver; 94 95 private Connection(DatabaseConnection dbconn, JDBCDriver jdbcDriver) { 96 this.dbconn = dbconn; 97 this.jdbcDriver = jdbcDriver; 98 } 99 100 103 public DatabaseConnection getDatabaseConnection() { 104 return dbconn; 105 } 106 107 110 public JDBCDriver getJDBCDriver() { 111 return jdbcDriver; 112 } 113 114 public String toString() { 115 return "Connection[databaseConnection=" + dbconn + ",jdbcDriver=" + jdbcDriver + "]"; } 117 } 118 119 122 public static final class Table { 123 124 private final DatabaseConnection dbconn; 125 private final JDBCDriver jdbcDriver; 126 private final String tableName; 127 128 private Table(DatabaseConnection dbconn, JDBCDriver jdbcDriver, String tableName) { 129 this.dbconn = dbconn; 130 this.jdbcDriver = jdbcDriver; 131 this.tableName = tableName; 132 } 133 134 137 public DatabaseConnection getDatabaseConnection() { 138 return dbconn; 139 } 140 141 144 public JDBCDriver getJDBCDriver() { 145 return jdbcDriver; 146 } 147 148 151 public String getTableName() { 152 return tableName; 153 } 154 155 public String toString() { 156 return "Table[databaseConnection=" + dbconn + ",jdbcDriver=" + jdbcDriver + ",tableName=" + tableName + "]"; } 158 } 159 160 163 public static final class View { 164 165 private final DatabaseConnection dbconn; 166 private final JDBCDriver jdbcDriver; 167 private final String viewName; 168 169 private View(DatabaseConnection dbconn, JDBCDriver jdbcDriver, String viewName) { 170 this.dbconn = dbconn; 171 this.jdbcDriver = jdbcDriver; 172 this.viewName = viewName; 173 } 174 175 178 public DatabaseConnection getDatabaseConnection() { 179 return dbconn; 180 } 181 182 185 public JDBCDriver getJDBCDriver() { 186 return jdbcDriver; 187 } 188 189 192 public String getViewName() { 193 return viewName; 194 } 195 196 public String toString() { 197 return "View[databaseConnection=" + dbconn + ",jdbcDriver=" + jdbcDriver + ",viewName=" + viewName + "]"; } 199 } 200 201 204 public static final class Column { 205 206 private final DatabaseConnection dbconn; 207 private final JDBCDriver jdbcDriver; 208 private final String tableName; 209 private final String columnName; 210 211 private Column(DatabaseConnection dbconn, JDBCDriver jdbcDriver, String tableName, String columnName) { 212 this.dbconn = dbconn; 213 this.jdbcDriver = jdbcDriver; 214 this.tableName = tableName; 215 this.columnName = columnName; 216 } 217 218 221 public DatabaseConnection getDatabaseConnection() { 222 return dbconn; 223 } 224 225 228 public JDBCDriver getJDBCDriver() { 229 return jdbcDriver; 230 } 231 232 235 public String getTableName() { 236 return tableName; 237 } 238 239 242 public String getColumnName() { 243 return columnName; 244 } 245 246 public String toString() { 247 return "Column[databaseConnection=" + dbconn + ",jdbcDriver=" + jdbcDriver + ",tableName=" + tableName + ",columnName=" + columnName + "]"; } 249 } 250 251 255 private static final class DbMetaDataTransferProviderImpl implements DbMetaDataTransferProvider { 256 257 public DataFlavor getConnectionDataFlavor() { 258 return CONNECTION_FLAVOR; 259 } 260 261 public DataFlavor getTableDataFlavor() { 262 return TABLE_FLAVOR; 263 } 264 265 public DataFlavor getViewDataFlavor() { 266 return VIEW_FLAVOR; 267 } 268 269 270 public DataFlavor getColumnDataFlavor() { 271 return COLUMN_FLAVOR; 272 } 273 274 public Object createConnectionData(DatabaseConnection dbconn, JDBCDriver jdbcDriver) { 275 return new Connection(dbconn, jdbcDriver); 276 } 277 278 public Object createTableData(DatabaseConnection dbconn, JDBCDriver jdbcDriver, String tableName) { 279 return new Table(dbconn, jdbcDriver, tableName); 280 } 281 282 public Object createViewData(DatabaseConnection dbconn, JDBCDriver jdbcDriver, String viewName) { 283 return new View(dbconn, jdbcDriver, viewName); 284 } 285 286 public Object createColumnData(DatabaseConnection dbconn, JDBCDriver jdbcDriver, String tableName, String columnName) { 287 return new Column(dbconn, jdbcDriver, tableName, columnName); 288 } 289 } 290 } 291 | Popular Tags |