34
34
import java .util .Map ;
35
35
import java .util .Set ;
36
36
37
- import org .jboss .logging .Logger ;
38
-
39
37
import org .hibernate .HibernateException ;
38
+ import org .hibernate .cfg .AvailableSettings ;
39
+ import org .hibernate .cfg .Configuration ;
40
40
import org .hibernate .dialect .Dialect ;
41
41
import org .hibernate .engine .jdbc .spi .SqlExceptionHelper ;
42
42
import org .hibernate .exception .spi .SQLExceptionConverter ;
43
43
import org .hibernate .internal .CoreMessageLogger ;
44
44
import org .hibernate .internal .util .StringHelper ;
45
+ import org .hibernate .internal .util .config .ConfigurationHelper ;
45
46
import org .hibernate .mapping .Table ;
47
+ import org .jboss .logging .Logger ;
46
48
47
49
/**
48
50
* JDBC database metadata
49
51
* @author Christoph Sturm, Teodor Danciu
50
52
*/
53
+ /**
54
+ * @author Brett Meyer
55
+ */
51
56
public class DatabaseMetadata {
52
57
53
58
private static final CoreMessageLogger LOG = Logger .getMessageLogger (CoreMessageLogger .class , DatabaseMetaData .class .getName ());
@@ -59,19 +64,42 @@ public class DatabaseMetadata {
59
64
private DatabaseMetaData meta ;
60
65
private SQLExceptionConverter sqlExceptionConverter ;
61
66
67
+ private final String [] types ;
68
+ /**
69
+ * @deprecated Use {@link #DatabaseMetadata(Connection, Dialect, Configuration)} instead
70
+ */
71
+ @ Deprecated
62
72
public DatabaseMetadata (Connection connection , Dialect dialect ) throws SQLException {
63
- this (connection , dialect , true );
73
+ this (connection , dialect , null , true );
64
74
}
65
75
76
+ /**
77
+ * @deprecated Use {@link #DatabaseMetadata(Connection, Dialect, Configuration, boolean)} instead
78
+ */
79
+ @ Deprecated
66
80
public DatabaseMetadata (Connection connection , Dialect dialect , boolean extras ) throws SQLException {
81
+ this (connection , dialect , null , extras );
82
+ }
83
+
84
+ public DatabaseMetadata (Connection connection , Dialect dialect , Configuration config ) throws SQLException {
85
+ this (connection , dialect , config , true );
86
+ }
87
+
88
+ public DatabaseMetadata (Connection connection , Dialect dialect , Configuration config , boolean extras )
89
+ throws SQLException {
67
90
sqlExceptionConverter = dialect .buildSQLExceptionConverter ();
68
91
meta = connection .getMetaData ();
69
92
this .extras = extras ;
70
- initSequences (connection , dialect );
93
+ initSequences ( connection , dialect );
94
+ if ( config != null
95
+ && ConfigurationHelper .getBoolean ( AvailableSettings .ENABLE_SYNONYMS , config .getProperties (), false ) ) {
96
+ types = new String [] { "TABLE" , "VIEW" , "SYNONYM" };
97
+ }
98
+ else {
99
+ types = new String [] { "TABLE" , "VIEW" };
100
+ }
71
101
}
72
102
73
- private static final String [] TYPES = {"TABLE" , "VIEW" , "SYNONYM" };
74
-
75
103
public TableMetadata getTableMetadata (String name , String schema , String catalog , boolean isQuoted ) throws HibernateException {
76
104
77
105
Object identifier = identifier (catalog , schema , name );
@@ -85,14 +113,14 @@ public TableMetadata getTableMetadata(String name, String schema, String catalog
85
113
ResultSet rs = null ;
86
114
try {
87
115
if ( (isQuoted && meta .storesMixedCaseQuotedIdentifiers ())) {
88
- rs = meta .getTables (catalog , schema , name , TYPES );
116
+ rs = meta .getTables (catalog , schema , name , types );
89
117
} else if ( (isQuoted && meta .storesUpperCaseQuotedIdentifiers ())
90
118
|| (!isQuoted && meta .storesUpperCaseIdentifiers () )) {
91
119
rs = meta .getTables (
92
120
StringHelper .toUpperCase (catalog ),
93
121
StringHelper .toUpperCase (schema ),
94
122
StringHelper .toUpperCase (name ),
95
- TYPES
123
+ types
96
124
);
97
125
}
98
126
else if ( (isQuoted && meta .storesLowerCaseQuotedIdentifiers ())
@@ -101,11 +129,11 @@ else if ( (isQuoted && meta.storesLowerCaseQuotedIdentifiers())
101
129
StringHelper .toLowerCase ( catalog ),
102
130
StringHelper .toLowerCase (schema ),
103
131
StringHelper .toLowerCase (name ),
104
- TYPES
132
+ types
105
133
);
106
134
}
107
135
else {
108
- rs = meta .getTables (catalog , schema , name , TYPES );
136
+ rs = meta .getTables (catalog , schema , name , types );
109
137
}
110
138
111
139
while ( rs .next () ) {
0 commit comments