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 java.sql.Connection;
23 import java.sql.DriverManager;
24 import java.sql.SQLException;
25 import java.util.Iterator;
26 import java.util.Map;
27 import java.util.Properties;
28
29
30
31
32 public class DefaultConfigurableJdoFactory
33 extends AbstractConfigurableJdoFactory
34 implements ConfigurableJdoFactory
35 {
36
37
38
39
40 private String driverName;
41
42 private String url;
43
44 private String userName;
45
46 private String password;
47
48 public void setDriverName( String driverName )
49 {
50 this.driverName = driverName;
51 }
52
53 public void setUrl( String url )
54 {
55 this.url = url;
56 }
57
58 public void setUserName( String userName )
59 {
60 this.userName = userName;
61 }
62
63 public void setPassword( String password )
64 {
65 this.password = password;
66 }
67
68 public void shutdown()
69 throws Exception
70 {
71 if ( url != null )
72 {
73
74 if ( url.indexOf( "jdbc:derby:" ) == 0 )
75 {
76 String databasePath = url.substring( "jdbc:derby:".length() );
77
78 if ( databasePath.indexOf( ';' ) > 0 )
79 {
80 databasePath = databasePath.substring( 0, databasePath.indexOf( ';' ) );
81 }
82
83 Connection connection = null;
84
85 try
86 {
87
88 DriverManager.getConnection( "jdbc:derby:" + databasePath + ";shutdown=true" );
89 }
90 catch ( SQLException e )
91 {
92
93
94
95
96 }
97 finally
98 {
99 if ( connection != null )
100 {
101 try
102 {
103 connection.close();
104 }
105 catch ( SQLException e )
106 {
107
108 }
109 }
110 }
111
112 System.gc();
113 }
114 }
115 super.shutdown();
116 }
117
118 public Properties getProperties()
119 {
120 synchronized ( configured )
121 {
122 if ( configured == Boolean.TRUE )
123 {
124 return properties;
125 }
126 else
127 {
128 Properties properties = new Properties();
129
130 Iterator it = otherProperties.entrySet().iterator();
131 while ( it.hasNext() )
132 {
133 Map.Entry entry = (Map.Entry) it.next();
134 properties.setProperty( (String) entry.getKey(), (String) entry.getValue() );
135 }
136
137 setPropertyInner( properties, "javax.jdo.PersistenceManagerFactoryClass",
138 persistenceManagerFactoryClass );
139 setPropertyInner( properties, "javax.jdo.option.ConnectionDriverName", driverName );
140 setPropertyInner( properties, "javax.jdo.option.ConnectionURL", url );
141 setPropertyInner( properties, "javax.jdo.option.ConnectionUserName", userName );
142 setPropertyInner( properties, "javax.jdo.option.ConnectionPassword", password );
143
144 return properties;
145 }
146 }
147 }
148
149 public String getDriverName()
150 {
151 return driverName;
152 }
153
154 public String getPassword()
155 {
156 return password;
157 }
158
159 public String getUrl()
160 {
161 return url;
162 }
163
164 public String getUserName()
165 {
166 return userName;
167 }
168
169 }