1 package org.apache.archiva.redback.components.jdo;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import javax.naming.Context;
23 import javax.naming.InitialContext;
24 import javax.sql.DataSource;
25 import java.util.Iterator;
26 import java.util.Map;
27 import java.util.Properties;
28 import java.sql.SQLException;
29
30
31
32
33
34 public class DataSourceConfigurableJdoFactory
35 extends AbstractConfigurableJdoFactory
36 {
37
38
39
40
41
42
43
44 private String connectionFactoryName;
45
46
47
48
49 private String shutdownConnectionFactoryName;
50
51 public Properties getProperties()
52 {
53 synchronized ( configured )
54 {
55 if ( configured == Boolean.TRUE )
56 {
57 return properties;
58 }
59 else
60 {
61 Properties properties = new Properties();
62
63 Iterator it = otherProperties.entrySet().iterator();
64 while ( it.hasNext() )
65 {
66 Map.Entry entry = (Map.Entry) it.next();
67 properties.setProperty( (String) entry.getKey(), (String) entry.getValue() );
68 }
69
70 setPropertyInner( properties, "javax.jdo.PersistenceManagerFactoryClass",
71 persistenceManagerFactoryClass );
72 setPropertyInner( properties, "javax.jdo.option.ConnectionFactoryName", connectionFactoryName );
73
74 return properties;
75 }
76 }
77 }
78
79
80 public void shutdown()
81 throws Exception
82 {
83 if ( shutdownConnectionFactoryName != null )
84 {
85 Context ctx = new InitialContext();
86 DataSource ds = (DataSource) ctx.lookup( shutdownConnectionFactoryName );
87 try
88 {
89 ds.getConnection();
90 }
91 catch ( SQLException e )
92 {
93
94
95
96
97 }
98 }
99
100 super.shutdown();
101 }
102
103 public String getConnectionFactoryName()
104 {
105 return connectionFactoryName;
106 }
107
108 public void setConnectionFactoryName( String connectionFactoryName )
109 {
110 this.connectionFactoryName = connectionFactoryName;
111 }
112
113 public String getShutdownConnectionFactoryName()
114 {
115 return shutdownConnectionFactoryName;
116 }
117
118 public void setShutdownConnectionFactoryName( String shutdownConnectionFactoryName )
119 {
120 this.shutdownConnectionFactoryName = shutdownConnectionFactoryName;
121 }
122 }