Skip to content
Snippets Groups Projects
Commit 3df54121 authored by fedoreno's avatar fedoreno
Browse files

SSDM-2294: V3 AS API - paging and sorting of search results (ehcache)

SVN: 34484
parent 0bec901c
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,9 @@ dependencies {
'apache:poi-ooxml:3.8-20120326',
'hibernate:hibernate-validator:4.2.0.Final',
'unimi:fastutil:5.1.5',
'apache:commons-collections:+'
'apache:commons-collections:+',
'springframework:spring-context-support:+',
'ehcache:ehcache:2.10.0'
runtime 'slf4j:slf4j-log4j12:+'
......
......@@ -26,6 +26,7 @@ import org.springframework.stereotype.Component;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.executor.material.ISearchMaterialIdExecutor;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.ITranslationContextProvider;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext;
import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.material.sql.IMaterialSqlTranslator;
import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.Material;
......@@ -45,6 +46,9 @@ public class SearchMaterialSqlMethodExecutor extends AbstractMethodExecutor impl
@Autowired
private IMaterialSqlTranslator translator;
@Autowired
private ITranslationContextProvider contextProvider;
@Override
public List<Material> search(final String sessionToken, final MaterialSearchCriterion criterion, final MaterialFetchOptions fetchOptions)
{
......@@ -86,21 +90,16 @@ public class SearchMaterialSqlMethodExecutor extends AbstractMethodExecutor impl
return Collections.emptyList();
}
TranslationContext translationContext = null;
Integer cacheMode = fetchOptions.getCacheMode();
cacheMode = cacheMode == null ? 0 : cacheMode;
if (fetchOptions.getCacheMode() != null)
{
translationContext = (TranslationContext) context.getSession().getAttributes().get(getClass().getName() + "_context");
if (translationContext == null)
{
translationContext = new TranslationContext(context.getSession());
context.getSession().getAttributes().put(getClass().getName() + "_context", translationContext);
}
} else
if (cacheMode == 999) // TODO
{
translationContext = new TranslationContext(context.getSession());
contextProvider.discardTranslationContext(context.getSession());
}
TranslationContext translationContext = contextProvider.getTranslationContext(context.getSession(), cacheMode > 0);
Map<Long, Material> peToObjectMap = translator.translate(translationContext, peList, fetchOptions);
return new ArrayList<Material>(peToObjectMap.values());
}
......
/*
* Copyright 2013 ETH Zuerich, CISD
*
* 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 ch.ethz.sis.openbis.generic.server.api.v3.translator;
import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
public interface ITranslationContextProvider
{
/**
* Get the translation context for the current session
*
* @param session
* @param useCache whether to cache the context for later use
* @return
*/
TranslationContext getTranslationContext(Session session, boolean useCache);
/**
* Optional call to notify the server that the corresponding session context is not going to be used ever
*
* @param session
*/
void discardTranslationContext(Session session);
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ public class TranslationContext extends Context
public TranslationCache getTranslationCache()
{
return translationCache;
}
......
/*
* Copyright 2013 ETH Zuerich, CISD
*
* 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 ch.ethz.sis.openbis.generic.server.api.v3.translator;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
@Component
public class TranslationContextProvider implements ITranslationContextProvider
{
@Override
@Cacheable(value = "searchCache", key = "#session.getSessionToken()", condition = "#useCache")
public TranslationContext getTranslationContext(Session session, boolean useCache)
{
return new TranslationContext(session);
}
@Override
@CacheEvict(value = "searchCache", key = "#session.getSessionToken()")
public void discardTranslationContext(Session session)
{
// aop noop
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<diskStore path="java.io.tmpdir" />
<diskStore path="java.io.tmpdir" />
<!--
// The default cache configuration for (see warnings in the server startup log):
// * ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPropertyPE
// * ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPropertyPE
// * ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE.materialProperties
// * ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE.experimentProperties
// and:
// * org.hibernate.cache.UpdateTimestampsCache
// * org.hibernate.cache.StandardQueryCache
-->
<defaultCache maxElementsInMemory="1000000" eternal="true" overflowToDisk="false"
diskPersistent="false" memoryStoreEvictionPolicy="LFU" />
<!-- // The default cache configuration for (see warnings in the server
startup log): // * ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPropertyPE
// * ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPropertyPE //
* ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE.materialProperties
// * ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE.experimentProperties
// and: // * org.hibernate.cache.UpdateTimestampsCache // * org.hibernate.cache.StandardQueryCache -->
<defaultCache maxElementsInMemory="1000000" eternal="true"
overflowToDisk="false" diskPersistent="false"
memoryStoreEvictionPolicy="LFU" />
<cache name="searchCache" eternal="false" maxElementsInMemory="100"
overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
timeToLiveSeconds="300" memoryStoreEvictionPolicy="LRU" />
</ehcache>
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment