diff options
5 files changed, 7 insertions, 108 deletions
diff --git a/sonar-application/src/main/assembly/conf/sonar.properties b/sonar-application/src/main/assembly/conf/sonar.properties index 97515452f73..dc05f1625ff 100644 --- a/sonar-application/src/main/assembly/conf/sonar.properties +++ b/sonar-application/src/main/assembly/conf/sonar.properties @@ -108,17 +108,6 @@ sonar.jdbc.minEvictableIdleTimeMillis: 600000 sonar.jdbc.timeBetweenEvictionRunsMillis: 30000 -#----- JDBC Datasource bounded to JNDI -# When sonar webapp is deployed into a JEE server, the JDBC datasource can be loaded from JNDI. -# In such a case Sonar uses this datasource to connect to database. -# If you activate this feature, then the properties starting with "sonar.jdbc." can be commented, except sonar.jdbc.dialect. -# The JDBC driver must still be deployed into the directory /extensions/jdbc-driver. -#sonar.jdbc.jndiName: jdbc/sonar - -# Values are : mysql, mssql, oracle, postgresql -#sonar.jdbc.dialect= - - #--------------------------------------------------------- # UPDATE CENTER #--------------------------------------------------------- diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/DatabaseProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/DatabaseProperties.java index 8b6ed15b8d6..97d9bd3004f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/DatabaseProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/DatabaseProperties.java @@ -38,7 +38,6 @@ public interface DatabaseProperties { String PROP_HIBERNATE_GENERATE_STATISTICS = "sonar.jdbc.hibernate.generate_statistics"; String PROP_DIALECT = "sonar.jdbc.dialect"; String PROP_DIALECT_CLASS = "sonar.jdbc.dialectClass"; - String PROP_JNDI_NAME = "sonar.jdbc.jndiName"; String PROP_EMBEDDED_PORT = "sonar.embeddedDatabase.port"; String PROP_HIBERNATE_DEFAULT_SCHEMA = "sonar.hibernate.default_schema"; diff --git a/sonar-server/src/main/java/org/sonar/server/database/JndiDatabaseConnector.java b/sonar-server/src/main/java/org/sonar/server/database/JndiDatabaseConnector.java index 581f8ae6361..abcb18f9a4c 100644 --- a/sonar-server/src/main/java/org/sonar/server/database/JndiDatabaseConnector.java +++ b/sonar-server/src/main/java/org/sonar/server/database/JndiDatabaseConnector.java @@ -21,17 +21,12 @@ package org.sonar.server.database; import org.apache.commons.configuration.Configuration; import org.apache.commons.dbcp.BasicDataSourceFactory; -import org.apache.commons.lang.StringUtils; import org.hibernate.cfg.Environment; -import org.sonar.api.database.DatabaseProperties; import org.sonar.api.utils.Logs; import org.sonar.api.utils.SonarException; import org.sonar.jpa.entity.SchemaMigration; import org.sonar.jpa.session.AbstractDatabaseConnector; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; @@ -40,13 +35,10 @@ import java.util.Properties; public class JndiDatabaseConnector extends AbstractDatabaseConnector { - static final String JNDI_ENV_CONTEXT = "java:comp/env"; private DataSource datasource = null; - private String jndiKey; public JndiDatabaseConnector(Configuration configuration) { super(configuration, false); - jndiKey = getConfiguration().getString(DatabaseProperties.PROP_JNDI_NAME); } @Override @@ -62,11 +54,7 @@ public class JndiDatabaseConnector extends AbstractDatabaseConnector { @Override public void start() { if (!isStarted()) { - if (StringUtils.isNotBlank(jndiKey)) { - loadJndiDatasource(); - } else { - createDatasource(); - } + createDatasource(); } if (!super.isOperational()) { super.start(); @@ -80,37 +68,12 @@ public class JndiDatabaseConnector extends AbstractDatabaseConnector { } - private void loadJndiDatasource() { - Context ctx; - try { - ctx = new InitialContext(); - - } catch (NamingException e) { - throw new SonarException("Can not instantiate JNDI context", e); - } - - try { - Context envCtx = (Context) ctx.lookup(JNDI_ENV_CONTEXT); - datasource = (DataSource) envCtx.lookup(jndiKey); - Logs.INFO.info("JDBC datasource loaded from JNDI: " + jndiKey); - - } catch (NamingException e) { - throw new SonarException("JNDI context of JDBC datasource not found: " + jndiKey, e); - - } finally { - try { - ctx.close(); - } catch (NamingException e) { - } - } - } - private void createDatasource() { try { Logs.INFO.info("Creating JDBC datasource"); Properties properties = new Properties(); Configuration dsConfig = getConfiguration().subset("sonar.jdbc"); - for (Iterator<String> it = dsConfig.getKeys(); it.hasNext();) { + for (Iterator<String> it = dsConfig.getKeys(); it.hasNext(); ) { String key = it.next(); properties.setProperty(key, dsConfig.getString(key)); } @@ -139,11 +102,7 @@ public class JndiDatabaseConnector extends AbstractDatabaseConnector { @Override public void setupEntityManagerFactory(Properties factoryProps) { - if (StringUtils.isNotBlank(jndiKey)) { - factoryProps.put(Environment.DATASOURCE, JNDI_ENV_CONTEXT + "/" + jndiKey); - } else { - factoryProps.put(Environment.CONNECTION_PROVIDER, CustomHibernateConnectionProvider.class.getName()); - } + factoryProps.put(Environment.CONNECTION_PROVIDER, CustomHibernateConnectionProvider.class.getName()); } }
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/config/database.yml b/sonar-server/src/main/webapp/WEB-INF/config/database.yml index 7b755e4b2ba..fe16fdbd96e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/config/database.yml +++ b/sonar-server/src/main/webapp/WEB-INF/config/database.yml @@ -1,17 +1,8 @@ base: &base adapter: <%= ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getDialect().getActiveRecordJdbcAdapter() %> -<% - jndi_name = ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getConfigurationValue('sonar.jdbc.jndiName') - unless jndi_name -%> - # JDBC settings username: <%= ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getConfigurationValue('sonar.jdbc.username' ) || 'sonar' %> password: <%= ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getConfigurationValue('sonar.jdbc.password') || 'sonar' %> url: <%= ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getConfigurationValue('sonar.jdbc.url') %> -<% - end -%> - # Generic settings dialect: <%= ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getDialect().getActiveRecordDialectCode() %> driver: <%= ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getConfigurationValue('sonar.jdbc.driverClassName') %> pool: <%= ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getConfigurationValue('sonar.jdbc.maxActive') || 10 %> diff --git a/sonar-server/src/test/java/org/sonar/server/database/JndiDatabaseConnectorTest.java b/sonar-server/src/test/java/org/sonar/server/database/JndiDatabaseConnectorTest.java index 37e28fb7b5d..e3874c385af 100644 --- a/sonar-server/src/test/java/org/sonar/server/database/JndiDatabaseConnectorTest.java +++ b/sonar-server/src/test/java/org/sonar/server/database/JndiDatabaseConnectorTest.java @@ -28,31 +28,25 @@ import org.sonar.api.database.DatabaseProperties; import org.sonar.jpa.entity.SchemaMigration; import javax.naming.Context; -import javax.naming.spi.InitialContextFactory; import javax.persistence.EntityManagerFactory; -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.util.Hashtable; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; public class JndiDatabaseConnectorTest { - private Configuration conf; private String currentInitialContextFacto; private JndiDatabaseConnector connector; private int emfCreationCounter; @Before public void setup() { - conf = new PropertiesConfiguration(); - conf.setProperty(DatabaseProperties.PROP_JNDI_NAME, "jdbc/sonar"); + Configuration conf = new PropertiesConfiguration(); conf.setProperty(DatabaseProperties.PROP_DIALECT, DatabaseProperties.DIALECT_HSQLDB); + conf.setProperty(DatabaseProperties.PROP_URL, "jdbc:hsqldb:mem:sonar"); + conf.setProperty(DatabaseProperties.PROP_DRIVER, "org.hsqldb.jdbcDriver"); currentInitialContextFacto = System.getProperty(Context.INITIAL_CONTEXT_FACTORY); connector = getTestJndiConnector(conf); - System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TestInitialContextFactory.class.getName()); } @After @@ -75,16 +69,6 @@ public class JndiDatabaseConnectorTest { assertEquals(2, emfCreationCounter); } - @Test - public void transactionIsolationCorrectlySet() throws Exception { - int fakeTransactionIsolation = 9; - conf.setProperty(DatabaseProperties.PROP_ISOLATION, fakeTransactionIsolation); - connector.start(); - Connection c = connector.getConnection(); - // start method call get a connection to test it, so total number is 2 - verify(c, times(2)).setTransactionIsolation(fakeTransactionIsolation); - } - private JndiDatabaseConnector getTestJndiConnector(Configuration conf) { JndiDatabaseConnector connector = new JndiDatabaseConnector(conf) { @Override @@ -102,28 +86,5 @@ public class JndiDatabaseConnectorTest { return connector; } - public static class TestInitialContextFactory implements InitialContextFactory { - - private Connection c; - - public Context getInitialContext(Hashtable env) { - Context envContext = mock(Context.class); - Context context = mock(Context.class); - DataSource ds = mock(DataSource.class); - DatabaseMetaData m = mock(DatabaseMetaData.class); - c = mock(Connection.class); - try { - when(envContext.lookup(JndiDatabaseConnector.JNDI_ENV_CONTEXT)).thenReturn(context); - when(context.lookup("jdbc/sonar")).thenReturn(ds); - when(ds.getConnection()).thenReturn(c); - when(m.getURL()).thenReturn("jdbc:test"); - when(c.getMetaData()).thenReturn(m); - } catch (Exception e) { - throw new RuntimeException(e); - } - - return envContext; - } - } } |