1 34 package org.objectstyle.cayenne.modeler.pref; 35 36 import java.sql.Driver ; 37 import java.sql.SQLException ; 38 39 import javax.sql.DataSource ; 40 41 import org.objectstyle.cayenne.conn.DataSourceInfo; 42 import org.objectstyle.cayenne.conn.DriverDataSource; 43 import org.objectstyle.cayenne.dba.DbAdapter; 44 import org.objectstyle.cayenne.modeler.ClassLoadingService; 45 import org.objectstyle.cayenne.util.Util; 46 47 public class DBConnectionInfo extends _DBConnectionInfo { 48 49 52 public DbAdapter makeAdapter(ClassLoadingService classLoader) throws Exception { 53 if (getDbAdapter() == null) { 54 throw new Exception ("No DbAdapter set."); 55 } 56 57 try { 58 return (DbAdapter) classLoader.loadClass(getDbAdapter()).newInstance(); 59 } 60 catch (Throwable th) { 61 th = Util.unwindException(th); 62 throw new Exception ("DbAdapter load error: " + th.getLocalizedMessage()); 63 } 64 } 65 66 71 public DataSource makeDataSource(ClassLoadingService classLoader) throws SQLException { 72 73 if (getJdbcDriver() == null) { 75 throw new SQLException ("No JDBC driver set."); 76 } 77 78 if (getUrl() == null) { 79 throw new SQLException ("No DB URL set."); 80 } 81 82 Driver driver; 84 85 try { 86 driver = (Driver ) classLoader.loadClass(getJdbcDriver()).newInstance(); 87 } 88 catch (Throwable th) { 89 th = Util.unwindException(th); 90 throw new SQLException ("Driver load error: " + th.getLocalizedMessage()); 91 } 92 93 return new DriverDataSource(driver, getUrl(), getUserName(), getPassword()); 94 } 95 96 99 public boolean copyTo(DBConnectionInfo dataSourceInfo) { 100 boolean updated = false; 101 102 if (!Util.nullSafeEquals(dataSourceInfo.getUrl(), getUrl())) { 103 dataSourceInfo.setUrl(getUrl()); 104 updated = true; 105 } 106 107 if (!Util.nullSafeEquals(dataSourceInfo.getUserName(), getUserName())) { 108 dataSourceInfo.setUserName(getUserName()); 109 updated = true; 110 } 111 112 if (!Util.nullSafeEquals(dataSourceInfo.getPassword(), getPassword())) { 113 dataSourceInfo.setPassword(getPassword()); 114 updated = true; 115 } 116 117 if (!Util.nullSafeEquals(dataSourceInfo.getJdbcDriver(), getJdbcDriver())) { 118 dataSourceInfo.setJdbcDriver(getJdbcDriver()); 119 updated = true; 120 } 121 122 if (!Util.nullSafeEquals(dataSourceInfo.getDbAdapter(), getDbAdapter())) { 123 dataSourceInfo.setDbAdapter(getDbAdapter()); 124 updated = true; 125 } 126 127 return updated; 128 } 129 130 138 public boolean copyTo(DataSourceInfo dataSourceInfo) { 139 boolean updated = false; 140 141 if (!Util.nullSafeEquals(dataSourceInfo.getDataSourceUrl(), getUrl())) { 142 dataSourceInfo.setDataSourceUrl(getUrl()); 143 updated = true; 144 } 145 146 if (!Util.nullSafeEquals(dataSourceInfo.getUserName(), getUserName())) { 147 dataSourceInfo.setUserName(getUserName()); 148 updated = true; 149 } 150 151 if (!Util.nullSafeEquals(dataSourceInfo.getPassword(), getPassword())) { 152 dataSourceInfo.setPassword(getPassword()); 153 updated = true; 154 } 155 156 if (!Util.nullSafeEquals(dataSourceInfo.getJdbcDriver(), getJdbcDriver())) { 157 dataSourceInfo.setJdbcDriver(getJdbcDriver()); 158 updated = true; 159 } 160 161 return updated; 162 } 163 164 public boolean copyFrom(DataSourceInfo dataSourceInfo) { 165 boolean updated = false; 166 167 if (!Util.nullSafeEquals(dataSourceInfo.getDataSourceUrl(), getUrl())) { 168 setUrl(dataSourceInfo.getDataSourceUrl()); 169 updated = true; 170 } 171 172 if (!Util.nullSafeEquals(dataSourceInfo.getUserName(), getUserName())) { 173 setUserName(dataSourceInfo.getUserName()); 174 updated = true; 175 } 176 177 if (!Util.nullSafeEquals(dataSourceInfo.getPassword(), getPassword())) { 178 setPassword(dataSourceInfo.getPassword()); 179 updated = true; 180 } 181 182 if (!Util.nullSafeEquals(dataSourceInfo.getJdbcDriver(), getJdbcDriver())) { 183 setJdbcDriver(dataSourceInfo.getJdbcDriver()); 184 updated = true; 185 } 186 187 return updated; 188 } 189 } 190 191 | Popular Tags |