This project has retired. For details please refer to its
Attic page.
UserConfigurableJdoFactory xref
1 package org.apache.archiva.redback.common.jdo;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.archiva.redback.components.jdo.DefaultConfigurableJdoFactory;
23 import org.apache.archiva.redback.configuration.UserConfiguration;
24 import org.apache.commons.lang.StringUtils;
25 import org.codehaus.plexus.interpolation.InterpolationException;
26 import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
27 import org.codehaus.plexus.interpolation.StringSearchInterpolator;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.stereotype.Service;
31
32 import javax.annotation.PostConstruct;
33 import javax.inject.Inject;
34 import javax.inject.Named;
35
36
37
38
39
40
41
42 @Service( "jdoFactory#users" )
43 public class UserConfigurableJdoFactory
44 extends DefaultConfigurableJdoFactory
45 {
46
47 private Logger log = LoggerFactory.getLogger( getClass() );
48
49 @Inject
50 @Named( value = "userConfiguration#default" )
51 private UserConfiguration config;
52
53 private String getConfigString( String key, String currentValue, String defaultValue )
54 {
55 String valueFromSysProps = System.getProperty( "redback." + key );
56 if (StringUtils.isNotEmpty( valueFromSysProps ))
57 {
58 return valueFromSysProps;
59 }
60 String value = null;
61 if ( StringUtils.isNotEmpty( currentValue ) )
62 {
63 value = config.getString( key, currentValue );
64 }
65 else
66 {
67 value = config.getString( key, defaultValue );
68 }
69
70 StringSearchInterpolator interpolator = new StringSearchInterpolator();
71 interpolator.addValueSource( new PropertiesBasedValueSource( System.getProperties() ) );
72
73 try
74 {
75 return interpolator.interpolate( value );
76 }
77 catch ( InterpolationException e )
78 {
79
80 log.warn( "skip issue during interpolation " + e.getMessage() );
81 return value;
82 }
83 }
84
85 @PostConstruct
86 public void initialize()
87 {
88 String jdbcDriverName =
89 getConfigString( "jdbc.driver.name", super.getDriverName(), "org.apache.derby.jdbc.EmbeddedDriver" );
90 String jdbcUrl =
91 getConfigString( "jdbc.url", super.getUrl(), "jdbc:derby:${plexus.home}/database;create=true" );
92
93 String jdbcUsername = getConfigString( "jdbc.username", super.getUserName(), "sa" );
94 String jdbcPassword = getConfigString( "jdbc.password", super.getPassword(), "" );
95
96 super.setDriverName( jdbcDriverName );
97 super.setUrl( jdbcUrl );
98 super.setUserName( jdbcUsername );
99 super.setPassword( jdbcPassword );
100
101 if ( StringUtils.isEmpty( super.persistenceManagerFactoryClass ) )
102 {
103 super.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
104 }
105
106 if ( ( super.otherProperties == null ) || super.otherProperties.isEmpty() )
107 {
108 super.setProperty( "org.jpox.autoCreateSchema", "true" );
109 super.setProperty( "org.jpox.validateSchema", "false" );
110 super.setProperty( "org.jpox.validateTables", "false" );
111 super.setProperty( "org.jpox.validateConstraints", "false" );
112 super.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
113 super.setProperty( "org.jpox.rdbms.dateTimezone", "JDK_DEFAULT_TIMEZONE" );
114 }
115
116 super.initialize();
117 }
118
119 public UserConfiguration getConfig()
120 {
121 return config;
122 }
123
124 public void setConfig( UserConfiguration config )
125 {
126 this.config = config;
127 }
128 }