Changeset 982 for AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/connection/JdbcDatastore.java
- Timestamp:
- 08/28/10 21:55:08 (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/connection/JdbcDatastore.java
r947 r982 5 5 import java.sql.DriverManager; 6 6 import java.sql.SQLException; 7 8 import javax.naming.InitialContext; 9 import javax.sql.DataSource; 10 11 import org.eobjects.analyzer.util.StringUtils; 7 12 8 13 import dk.eobjects.metamodel.DataContext; … … 14 19 15 20 private String _name; 16 private String _ url;21 private String _jdbcUrl; 17 22 private String _username; 18 23 private String _password; 19 24 private String _driverClass; 25 private String _datasourceJndiUrl; 20 26 private transient DataContextProvider _dataContextProvider; 21 27 private transient Connection _connection; 22 28 23 public JdbcDatastore(String name, String url, String driverClass) {29 public JdbcDatastore(String name, String jdbcUrl, String driverClass) { 24 30 _name = name; 25 _ url = url;31 _jdbcUrl = jdbcUrl; 26 32 _driverClass = driverClass; 27 33 } … … 34 40 } 35 41 36 public String getUrl() { 37 return _url; 42 public JdbcDatastore(String name, String datasourceJndiUrl) { 43 _name = name; 44 _datasourceJndiUrl = datasourceJndiUrl; 45 38 46 } 39 47 40 public void setUrl(String url) {41 _url = url;48 public String getJdbcUrl() { 49 return _jdbcUrl; 42 50 } 43 51 … … 46 54 } 47 55 48 public void setUsername(String username) {49 synchronized (this) {50 _username = username;51 }52 }53 54 56 public String getPassword() { 55 57 return _password; 56 58 } 57 59 58 public void setPassword(String password) {59 synchronized (this) {60 _password = password;61 }62 }63 64 60 public String getDriverClass() { 65 61 return _driverClass; 66 }67 68 public void setDriverClass(String driverClass) {69 _driverClass = driverClass;70 62 } 71 63 … … 75 67 } 76 68 77 public void setName(String name) {78 _name = name;69 public String getDatasourceJndiUrl() { 70 return _datasourceJndiUrl; 79 71 } 80 72 … … 84 76 synchronized (this) { 85 77 if (_dataContextProvider == null) { 86 try { 87 Class.forName(_driverClass); 88 } catch (ClassNotFoundException e) { 89 throw new IllegalStateException( 90 "Could not initialize JDBC driver", e); 78 if (StringUtils.isNullOrEmpty(_datasourceJndiUrl)) { 79 try { 80 Class.forName(_driverClass); 81 } catch (ClassNotFoundException e) { 82 throw new IllegalStateException( 83 "Could not initialize JDBC driver", e); 84 } 85 try { 86 if (_username == null && _password == null) { 87 _connection = DriverManager 88 .getConnection(_jdbcUrl); 89 } else { 90 _connection = DriverManager.getConnection( 91 _jdbcUrl, _username, _password); 92 } 93 } catch (SQLException e) { 94 throw new IllegalStateException( 95 "Could not establish JDBC connection", e); 96 } 97 98 DataContext dataContext = DataContextFactory 99 .createJdbcDataContext(_connection); 100 _dataContextProvider = new SingleDataContextProvider( 101 dataContext); 102 } else { 103 try { 104 InitialContext initialContext = new InitialContext(); 105 DataSource dataSource = (DataSource) initialContext 106 .lookup(_datasourceJndiUrl); 107 _dataContextProvider = new DataSourceDataContextProvider( 108 dataSource); 109 } catch (Exception e) { 110 throw new IllegalStateException(e); 111 } 91 112 } 92 try {93 if (_username == null && _password == null) {94 _connection = DriverManager.getConnection(_url);95 } else {96 _connection = DriverManager.getConnection(_url,97 _username, _password);98 }99 } catch (SQLException e) {100 throw new IllegalStateException(101 "Could not establish JDBC connection", e);102 }103 104 DataContext dataContext = DataContextFactory105 .createJdbcDataContext(_connection);106 _dataContextProvider = new SingleDataContextProvider(107 dataContext);108 113 } 109 114 }
Note: See TracChangeset
for help on using the changeset viewer.
