01: package net.sourceforge.squirrel_sql.plugins.hibernate.mapping;
02:
03: import net.sourceforge.squirrel_sql.plugins.hibernate.HibernateConnection;
04: import net.sourceforge.squirrel_sql.plugins.hibernate.configuration.HibernateConfiguration;
05: import net.sourceforge.squirrel_sql.fw.util.StringManager;
06: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
07: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
08: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
09:
10: import java.util.Hashtable;
11: import java.sql.Connection;
12: import java.sql.DatabaseMetaData;
13:
14: public class MappingRoot extends Object {
15:
16: private static ILogger s_log = LoggerController
17: .createLogger(MappingRoot.class);
18:
19: private static final StringManager s_stringMgr = StringManagerFactory
20: .getStringManager(MappingRoot.class);
21:
22: //i18n[MappingRoot.toString=Mapping]
23: private String _toString = s_stringMgr
24: .getString("MappingRoot.toString");
25:
26: private Hashtable<String, String> _properties = new Hashtable<String, String>();
27:
28: public String toString() {
29: return _toString;
30: }
31:
32: public Hashtable<String, String> getMappingProperties() {
33: return _properties;
34: }
35:
36: public void clear() {
37: _properties = new Hashtable<String, String>();
38: }
39:
40: public void init(HibernateConnection con, HibernateConfiguration cfg) {
41: clear();
42:
43: //i18n[MappingRoot.cfgName=Configuration]
44: _properties.put(s_stringMgr.getString("MappingRoot.cfgName"),
45: cfg.getName());
46:
47: //i18n[MappingRoot.classpath=Classpath]
48: _properties.put(s_stringMgr.getString("MappingRoot.classpath"),
49: cfg.classpathAsString());
50:
51: try {
52: // //i18n[MappingRoot.driverClassName=JDBC Driver class name (Hibernate)]
53: // _properties.put(s_stringMgr.getString("MappingRoot.driverClassName"), con.getDriverClassName());
54:
55: Connection sqlCon = con.getSqlConnection();
56: DatabaseMetaData md = sqlCon.getMetaData();
57:
58: //i18n[MappingRoot.url=JDBC Url (Hibernate)]
59: _properties.put(s_stringMgr.getString("MappingRoot.url"),
60: md.getURL());
61:
62: //i18n[MappingRoot.user=JDBC User (Hibernate)]
63: _properties.put(s_stringMgr.getString("MappingRoot.user"),
64: md.getUserName());
65:
66: //i18n[MappingRoot.driverName=JDBC driver name (Hibernate)]
67: _properties.put(s_stringMgr
68: .getString("MappingRoot.driverName"), md
69: .getDriverName());
70:
71: //i18n[MappingRoot.driverVersion=JDBC driver version (Hibernate)]
72: _properties.put(s_stringMgr
73: .getString("MappingRoot.driverVersion"), md
74: .getDriverVersion());
75: } catch (Exception e) {
76: //i18n[MappingRoot.connectionErr=Error getting SQL connection data from Hibernate:]
77: s_log.error(s_stringMgr
78: .getString("MappingRoot.connectionErr"), e);
79: }
80: }
81: }
|