MIFOSX-694: add missing users cache to ehcache xml file.

This commit is contained in:
Keith Woodlock
2013-09-26 23:56:04 +01:00
parent 1ca11846b4
commit c4e92edf99
4 changed files with 14 additions and 60 deletions
@@ -7,14 +7,11 @@ package org.mifosplatform.organisation.office.service;
import java.util.Collection;
import org.mifosplatform.infrastructure.core.domain.MifosPlatformTenant;
import org.mifosplatform.organisation.office.data.OfficeData;
import org.mifosplatform.organisation.office.data.OfficeTransactionData;
public interface OfficeReadPlatformService {
MifosPlatformTenant loadTenantById(String tenantIdentifier);
Collection<OfficeData> retrieveAllOffices(boolean includeAllOffices);
Collection<OfficeData> retrieveAllOfficesForDropdown();
@@ -11,13 +11,9 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import javax.sql.DataSource;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.domain.MifosPlatformTenant;
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.mifosplatform.infrastructure.security.exception.InvalidTenantIdentiferException;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.data.CurrencyData;
import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService;
@@ -26,7 +22,6 @@ import org.mifosplatform.organisation.office.data.OfficeTransactionData;
import org.mifosplatform.organisation.office.exception.OfficeNotFoundException;
import org.mifosplatform.useradministration.domain.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -37,19 +32,16 @@ import org.springframework.stereotype.Service;
public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final JdbcTemplate tenantsJdbcTemplate;
private final PlatformSecurityContext context;
private final CurrencyReadPlatformService currencyReadPlatformService;
private final static String nameDecoratedBaseOnHierarchy = "concat(substring('........................................', 1, ((LENGTH(o.hierarchy) - LENGTH(REPLACE(o.hierarchy, '.', '')) - 1) * 4)), o.name)";
@Autowired
public OfficeReadPlatformServiceImpl(final PlatformSecurityContext context,
final CurrencyReadPlatformService currencyReadPlatformService, final RoutingDataSource dataSource,
@Qualifier("tenantDataSourceJndi") final DataSource tenantsJndiDataSource) {
final CurrencyReadPlatformService currencyReadPlatformService, final RoutingDataSource dataSource) {
this.context = context;
this.currencyReadPlatformService = currencyReadPlatformService;
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.tenantsJdbcTemplate = new JdbcTemplate(tenantsJndiDataSource);
}
private static final class OfficeMapper implements RowMapper<OfficeData> {
@@ -134,7 +126,6 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
}
}
/** TODO: Vishwas This change breaks caching, need to have a relook **/
@Override
@Cacheable(value = "offices", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'of')")
public Collection<OfficeData> retrieveAllOffices(final boolean includeAllOffices) {
@@ -243,48 +234,4 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
public PlatformSecurityContext getContext() {
return this.context;
}
@Override
@Cacheable(value = "tenantsById", key = "#tenantIdentifier")
public MifosPlatformTenant loadTenantById(final String tenantIdentifier) {
try {
final TenantMapper rm = new TenantMapper();
final String sql = "select " + rm.schema() + " where t.identifier like ?";
return this.tenantsJdbcTemplate.queryForObject(sql, rm, new Object[] { tenantIdentifier });
} catch (final EmptyResultDataAccessException e) {
throw new InvalidTenantIdentiferException("The tenant identifier: " + tenantIdentifier + " is not valid.");
}
}
private static final class TenantMapper implements RowMapper<MifosPlatformTenant> {
private final StringBuilder sqlBuilder = new StringBuilder(
"id, name,identifier, schema_name as schemaName, schema_server as schemaServer, schema_server_port as schemaServerPort, auto_update as autoUpdate, ")//
.append(" schema_username as schemaUsername, schema_password as schemaPassword , timezone_id as timezoneId ")//
.append(" from tenants t");//
public String schema() {
return this.sqlBuilder.toString();
}
@Override
public MifosPlatformTenant mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
final Long id = rs.getLong("id");
final String tenantIdentifier = rs.getString("identifier");
final String name = rs.getString("name");
final String schemaName = rs.getString("schemaName");
final String schemaServer = rs.getString("schemaServer");
final String schemaServerPort = rs.getString("schemaServerPort");
final String schemaUsername = rs.getString("schemaUsername");
final String schemaPassword = rs.getString("schemaPassword");
final String timezoneId = rs.getString("timezoneId");
final boolean autoUpdateEnabled = rs.getBoolean("autoUpdate");
return new MifosPlatformTenant(id, tenantIdentifier, name, schemaName, schemaServer, schemaServerPort, schemaUsername,
schemaPassword, timezoneId, autoUpdateEnabled);
}
}
}
@@ -34,6 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Caching;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -67,7 +68,9 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
@Transactional
@Override
@CacheEvict(value = "usersByUsername", allEntries = true)
@Caching(evict = {
@CacheEvict(value = "users", allEntries = true),
@CacheEvict(value = "usersByUsername", allEntries = true)})
public CommandProcessingResult createUser(final JsonCommand command) {
try {
@@ -111,7 +114,9 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
@Transactional
@Override
@CacheEvict(value = "usersByUsername", allEntries = true)
@Caching(evict = {
@CacheEvict(value = "users", allEntries = true),
@CacheEvict(value = "usersByUsername", allEntries = true)})
public CommandProcessingResult updateUser(final Long userId, final JsonCommand command) {
try {
@@ -172,7 +177,9 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
@Transactional
@Override
@CacheEvict(value = "usersByUsername", allEntries = true)
@Caching(evict = {
@CacheEvict(value = "users", allEntries = true),
@CacheEvict(value = "usersByUsername", allEntries = true)})
public CommandProcessingResult deleteUser(final Long userId) {
final AppUser user = this.appUserRepository.findOne(userId);
@@ -6,6 +6,9 @@
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<defaultCache eternal="true" maxEntriesLocalHeap="100"
overflowToDisk="false" />
<cache name="users" maxEntriesLocalHeap="10000"
eternal="true" overflowToDisk="false" />
<cache name="usersByUsername" maxEntriesLocalHeap="10000"
eternal="true" overflowToDisk="false" />
<cache name="tenantsById" maxEntriesLocalHeap="10000"