Skip to content

Commit 07001a6

Browse files
committed
Add PythonScript object in common module for easy interactions with a Python script body and refactor whole PythonProcessor, PythonFileHandler (now PythonFileReader), PythonExecutor and PythonResolver flow
1 parent 8970cd8 commit 07001a6

File tree

77 files changed

+991
-1230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+991
-1230
lines changed

cache/spring-boot-python-executor-cache-autoconfigure/src/main/java/io/w4t3rcs/python/config/PythonCacheAutoConfiguration.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import io.w4t3rcs.python.condition.ResolverCacheLevelCondition;
1010
import io.w4t3rcs.python.executor.CachingPythonExecutor;
1111
import io.w4t3rcs.python.executor.PythonExecutor;
12-
import io.w4t3rcs.python.file.CachingPythonFileHandler;
13-
import io.w4t3rcs.python.file.PythonFileHandler;
12+
import io.w4t3rcs.python.file.CachingPythonFileReader;
13+
import io.w4t3rcs.python.file.PythonFileReader;
1414
import io.w4t3rcs.python.processor.CachingPythonProcessor;
1515
import io.w4t3rcs.python.processor.PythonProcessor;
1616
import io.w4t3rcs.python.properties.PythonCacheProperties;
@@ -36,7 +36,7 @@
3636
* </p>
3737
* <p>
3838
* Provides default {@link CacheKeyGenerator} and caching wrappers for
39-
* {@link PythonFileHandler}, {@link PythonResolverHolder}, {@link PythonExecutor}, and {@link PythonProcessor}
39+
* {@link PythonFileReader}, {@link PythonResolverHolder}, {@link PythonExecutor}, and {@link PythonProcessor}
4040
* beans if present in the context.
4141
* </p>
4242
* <p>
@@ -50,7 +50,7 @@
5050
*
5151
* @see PythonCacheProperties
5252
* @see CacheKeyGenerator
53-
* @see CachingPythonFileHandler
53+
* @see CachingPythonFileReader
5454
* @see CachingPythonResolverHolder
5555
* @see CachingPythonExecutor
5656
* @see CachingPythonProcessor
@@ -76,22 +76,22 @@ public CacheKeyGenerator cacheKeyGenerator(PythonCacheProperties cacheProperties
7676
}
7777

