1 package org.apache.archiva.redback.common.jdo;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
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;
32 import javax.annotation.PostConstruct;
33 import javax.inject.Inject;
34 import javax.inject.Named;
37 * UserConfigurableJdoFactory
39 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
42 @Service( "jdoFactory#users" )
43 public class UserConfigurableJdoFactory
44 extends DefaultConfigurableJdoFactory
47 private Logger log = LoggerFactory.getLogger( getClass() );
50 @Named( value = "userConfiguration" )
51 private UserConfiguration config;
53 private String getConfigString( String key, String currentValue, String defaultValue )
55 String valueFromSysProps = System.getProperty( "redback." + key );
56 if (StringUtils.isNotEmpty( valueFromSysProps ))
58 return valueFromSysProps;
61 if ( StringUtils.isNotEmpty( currentValue ) )
63 value = config.getString( key, currentValue );
67 value = config.getString( key, defaultValue );
69 // do some interpolation as we can have some ${plexus.home} etc...
70 StringSearchInterpolator interpolator = new StringSearchInterpolator();
71 interpolator.addValueSource( new PropertiesBasedValueSource( System.getProperties() ) );
75 return interpolator.interpolate( value );
77 catch ( InterpolationException e )
79 // ignore interpolation issue
80 log.warn( "skip issue during interpolation " + e.getMessage() );
86 public void initialize()
88 String jdbcDriverName =
89 getConfigString( "jdbc.driver.name", super.getDriverName(), "org.apache.derby.jdbc.EmbeddedDriver" );
91 getConfigString( "jdbc.url", super.getUrl(), "jdbc:derby:${plexus.home}/database;create=true" );
93 String jdbcUsername = getConfigString( "jdbc.username", super.getUserName(), "sa" );
94 String jdbcPassword = getConfigString( "jdbc.password", super.getPassword(), "" );
96 super.setDriverName( jdbcDriverName );
97 super.setUrl( jdbcUrl );
98 super.setUserName( jdbcUsername );
99 super.setPassword( jdbcPassword );
101 if ( StringUtils.isEmpty( super.persistenceManagerFactoryClass ) )
103 super.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
106 if ( ( super.otherProperties == null ) || super.otherProperties.isEmpty() )
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" );
119 public UserConfiguration getConfig()
124 public void setConfig( UserConfiguration config )
126 this.config = config;