1 |
|
package net.sf.infrared.collector.impl.persistence; |
2 |
|
|
3 |
|
import java.util.Hashtable; |
4 |
|
|
5 |
|
import javax.naming.InitialContext; |
6 |
|
import javax.naming.NamingException; |
7 |
|
import javax.sql.DataSource; |
8 |
|
|
9 |
|
import net.sf.infrared.base.util.LoggingFactory; |
10 |
|
|
11 |
|
import org.apache.log4j.Logger; |
12 |
|
import org.springframework.jdbc.datasource.DelegatingDataSource; |
13 |
|
|
14 |
2 |
public class CollectorDataSource extends DelegatingDataSource { |
15 |
|
|
16 |
|
private String jndiName; |
17 |
|
|
18 |
|
private DataSource defaultDataSource; |
19 |
|
|
20 |
2 |
private static final Logger log = LoggingFactory.getLogger(CollectorDataSource.class); |
21 |
|
|
22 |
|
public DataSource getDefaultDataSource() { |
23 |
0 |
return defaultDataSource; |
24 |
|
} |
25 |
|
|
26 |
|
public void setDefaultDataSource(DataSource defaultDataSource) { |
27 |
2 |
this.defaultDataSource = defaultDataSource; |
28 |
2 |
} |
29 |
|
|
30 |
|
public String getJndiName() { |
31 |
0 |
return jndiName; |
32 |
|
} |
33 |
|
|
34 |
|
public void setJndiName(String jndiName) { |
35 |
2 |
this.jndiName = jndiName; |
36 |
2 |
} |
37 |
|
|
38 |
|
public void afterPropertiesSet() { |
39 |
|
try { |
40 |
2 |
InitialContext ctx = new InitialContext(class="keyword">new Hashtable() ); |
41 |
2 |
Object obj = ctx.lookup(jndiName); |
42 |
|
|
43 |
0 |
setTargetDataSource((DataSource) obj); |
44 |
0 |
log.debug("Datasource configured for the iRED jndi name. Using the user specified datasource."); |
45 |
2 |
} catch (NamingException e) { |
46 |
2 |
log.debug("The JNDI name " + jndiName + |
47 |
|
" is not bound to a valid database. Starting the default hypersonic database."); |
48 |
2 |
setTargetDataSource(defaultDataSource); |
49 |
0 |
} |
50 |
2 |
super.afterPropertiesSet(); |
51 |
2 |
} |
52 |
|
} |