HHH-10181: CacheableFileXmlSource.doBind uses obsolete .bin file

This commit is contained in:
Holger 2015-10-29 22:59:40 +01:00 committed by Steve Ebersole
parent eb2f33328d
commit 6ace838d61
3 changed files with 27 additions and 8 deletions

View File

@ -32,6 +32,7 @@ public class CacheableFileXmlSource extends XmlSource {
private final File xmlFile; private final File xmlFile;
private final File serFile; private final File serFile;
private final boolean strict; private final boolean strict;
private final boolean serFileObsolete;
public CacheableFileXmlSource(Origin origin, File xmlFile, boolean strict) { public CacheableFileXmlSource(Origin origin, File xmlFile, boolean strict) {
super( origin ); super( origin );
@ -40,6 +41,8 @@ public class CacheableFileXmlSource extends XmlSource {
this.serFile = determineCachedFile( xmlFile ); this.serFile = determineCachedFile( xmlFile );
this.serFileObsolete = xmlFile.exists() && serFile.exists() && xmlFile.lastModified() > serFile.lastModified();
if ( strict ) { if ( strict ) {
if ( !serFile.exists() ) { if ( !serFile.exists() ) {
throw new MappingException( throw new MappingException(
@ -47,7 +50,7 @@ public class CacheableFileXmlSource extends XmlSource {
origin origin
); );
} }
if ( xmlFile.exists() && xmlFile.lastModified() > serFile.lastModified() ) { if ( serFileObsolete ) {
throw new MappingException( throw new MappingException(
String.format( "Cached file [%s] could not be used as the mapping file is newer", origin.getName() ), String.format( "Cached file [%s] could not be used as the mapping file is newer", origin.getName() ),
origin origin
@ -83,6 +86,7 @@ public class CacheableFileXmlSource extends XmlSource {
} }
} }
else { else {
if ( !serFileObsolete ) {
try { try {
return readSerFile(); return readSerFile();
} }
@ -92,6 +96,10 @@ public class CacheableFileXmlSource extends XmlSource {
catch ( FileNotFoundException e ) { catch ( FileNotFoundException e ) {
log.cachedFileNotFound( serFile.getName(), e ); log.cachedFileNotFound( serFile.getName(), e );
} }
}
else {
log.cachedFileObsolete( serFile );
}
log.readingMappingsFromFile( xmlFile.getPath() ); log.readingMappingsFromFile( xmlFile.getPath() );
final Binding binding = FileXmlSource.doBind( binder, xmlFile, getOrigin() ); final Binding binding = FileXmlSource.doBind( binder, xmlFile, getOrigin() );

View File

@ -1747,4 +1747,8 @@ public interface CoreMessageLogger extends BasicLogger {
@Message(value = "Hikari properties were encountered, but the Hikari ConnectionProvider was not found on the classpath; these properties are going to be ignored.", @Message(value = "Hikari properties were encountered, but the Hikari ConnectionProvider was not found on the classpath; these properties are going to be ignored.",
id = 472) id = 472)
void hikariProviderClassNotFound(); void hikariProviderClassNotFound();
@LogMessage(level = INFO)
@Message(value = "Omitting cached file [%s] as the mapping file is newer", id = 473)
void cachedFileObsolete(File cachedFile);
} }

View File

@ -59,5 +59,12 @@ public class CacheableFileTest extends BaseUnitTestCase {
assertTrue( mappingBinFile.exists() ); assertTrue( mappingBinFile.exists() );
new Configuration().addCacheableFileStrictly( mappingFile ); new Configuration().addCacheableFileStrictly( mappingFile );
// make mappingBinFile obsolete by declaring it a minute older than mappingFile
mappingBinFile.setLastModified( mappingFile.lastModified() - 60000L );
new Configuration().addCacheableFile( mappingFile );
assertTrue( mappingBinFile.exists() );
assertTrue( "mappingFile should have been recreated.", mappingBinFile.lastModified() >= mappingFile.lastModified());
} }
} }