7878
/**
79-
* Wraps the existing {@link PythonFileHandler} with caching capabilities
79+
* Wraps the existing {@link PythonFileReader} with caching capabilities
8080
* when file cache level is enabled.
8181
*
8282
* @param cacheProperties non-null Python cache configuration properties
83-
* @param pythonFileHandler non-null delegate {@link PythonFileHandler} bean
83+
* @param pythonFileReader non-null delegate {@link PythonFileReader} bean
8484
* @param cacheManager non-null Spring cache manager for cache resolution
85-
* @return a caching-enabled {@link PythonFileHandler} bean marked as primary
85+
* @return a caching-enabled {@link PythonFileReader} bean marked as primary
8686
*/
8787
@Bean
8888
@Primary
89-
@ConditionalOnBean(PythonFileHandler.class)
89+
@ConditionalOnBean(PythonFileReader.class)
9090
@Conditional(FileCacheLevelCondition.class)
91-
public PythonFileHandler cachingPythonFileHandler(PythonCacheProperties cacheProperties,
92-
PythonFileHandler pythonFileHandler,
93-
CacheManager cacheManager) {
94-
return new CachingPythonFileHandler(cacheProperties, pythonFileHandler, cacheManager);
91+
public PythonFileReader cachingPythonFileHandler(PythonCacheProperties cacheProperties,
92+
PythonFileReader pythonFileReader,
93+
CacheManager cacheManager) {
94+
return new CachingPythonFileReader(cacheProperties, pythonFileReader, cacheManager);
9595
}
9696

9797
/**

cache/spring-boot-python-executor-cache-autoconfigure/src/test/java/io/w4t3rcs/python/CachingPythonLevelConfigurationTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import io.w4t3rcs.python.config.PythonCacheAutoConfiguration;
44
import io.w4t3rcs.python.executor.CachingPythonExecutor;
55
import io.w4t3rcs.python.executor.PythonExecutor;
6-
import io.w4t3rcs.python.file.CachingPythonFileHandler;
7-
import io.w4t3rcs.python.file.PythonFileHandler;
6+
import io.w4t3rcs.python.file.CachingPythonFileReader;
7+
import io.w4t3rcs.python.file.PythonFileReader;
88
import io.w4t3rcs.python.processor.CachingPythonProcessor;
99
import io.w4t3rcs.python.processor.PythonProcessor;
1010
import io.w4t3rcs.python.resolver.CachingPythonResolverHolder;
@@ -37,14 +37,14 @@ class CachingPythonLevelConfigurationTests {
3737
@TestPropertySource(properties = "spring.python.cache.levels=file")
3838
class OnlyFileTests {
3939
@Autowired
40-
private PythonFileHandler pythonFileHandler;
40+
private PythonFileReader pythonFileReader;
4141
@Autowired
42-
private List<PythonFileHandler> pythonFileHandlers;
42+
private List<PythonFileReader> pythonFileReaders;
4343

4444
@Test
4545
void testMandatoryBeansLoad() {
46-
Assertions.assertInstanceOf(CachingPythonFileHandler.class, pythonFileHandler);
47-
Assertions.assertEquals(2, pythonFileHandlers.size());
46+
Assertions.assertInstanceOf(CachingPythonFileReader.class, pythonFileReader);
47+
Assertions.assertEquals(2, pythonFileReaders.size());
4848
}
4949
}
5050

@@ -97,7 +97,7 @@ void testMandatoryBeansLoad() {
9797
@TestPropertySource(properties = "spring.python.cache.levels=file, resolver, executor, processor")
9898
class MultipleLevelsTests {
9999
@Autowired
100-
private PythonFileHandler pythonFileHandler;
100+
private PythonFileReader pythonFileReader;
101101
@Autowired
102102
private PythonResolverHolder pythonResolverHolder;
103103
@Autowired
@@ -107,7 +107,7 @@ class MultipleLevelsTests {
107107

108108
@Test
109109
void testMandatoryBeansLoad() {
110-
Assertions.assertInstanceOf(CachingPythonFileHandler.class, pythonFileHandler);
110+
Assertions.assertInstanceOf(CachingPythonFileReader.class, pythonFileReader);
111111
Assertions.assertInstanceOf(CachingPythonResolverHolder.class, pythonResolverHolder);
112112
Assertions.assertInstanceOf(CachingPythonExecutor.class, pythonExecutor);
113113
Assertions.assertInstanceOf(CachingPythonProcessor.class, pythonProcessor);
@@ -117,8 +117,8 @@ void testMandatoryBeansLoad() {
117117
@TestConfiguration
118118
static class TestBeansConfiguration {
119119
@Bean
120-
public PythonFileHandler pythonFileHandler() {
121-
return Mockito.mock(PythonFileHandler.class);
120+
public PythonFileReader pythonFileHandler() {
121+
return Mockito.mock(PythonFileReader.class);
122122
}
123123

124124
@Bean

cache/spring-boot-python-executor-cache/src/main/java/io/w4t3rcs/python/cache/impl/HashCacheKeyGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io.w4t3rcs.python.cache.CacheKeyGenerator;
44
import io.w4t3rcs.python.exception.CacheKeyGenerationException;
55
import io.w4t3rcs.python.executor.CachingPythonExecutor;
6-
import io.w4t3rcs.python.file.CachingPythonFileHandler;
6+
import io.w4t3rcs.python.file.CachingPythonFileReader;
77
import io.w4t3rcs.python.processor.CachingPythonProcessor;
88
import io.w4t3rcs.python.properties.PythonCacheProperties;
99
import io.w4t3rcs.python.resolver.CachingPythonResolverHolder;
@@ -33,7 +33,7 @@
3333
*
3434
* @see CacheKeyGenerator
3535
* @see PythonCacheProperties.KeyProperties
36-
* @see CachingPythonFileHandler
36+
* @see CachingPythonFileReader
3737
* @see CachingPythonResolverHolder
3838
* @see CachingPythonExecutor
3939
* @see CachingPythonProcessor

cache/spring-boot-python-executor-cache/src/main/java/io/w4t3rcs/python/exception/PythonCacheException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.w4t3rcs.python.exception;
22

33
import io.w4t3rcs.python.executor.CachingPythonExecutor;
4-
import io.w4t3rcs.python.file.CachingPythonFileHandler;
4+
import io.w4t3rcs.python.file.CachingPythonFileReader;
55
import io.w4t3rcs.python.processor.CachingPythonProcessor;
66
import io.w4t3rcs.python.resolver.CachingPythonResolverHolder;
77

@@ -12,7 +12,7 @@
1212
* handling in the Python integration context.
1313
* </p>
1414
*
15-
* @see CachingPythonFileHandler
15+
* @see CachingPythonFileReader
1616
* @see CachingPythonResolverHolder
1717
* @see CachingPythonExecutor
1818
* @see CachingPythonProcessor

cache/spring-boot-python-executor-cache/src/main/java/io/w4t3rcs/python/executor/CachingPythonExecutor.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.w4t3rcs.python.dto.PythonExecutionResponse;
55
import io.w4t3rcs.python.exception.PythonCacheException;
66
import io.w4t3rcs.python.properties.PythonCacheProperties;
7+
import io.w4t3rcs.python.script.PythonScript;
78
import org.springframework.cache.Cache;
89
import org.springframework.cache.CacheManager;
910

@@ -71,17 +72,15 @@ public CachingPythonExecutor(PythonCacheProperties cacheProperties, PythonExecut
7172
*/
7273
@Override
7374
@SuppressWarnings("unchecked")
74-
public <R> PythonExecutionResponse<R> execute(String script, Class<? extends R> resultClass) {
75+
public <R> PythonExecutionResponse<R> execute(PythonScript script, Class<? extends R> resultClass) {
7576
try {
76-
String key = keyGenerator.generateKey(script, resultClass);
77+
String scriptBody = script.toString();
78+
String key = keyGenerator.generateKey(scriptBody, resultClass);
7779
PythonExecutionResponse<R> cachedResult = (PythonExecutionResponse<R>) cache.get(key, PythonExecutionResponse.class);
78-
if (cachedResult != null) {
79-
return cachedResult;
80-
} else {
81-
PythonExecutionResponse<R> result = pythonExecutor.execute(script, resultClass);
82-
cache.put(key, result);
83-
return result;
84-
}
80+
if (cachedResult != null) return cachedResult;
81+
PythonExecutionResponse<R> result = pythonExecutor.execute(script, resultClass);
82+
cache.put(key, result);
83+
return result;
8584
} catch (Exception e) {
8685
throw new PythonCacheException(e);
8786
}

0 commit comments

Comments
 (0)