Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Nov 27, 2015
2 parents f93b1f3 + 26bd286 commit e1b30c8
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 134 deletions.
Expand Up @@ -961,7 +961,7 @@ private void prepareActivation(ResourceActivationDefinitionType activation){
existence.getInbound().addAll(newInbounds);

List<MappingType> outbounds = existence.getOutbound();
List<MappingType> newOutbounds = existence.getOutbound();
List<MappingType> newOutbounds = new ArrayList<>();

for(MappingType outbound: outbounds){
if(!WizardUtil.isEmptyMapping(outbound)){
Expand Down
Expand Up @@ -21,36 +21,18 @@
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
default-lazy-init="true" default-autowire="byName">

<bean id="testC3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" lazy-init="true"
destroy-method="close">
<property name="driverClass" value="#{testSqlRepositoryFactory.sqlConfiguration.driverClassName}"/>
<property name="jdbcUrl" value="#{testSqlRepositoryFactory.sqlConfiguration.jdbcUrl}"/>
<property name="user" value="#{testSqlRepositoryFactory.sqlConfiguration.jdbcUsername}"/>
<property name="password" value="#{testSqlRepositoryFactory.sqlConfiguration.jdbcPassword}"/>

<property name="acquireIncrement" value="3"/>
<property name="minPoolSize" value="#{testSqlRepositoryFactory.sqlConfiguration.minPoolSize}"/>
<property name="maxPoolSize" value="#{testSqlRepositoryFactory.sqlConfiguration.maxPoolSize}"/>
<property name="idleConnectionTestPeriod" value="1800"/>
<property name="connectionTesterClassName" value="com.evolveum.midpoint.repo.sql.util.MidPointConnectionTester" />
<property name="connectionCustomizerClassName"
value="com.evolveum.midpoint.repo.sql.util.MidPointConnectionCustomizer"/>
</bean>

<bean id="testJndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiName" value="#{testSqlRepositoryFactory.sqlConfiguration.dataSource}"/>
<bean id="testDataSourceFactory" class="com.evolveum.midpoint.repo.sql.DataSourceFactory">
<property name="configuration" value="#{testSqlRepositoryFactory.sqlConfiguration}" />
</bean>

<bean name="testSqlDataSource" class="com.evolveum.midpoint.repo.sql.CompositeDataSource" lazy-init="true">
<property name="configuration" value="#{testSqlRepositoryFactory.sqlConfiguration}"/>
<property name="testing" value="true"/>
</bean>
<bean id="testDataSource" factory-bean="testDataSourceFactory" factory-method="createDataSource"
depends-on="testDataSourceFactory"/>

<!-- Hibernate session factory -->
<bean id="testSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
depends-on="testSqlDataSource" lazy-init="true">
depends-on="testDataSource" lazy-init="true">

<property name="dataSource" value="#{testSqlDataSource.dataSource}" />
<property name="dataSource" ref="testDataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">#{testSqlRepositoryFactory.sqlConfiguration.hibernateDialect}</prop>
Expand Down

This file was deleted.

@@ -0,0 +1,89 @@
/*
* Copyright (c) 2010-2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.repo.sql;

import com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException;
import com.evolveum.midpoint.repo.sql.util.MidPointConnectionCustomizer;
import com.evolveum.midpoint.repo.sql.util.MidPointConnectionTester;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.lang.StringUtils;
import org.springframework.jndi.JndiObjectFactoryBean;

import javax.naming.NamingException;
import javax.sql.DataSource;
import java.beans.PropertyVetoException;

/**
* @author Viliam Repan (lazyman)
*/
public class DataSourceFactory {

private static final Trace LOGGER = TraceManager.getTrace(DataSourceFactory.class);

private SqlRepositoryConfiguration configuration;

public void setConfiguration(SqlRepositoryConfiguration configuration) {
this.configuration = configuration;
}

public DataSource createDataSource() throws RepositoryServiceFactoryException {
LOGGER.info("Loading datasource.");
if (configuration == null) {
throw new RepositoryServiceFactoryException("SQL configuration is null, couldn't create datasource.");
}

try {
if (StringUtils.isNotEmpty(configuration.getDataSource())) {
LOGGER.info("JDNI datasource present in configuration, looking for '{}'.",
new Object[]{configuration.getDataSource()});
return createJNDIDataSource();
}

LOGGER.info("Constructing default C3P0 datasource with connection pooling.");
return createC3P0DataSource();
} catch (Exception ex) {
throw new RepositoryServiceFactoryException("Couldn't initialize datasource, reason: " + ex.getMessage(), ex);
}
}

private DataSource createJNDIDataSource() throws IllegalArgumentException, NamingException {
JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
factory.setJndiName(configuration.getDataSource());
factory.afterPropertiesSet();

return (DataSource) factory.getObject();
}

private DataSource createC3P0DataSource() throws PropertyVetoException {
ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setDriverClass(configuration.getDriverClassName());
ds.setJdbcUrl(configuration.getJdbcUrl());
ds.setUser(configuration.getJdbcUsername());
ds.setPassword(configuration.getJdbcPassword());

ds.setAcquireIncrement(3);
ds.setMinPoolSize(configuration.getMinPoolSize());
ds.setMaxPoolSize(configuration.getMaxPoolSize());
ds.setIdleConnectionTestPeriod(1800);
ds.setConnectionTesterClassName(MidPointConnectionTester.class.getName());
ds.setConnectionCustomizerClassName(MidPointConnectionCustomizer.class.getName());

return ds;
}
}
29 changes: 6 additions & 23 deletions repo/repo-sql-impl/src/main/resources/ctx-repository-session.xml
Expand Up @@ -21,35 +21,18 @@
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
default-lazy-init="true" default-autowire="byName">

<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" lazy-init="true"
destroy-method="close">
<property name="driverClass" value="#{sqlRepositoryFactory.sqlConfiguration.driverClassName}"/>
<property name="jdbcUrl" value="#{sqlRepositoryFactory.sqlConfiguration.jdbcUrl}"/>
<property name="user" value="#{sqlRepositoryFactory.sqlConfiguration.jdbcUsername}"/>
<property name="password" value="#{sqlRepositoryFactory.sqlConfiguration.jdbcPassword}"/>

<property name="acquireIncrement" value="3"/>
<property name="minPoolSize" value="#{sqlRepositoryFactory.sqlConfiguration.minPoolSize}"/>
<property name="maxPoolSize" value="#{sqlRepositoryFactory.sqlConfiguration.maxPoolSize}"/>
<property name="idleConnectionTestPeriod" value="1800"/>
<property name="connectionTesterClassName" value="com.evolveum.midpoint.repo.sql.util.MidPointConnectionTester" />
<property name="connectionCustomizerClassName"
value="com.evolveum.midpoint.repo.sql.util.MidPointConnectionCustomizer"/>
</bean>

<bean id="jndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiName" value="#{sqlRepositoryFactory.sqlConfiguration.dataSource}"/>
</bean>

<bean name="sqlDataSource" class="com.evolveum.midpoint.repo.sql.CompositeDataSource" lazy-init="true">
<bean id="dataSourceFactory" class="com.evolveum.midpoint.repo.sql.DataSourceFactory">
<property name="configuration" value="#{sqlRepositoryFactory.sqlConfiguration}" />
</bean>

<bean id="dataSource" factory-bean="dataSourceFactory" factory-method="createDataSource"
depends-on="dataSourceFactory"/>

<!-- Hibernate session factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
depends-on="sqlDataSource" lazy-init="true">
depends-on="dataSource" lazy-init="true">

<property name="dataSource" value="#{sqlDataSource.dataSource}" />
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">#{sqlRepositoryFactory.sqlConfiguration.hibernateDialect}</prop>
Expand Down

0 comments on commit e1b30c8

Please sign in to comment.