-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache compiled dtables during the building of a KieProject #6097
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,16 +42,16 @@ public class DecisionTableProviderImpl | |
implements | ||
DecisionTableProvider { | ||
|
||
private static final transient Logger logger = LoggerFactory.getLogger( DecisionTableProviderImpl.class ); | ||
private static final Logger logger = LoggerFactory.getLogger( DecisionTableProviderImpl.class ); | ||
|
||
private Map<String, String> compiledDtablesCache = new HashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, @mariofusco . Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you're right. In reality I was thinking to it yesterday when I wrote that code, and I decided that we don't have any situation when we do 2 dtable -> drl conversions in parallel, but I was not properly considering that this is a singleton indeed. Better to play on the safe side on this. I will turn it into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tkobayas done. |
||
|
||
@Override | ||
public String loadFromResource(Resource resource, | ||
DecisionTableConfiguration configuration) { | ||
|
||
try { | ||
return compileResource( resource, configuration ); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException( e ); | ||
} catch (Exception e) { | ||
throw new DecisionTableParseException(resource, e); | ||
} | ||
|
@@ -78,29 +78,45 @@ public List<String> loadFromInputStreamWithTemplates(Resource resource, | |
return drls; | ||
} | ||
|
||
private String compileResource(Resource resource, | ||
DecisionTableConfiguration configuration) throws IOException { | ||
private String compileResource(Resource resource, DecisionTableConfiguration configuration) { | ||
String resourcePath = resource.getSourcePath(); | ||
return resourcePath == null ? | ||
internalCompileResource(resource, configuration) : | ||
compiledDtablesCache.computeIfAbsent(resourcePath, path -> internalCompileResource(resource, configuration)); | ||
} | ||
|
||
private String internalCompileResource(Resource resource, DecisionTableConfiguration configuration) throws UncheckedIOException { | ||
SpreadsheetCompiler compiler = new SpreadsheetCompiler(configuration.isTrimCell()); | ||
|
||
switch ( configuration.getInputType() ) { | ||
case XLS : | ||
case XLSX : | ||
if ( StringUtils.isEmpty( configuration.getWorksheetName() ) ) { | ||
return compiler.compile( resource, | ||
InputType.XLS ); | ||
return compiler.compile( resource, InputType.XLS ); | ||
} else { | ||
return compiler.compile( resource.getInputStream(), | ||
configuration.getWorksheetName() ); | ||
try { | ||
return compiler.compile( resource.getInputStream(), configuration.getWorksheetName() ); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
case CSV : { | ||
return compiler.compile( resource.getInputStream(), | ||
InputType.CSV ); | ||
try { | ||
return compiler.compile( resource.getInputStream(), InputType.CSV ); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void clearCompilerCache() { | ||
compiledDtablesCache.clear(); | ||
} | ||
|
||
@Override | ||
public Map<String, List<String[]>> loadPropertiesFromFile(File file, DecisionTableConfiguration configuration) { | ||
switch (configuration.getInputType()) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I believe that there could be other things that we may want to cache when building a KieProject, so we could eventually perform the clean up of all those caches here.