blob: 4097b08014514641d348008187a4225df6d4d543 (
plain) (
blame)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*******************************************************************************
* Copyright (c) 2007 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0, which accompanies this distribution and is available at
* http://www.eclipse.org/legal/epl-v10.html.
*
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.db.internal;
import java.text.Collator;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject;
import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObjectListener;
/**
* Wrap a DTP Catalogs
*/
final class Catalog extends DTPWrapper {
private final Database database;
private final org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog;
private ICatalogObjectListener catalogListener; //TODO listen for change
// ********** constructors **********
Catalog( Database database, org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog) {
super();
this.database = database;
this.dtpCatalog = dtpCatalog;
}
// ********** behavior **********
protected boolean connectionIsOnline() {
return this.database.connectionIsOnline();
}
private ICatalogObjectListener buildCatalogListener() {
return new ICatalogObjectListener() {
public void notifyChanged( final ICatalogObject catalog, final int eventType) {
if( catalog == Catalog.this.dtpCatalog) {
// Catalog.this.refresh();
// Catalog.this.database.catalogChanged( Catalog.this, eventType);
}
}
};
}
protected void dispose() {
// this.removeCatalogObjectListener(( ICatalogObject) this.dtpCatalog, this.catalogListener);
}
boolean wraps( org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog) {
return this.dtpCatalog == dtpCatalog;
}
// ********** queries **********
public String getName() {
return this.dtpCatalog.getName();
}
boolean isCaseSensitive() {
return this.database.isCaseSensitive();
}
Column column( org.eclipse.datatools.modelbase.sql.tables.Column dtpColumn) {
return this.database.column(dtpColumn);
}
// ***** schemata
synchronized Set buildSchemata() {
Collection dtpSchemata = this.dtpCatalog.getSchemas();
Set result = new HashSet( dtpSchemata.size());
for( Iterator i = dtpSchemata.iterator(); i.hasNext(); ) {
result.add( this.wrap(( org.eclipse.datatools.modelbase.sql.schema.Schema)i.next()));
}
return result;
}
private Schema wrap( org.eclipse.datatools.modelbase.sql.schema.Schema schema) {
return new Schema( this.database, schema);
}
// ********** Comparable implementation **********
public int compareTo( Object o) {
return Collator.getInstance().compare( this.getName(), (( Catalog)o).getName());
}
}
|