Lines 1-7
Link Here
|
1 |
/* |
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
3 |
* |
4 |
* Copyright 2008-2013 Oracle and/or its affiliates. All rights reserved. |
4 |
* Copyright 2008-2015 Oracle and/or its affiliates. All rights reserved. |
5 |
* |
5 |
* |
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
7 |
* Other names may be trademarks of their respective owners. |
7 |
* Other names may be trademarks of their respective owners. |
Lines 60-76
Link Here
|
60 |
import javax.xml.parsers.DocumentBuilder; |
60 |
import javax.xml.parsers.DocumentBuilder; |
61 |
import javax.xml.parsers.DocumentBuilderFactory; |
61 |
import javax.xml.parsers.DocumentBuilderFactory; |
62 |
import javax.xml.parsers.ParserConfigurationException; |
62 |
import javax.xml.parsers.ParserConfigurationException; |
|
|
63 |
import org.netbeans.modules.glassfish.common.GlassFishState; |
64 |
import org.netbeans.modules.glassfish.common.parser.TreeParser; |
65 |
import org.netbeans.modules.glassfish.eecommon.api.UrlData; |
66 |
import org.netbeans.modules.glassfish.eecommon.api.config.GlassfishConfiguration; |
67 |
import org.netbeans.modules.glassfish.javaee.Hk2DeploymentManager; |
63 |
import org.netbeans.modules.glassfish.tooling.data.GlassFishServer; |
68 |
import org.netbeans.modules.glassfish.tooling.data.GlassFishServer; |
64 |
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion; |
69 |
import org.netbeans.modules.glassfish.tooling.data.GlassFishVersion; |
65 |
import org.netbeans.modules.glassfish.tooling.utils.OsUtils; |
70 |
import org.netbeans.modules.glassfish.tooling.utils.OsUtils; |
66 |
import org.netbeans.modules.glassfish.tooling.utils.ServerUtils; |
71 |
import org.netbeans.modules.glassfish.tooling.utils.ServerUtils; |
67 |
import org.netbeans.modules.glassfish.common.GlassFishState; |
|
|
68 |
import org.netbeans.modules.glassfish.eecommon.api.UrlData; |
69 |
import org.netbeans.modules.glassfish.javaee.*; |
70 |
import org.netbeans.modules.glassfish.common.parser.TreeParser; |
71 |
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; |
72 |
import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException; |
72 |
import org.netbeans.modules.j2ee.deployment.common.api.Datasource; |
73 |
import org.netbeans.modules.j2ee.deployment.common.api.Datasource; |
73 |
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException; |
74 |
import org.netbeans.modules.j2ee.deployment.common.api.DatasourceAlreadyExistsException; |
|
|
75 |
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; |
74 |
import org.netbeans.modules.j2ee.deployment.plugins.spi.DatasourceManager; |
76 |
import org.netbeans.modules.j2ee.deployment.plugins.spi.DatasourceManager; |
75 |
import org.netbeans.modules.j2ee.sun.dd.api.RootInterface; |
77 |
import org.netbeans.modules.j2ee.sun.dd.api.RootInterface; |
76 |
import org.openide.filesystems.FileLock; |
78 |
import org.openide.filesystems.FileLock; |
Lines 105-116
Link Here
|
105 |
ServerUtils.GF_DOMAIN_CONFIG_DIR_NAME, |
107 |
ServerUtils.GF_DOMAIN_CONFIG_DIR_NAME, |
106 |
ServerUtils.GF_DOMAIN_CONFIG_FILE_NAME); |
108 |
ServerUtils.GF_DOMAIN_CONFIG_FILE_NAME); |
107 |
|
109 |
|
108 |
/** List of base file names containing server resources. */ |
|
|
109 |
public static final String[] RESOURCE_FILES = { |
110 |
"glassfish-resources", |
111 |
"sun-resources" |
112 |
}; |
113 |
|
114 |
//////////////////////////////////////////////////////////////////////////// |
110 |
//////////////////////////////////////////////////////////////////////////// |
115 |
// Instance attributes // |
111 |
// Instance attributes // |
116 |
//////////////////////////////////////////////////////////////////////////// |
112 |
//////////////////////////////////////////////////////////////////////////// |
Lines 162-168
Link Here
|
162 |
if (!server.isRemote() && null != domainsDir) { |
158 |
if (!server.isRemote() && null != domainsDir) { |
163 |
File domainXml = new File(domainsDir, domainName + File.separatorChar + DOMAIN_XML_PATH); |
159 |
File domainXml = new File(domainsDir, domainName + File.separatorChar + DOMAIN_XML_PATH); |
164 |
return readDatasources( |
160 |
return readDatasources( |
165 |
domainXml, "/domain/", null, server.getVersion()); |
161 |
domainXml, "/domain/", server.getVersion()); |
166 |
} else { |
162 |
} else { |
167 |
return Collections.EMPTY_SET; |
163 |
return Collections.EMPTY_SET; |
168 |
} |
164 |
} |
Lines 170-176
Link Here
|
170 |
|
166 |
|
171 |
/** |
167 |
/** |
172 |
* Deploys the given set of data sources. |
168 |
* Deploys the given set of data sources. |
173 |
* |
169 |
* <p/> |
174 |
* @param Set of datasources to deploy. |
170 |
* @param Set of datasources to deploy. |
175 |
* @throws ConfigurationException if there is some problem with data source |
171 |
* @throws ConfigurationException if there is some problem with data source |
176 |
* configuration. |
172 |
* configuration. |
Lines 180-276
Link Here
|
180 |
@Override |
176 |
@Override |
181 |
public void deployDatasources(Set<Datasource> datasources) |
177 |
public void deployDatasources(Set<Datasource> datasources) |
182 |
throws ConfigurationException, DatasourceAlreadyExistsException { |
178 |
throws ConfigurationException, DatasourceAlreadyExistsException { |
183 |
// since a connection pool is not a Datasource, the deploy has to |
179 |
// Since a connection pool is not a Datasource, the deploy has to |
184 |
// happen in a different part of the deploy processing... |
180 |
// happen in a different part of the deploy processing... |
185 |
} |
181 |
} |
186 |
|
182 |
|
187 |
|
|
|
188 |
|
189 |
// ------------------------------------------------------------------------ |
190 |
// Used by ModuleConfigurationImpl since |
191 |
// ------------------------------------------------------------------------ |
192 |
|
193 |
// Making this method private because there is no reason to provide resources |
194 |
// file base names manually. |
195 |
/** |
183 |
/** |
196 |
* Get <code>Datasource</code> objects from first available resources file. |
184 |
* Get {@link Datasource} objects from first available resources file. |
197 |
* |
185 |
* <p/> |
198 |
* @param resourceDir Directory containing resource files. |
186 |
* @param version Resources file names depend on GlassFish server version. |
199 |
* @param baseNames List of resource file base names to search for. |
187 |
* @param module Java EE module (project). |
200 |
* @return <code>Datasource</code> objects found in first available file. |
188 |
* @return {@link Datasource} objects found in first available file. |
201 |
*/ |
189 |
*/ |
202 |
private static Set<Datasource> getDatasources( |
190 |
public static Set<Datasource> getDatasources( |
203 |
final File resourceDir, final String[] baseNames, |
191 |
final J2eeModule module, final GlassFishVersion version) { |
204 |
final GlassFishVersion version) { |
192 |
File file = GlassfishConfiguration.getExistingResourceFile(module, version); |
205 |
for (String baseName : baseNames) { |
193 |
if (file != null) { |
206 |
File file = new File(resourceDir, baseName+".xml"); |
194 |
return readDatasources(file, "/", version); |
207 |
// Return Datasource objects from first available file. |
195 |
} else { |
208 |
if (file.isFile()) |
196 |
return new HashSet<>(); |
209 |
return readDatasources(file, "/", resourceDir, version); |
|
|
210 |
} |
197 |
} |
211 |
// Return empty set when no resource file was found. |
|
|
212 |
return new HashSet<>(); |
213 |
} |
198 |
} |
214 |
|
199 |
|
215 |
/** |
|
|
216 |
* Get <code>Datasource</code> objects from first available resources file. |
217 |
* Default resource base names list is used. |
218 |
* |
219 |
* @param resourceDir Directory containing resource files. |
220 |
* @return <code>Datasource</code> objects found in first available file. |
221 |
*/ |
222 |
public static Set<Datasource> getDatasources(File resourceDir) { |
223 |
return getDatasources(resourceDir, RESOURCE_FILES, null); |
224 |
} |
225 |
|
226 |
// public Datasource createDataSource(String jndiName, String url, String username, |
227 |
// String password, String driver, File resourceDir) throws DatasourceAlreadyExistsException { |
228 |
// SunDatasource result = null; |
229 |
// try { |
230 |
// // Throw an exception if the data source already exists. |
231 |
// for(Datasource ds: getDatasources(resourceDir)) { |
232 |
// if(jndiName.equals(ds.getJndiName())) { |
233 |
// throw new DatasourceAlreadyExistsException(new SunDatasource( |
234 |
// jndiName, url, username, password, driver)); |
235 |
// } |
236 |
// } |
237 |
// |
238 |
// if(url != null) { |
239 |
//// String vendorName = convertToValidName(url); |
240 |
//// if(vendorName == null) { |
241 |
//// vendorName = jndiName; |
242 |
//// }else{ |
243 |
//// if(vendorName.equals("derby_embedded")){ //NOI18N |
244 |
//// NotifyDescriptor d = new NotifyDescriptor.Message(bundle.getString("Err_UnSupportedDerby"), NotifyDescriptor.WARNING_MESSAGE); // NOI18N |
245 |
//// DialogDisplayer.getDefault().notify(d); |
246 |
//// return null; |
247 |
//// } |
248 |
//// } |
249 |
// if(resourceDir.exists()) { |
250 |
// FileUtil.createFolder(resourceDir); |
251 |
// } |
252 |
// |
253 |
// // Create connection pool if needed. |
254 |
// String poolName = createCheckForConnectionPool(vendorName, url, username, password, driver, resourceDir); |
255 |
// boolean jdbcExists = requiredResourceExists(jndiName, resourceDir, JDBC_RESOURCE); |
256 |
// if (jdbcExists) { |
257 |
// result = null; |
258 |
// } else { |
259 |
// createJDBCResource(jndiName, poolName, resourceDir); |
260 |
// result = new SunDatasource(jndiName, url, username, password, driver); |
261 |
// } |
262 |
// } |
263 |
// } catch(IOException ex) { |
264 |
// Logger.getLogger("glassfish-javaee").log(Level.WARNING, ex.getLocalizedMessage(), ex); |
265 |
// } |
266 |
// return result; |
267 |
// } |
268 |
|
269 |
|
270 |
// ------------------------------------------------------------------------ |
200 |
// ------------------------------------------------------------------------ |
271 |
// Internal logic |
201 |
// Internal logic |
272 |
// ------------------------------------------------------------------------ |
202 |
// ------------------------------------------------------------------------ |
273 |
|
203 |
|
|
|
204 |
/** |
205 |
* Get resource file for new data source creation and verify it. |
206 |
* Verifies existing resource file syntax and data sources or provides |
207 |
* a new file when no resource file exists. |
208 |
* <br/> |
209 |
* <i>Internal {@link #createDataSource(String, String, String, |
210 |
* String, String, J2eeModule, GlassFishVersion)} helper method.</i> |
211 |
* <p/> |
212 |
* @param jndiName Data source JNDI name. |
213 |
* @param url Database URL. |
214 |
* @param username Database user name. |
215 |
* @param password Database user password. |
216 |
* @param driver Database JDBC driver. |
217 |
* @param module Java EE module (project). |
218 |
* @param version GlassFish server version. |
219 |
* @param cpFinder Connection pool finder. |
220 |
* @return Resource file for new data source creation. |
221 |
* @throws ConfigurationException if there is a problem with resource |
222 |
* file parsing. |
223 |
* @throws DatasourceAlreadyExistsException if the required data source |
224 |
* already exists in resource file. |
225 |
*/ |
226 |
private static File resourceFileForDSCreation( |
227 |
final String jndiName, final String url, final String username, |
228 |
final String password, final String driver, final J2eeModule module, |
229 |
final GlassFishVersion version,final ConnectionPoolFinder cpFinder |
230 |
) throws ConfigurationException, DatasourceAlreadyExistsException { |
231 |
final DuplicateJdbcResourceFinder jdbcFinder |
232 |
= new DuplicateJdbcResourceFinder(jndiName); |
233 |
File file = GlassfishConfiguration.getExistingResourceFile(module, version); |
234 |
if (file.exists()) { |
235 |
List<TreeParser.Path> pathList = new ArrayList<>(); |
236 |
pathList.add(new TreeParser.Path("/resources/jdbc-resource", jdbcFinder)); |
237 |
pathList.add(new TreeParser.Path("/resources/jdbc-connection-pool", cpFinder)); |
238 |
try { |
239 |
TreeParser.readXml(file, pathList); |
240 |
if(jdbcFinder.isDuplicate()) { |
241 |
throw new DatasourceAlreadyExistsException(new SunDatasource( |
242 |
jndiName, url, username, password, driver)); |
243 |
} |
244 |
} catch(IllegalStateException ex) { |
245 |
Logger.getLogger("glassfish-javaee").log( |
246 |
Level.INFO, ex.getLocalizedMessage(), ex); |
247 |
throw new ConfigurationException(ex.getLocalizedMessage(), ex); |
248 |
} |
249 |
} |
250 |
return file != null |
251 |
? file : GlassfishConfiguration.getNewResourceFile(module, version); |
252 |
} |
253 |
|
254 |
/** |
255 |
* Create a data source (jdbc-resource and jdbc-connection-pool) and add it |
256 |
* to sun-resources.xml in the specified resource folder. |
257 |
* |
258 |
* @param jndiName Data source JNDI name. |
259 |
* @param url Database URL. |
260 |
* @param username Database user name. |
261 |
* @param password Database user password. |
262 |
* @param driver Database JDBC driver. |
263 |
* @param module Java EE module (project). |
264 |
* @param version GlassFish server version. |
265 |
* @return New {@link Datasource} object. |
266 |
* @throws ConfigurationException if there is a problem with resource |
267 |
* file parsing. |
268 |
* @throws DatasourceAlreadyExistsException if the required data source |
269 |
* already exists in resource file. |
270 |
*/ |
271 |
public static Datasource createDataSource( |
272 |
final String jndiName, final String url, final String username, |
273 |
final String password, final String driver, |
274 |
final J2eeModule module, final GlassFishVersion version |
275 |
) throws ConfigurationException, DatasourceAlreadyExistsException { |
276 |
SunDatasource ds; |
277 |
ConnectionPoolFinder cpFinder = new ConnectionPoolFinder(); |
278 |
|
279 |
File xmlFile = resourceFileForDSCreation( |
280 |
jndiName, url, username, password, driver, module, version, cpFinder); |
281 |
|
282 |
try { |
283 |
String vendorName = VendorNameMgr.vendorNameFromDbUrl(url); |
284 |
if(vendorName == null) { |
285 |
vendorName = jndiName; |
286 |
} else { |
287 |
if("derby_embedded".equals(vendorName)) { |
288 |
// !PW FIXME display as dialog warning? |
289 |
Logger.getLogger("glassfish-javaee").log(Level.WARNING, |
290 |
"Embedded derby not supported as a datasource"); |
291 |
return null; |
292 |
} |
293 |
} |
294 |
|
295 |
// Is there a connection pool we can reuse, or do we need to create one? |
296 |
String defaultPoolName = computePoolName(url, vendorName, username); |
297 |
Map<String, CPool> pools = cpFinder.getPoolData(); |
298 |
CPool defaultPool = pools.get(defaultPoolName); |
299 |
|
300 |
String poolName = null; |
301 |
if(defaultPool != null && isSameDatabaseConnection(defaultPool, url, username, password)) { |
302 |
poolName = defaultPoolName; |
303 |
} else { |
304 |
for(CPool pool: pools.values()) { |
305 |
if(isSameDatabaseConnection(pool, url, username, password)) { |
306 |
poolName = pool.getPoolName(); |
307 |
break; |
308 |
} |
309 |
} |
310 |
} |
311 |
|
312 |
if(poolName == null) { |
313 |
poolName = defaultPool == null ? defaultPoolName : generateUniqueName(defaultPoolName, pools.keySet()); |
314 |
createConnectionPool(xmlFile, poolName, url, username, password, driver); |
315 |
} |
316 |
|
317 |
// create jdbc resource |
318 |
createJdbcResource(xmlFile, jndiName, poolName); |
319 |
|
320 |
ds = new SunDatasource(jndiName, url, username, password, driver); |
321 |
} catch(IOException ex) { |
322 |
Logger.getLogger("glassfish-javaee").log(Level.INFO, ex.getLocalizedMessage(), ex); |
323 |
throw new ConfigurationException(ex.getLocalizedMessage(), ex); |
324 |
} |
325 |
|
326 |
return ds; |
327 |
} |
328 |
|
274 |
/** |
329 |
/** |
275 |
* Parse resource file and build <code>Datasource</code> objects from it. |
330 |
* Parse resource file and build <code>Datasource</code> objects from it. |
276 |
* <p/> |
331 |
* <p/> |
Lines 289-302
Link Here
|
289 |
*/ |
344 |
*/ |
290 |
private static Set<Datasource> readDatasources( |
345 |
private static Set<Datasource> readDatasources( |
291 |
final File xmlFile, final String xPathPrefix, |
346 |
final File xmlFile, final String xPathPrefix, |
292 |
final File resourcesDir, final GlassFishVersion version) { |
347 |
final GlassFishVersion version) { |
293 |
Set<Datasource> dataSources = new HashSet<>(); |
348 |
final Set<Datasource> dataSources = new HashSet<>(); |
294 |
|
349 |
|
295 |
if (xmlFile.canRead()) { |
350 |
if (xmlFile.canRead()) { |
296 |
Map<String, JdbcResource> jdbcResourceMap = new HashMap<>(); |
351 |
final Map<String, JdbcResource> jdbcResourceMap = new HashMap<>(); |
297 |
Map<String, ConnectionPool> connectionPoolMap = new HashMap<>(); |
352 |
final Map<String, ConnectionPool> connectionPoolMap = new HashMap<>(); |
298 |
|
353 |
|
299 |
List<TreeParser.Path> pathList = new ArrayList<>(); |
354 |
final List<TreeParser.Path> pathList = new ArrayList<>(); |
300 |
pathList.add(new TreeParser.Path(xPathPrefix + "resources/jdbc-resource", new JdbcReader(jdbcResourceMap))); |
355 |
pathList.add(new TreeParser.Path(xPathPrefix + "resources/jdbc-resource", new JdbcReader(jdbcResourceMap))); |
301 |
pathList.add(new TreeParser.Path(xPathPrefix + "resources/jdbc-connection-pool", new ConnectionPoolReader(connectionPoolMap))); |
356 |
pathList.add(new TreeParser.Path(xPathPrefix + "resources/jdbc-connection-pool", new ConnectionPoolReader(connectionPoolMap))); |
302 |
|
357 |
|
Lines 307-325
Link Here
|
307 |
} |
362 |
} |
308 |
|
363 |
|
309 |
for (JdbcResource jdbc : jdbcResourceMap.values()) { |
364 |
for (JdbcResource jdbc : jdbcResourceMap.values()) { |
310 |
ConnectionPool pool = connectionPoolMap.get(jdbc.getPoolName()); |
365 |
final ConnectionPool pool = connectionPoolMap.get(jdbc.getPoolName()); |
311 |
if (pool != null) { |
366 |
if (pool != null) { |
312 |
try { |
367 |
try { |
313 |
pool.normalize(); |
368 |
pool.normalize(); |
314 |
|
369 |
|
315 |
// add to sun datasource list |
370 |
// add to sun datasource list |
316 |
String url = pool.getProperty("URL"); //NOI18N |
371 |
final String url = pool.getProperty("URL"); //NOI18N |
317 |
String username = pool.getProperty("User"); //NOI18N |
372 |
final String username = pool.getProperty("User"); //NOI18N |
318 |
String password = pool.getProperty("Password"); //NOI18N |
373 |
final String password = pool.getProperty("Password"); //NOI18N |
319 |
String driverClassName = pool.getProperty("driverClass"); //NOI18N |
374 |
final String driverClassName = pool.getProperty("driverClass"); //NOI18N |
320 |
SunDatasource dataSource = new SunDatasource( |
375 |
final SunDatasource dataSource = new SunDatasource( |
321 |
jdbc.getJndiName(), url, username, |
376 |
jdbc.getJndiName(), url, username, |
322 |
password, driverClassName, resourcesDir); |
377 |
password, driverClassName); |
323 |
dataSources.add(dataSource); |
378 |
dataSources.add(dataSource); |
324 |
// Add Java EE 7 comp/DefaultDataSource data source |
379 |
// Add Java EE 7 comp/DefaultDataSource data source |
325 |
// as jdbc/__default clone (since GF 4). |
380 |
// as jdbc/__default clone (since GF 4). |
Lines 470-562
Link Here
|
470 |
} |
525 |
} |
471 |
} |
526 |
} |
472 |
} |
527 |
} |
473 |
|
528 |
|
474 |
/** |
|
|
475 |
* Create a data source (jdbc-resource and jdbc-connection-pool) and add it |
476 |
* to sun-resources.xml in the specified resource folder. |
477 |
* |
478 |
* @param jndiName |
479 |
* @param url |
480 |
* @param username |
481 |
* @param password |
482 |
* @param driver |
483 |
* @param resourceDir |
484 |
* @return |
485 |
* @throws DatasourceAlreadyExistsException if the required resources already |
486 |
* exist. |
487 |
*/ |
488 |
public static Datasource createDataSource(String jndiName, String url, |
489 |
String username, String password, String driver, File resourceDir, String baseName) |
490 |
throws ConfigurationException, DatasourceAlreadyExistsException { |
491 |
SunDatasource ds; |
492 |
DuplicateJdbcResourceFinder jdbcFinder = new DuplicateJdbcResourceFinder(jndiName); |
493 |
ConnectionPoolFinder cpFinder = new ConnectionPoolFinder(); |
494 |
|
495 |
File xmlFile = new File(resourceDir, baseName+".xml"); |
496 |
if(xmlFile.exists()) { |
497 |
List<TreeParser.Path> pathList = new ArrayList<>(); |
498 |
pathList.add(new TreeParser.Path("/resources/jdbc-resource", jdbcFinder)); |
499 |
pathList.add(new TreeParser.Path("/resources/jdbc-connection-pool", cpFinder)); |
500 |
|
501 |
try { |
502 |
TreeParser.readXml(xmlFile, pathList); |
503 |
if(jdbcFinder.isDuplicate()) { |
504 |
throw new DatasourceAlreadyExistsException(new SunDatasource( |
505 |
jndiName, url, username, password, driver)); |
506 |
} |
507 |
} catch(IllegalStateException ex) { |
508 |
Logger.getLogger("glassfish-javaee").log(Level.INFO, ex.getLocalizedMessage(), ex); |
509 |
throw new ConfigurationException(ex.getLocalizedMessage(), ex); |
510 |
} |
511 |
} |
512 |
|
513 |
try { |
514 |
String vendorName = VendorNameMgr.vendorNameFromDbUrl(url); |
515 |
if(vendorName == null) { |
516 |
vendorName = jndiName; |
517 |
} else { |
518 |
if("derby_embedded".equals(vendorName)) { |
519 |
// !PW FIXME display as dialog warning? |
520 |
Logger.getLogger("glassfish-javaee").log(Level.WARNING, |
521 |
"Embedded derby not supported as a datasource"); |
522 |
return null; |
523 |
} |
524 |
} |
525 |
|
526 |
// Is there a connection pool we can reuse, or do we need to create one? |
527 |
String defaultPoolName = computePoolName(url, vendorName, username); |
528 |
Map<String, CPool> pools = cpFinder.getPoolData(); |
529 |
CPool defaultPool = pools.get(defaultPoolName); |
530 |
|
531 |
String poolName = null; |
532 |
if(defaultPool != null && isSameDatabaseConnection(defaultPool, url, username, password)) { |
533 |
poolName = defaultPoolName; |
534 |
} else { |
535 |
for(CPool pool: pools.values()) { |
536 |
if(isSameDatabaseConnection(pool, url, username, password)) { |
537 |
poolName = pool.getPoolName(); |
538 |
break; |
539 |
} |
540 |
} |
541 |
} |
542 |
|
543 |
if(poolName == null) { |
544 |
poolName = defaultPool == null ? defaultPoolName : generateUniqueName(defaultPoolName, pools.keySet()); |
545 |
createConnectionPool(xmlFile, poolName, url, username, password, driver); |
546 |
} |
547 |
|
548 |
// create jdbc resource |
549 |
createJdbcResource(xmlFile, jndiName, poolName); |
550 |
|
551 |
ds = new SunDatasource(jndiName, url, username, password, driver, resourceDir); |
552 |
} catch(IOException ex) { |
553 |
Logger.getLogger("glassfish-javaee").log(Level.INFO, ex.getLocalizedMessage(), ex); |
554 |
throw new ConfigurationException(ex.getLocalizedMessage(), ex); |
555 |
} |
556 |
|
557 |
return ds; |
558 |
} |
559 |
|
560 |
private static String generateUniqueName(String prefix, Set<String> keys) { |
529 |
private static String generateUniqueName(String prefix, Set<String> keys) { |
561 |
for(int i = 1; ; i++) { |
530 |
for(int i = 1; ; i++) { |
562 |
String candidate = prefix + "_" + i; // NOI18N |
531 |
String candidate = prefix + "_" + i; // NOI18N |