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

(cherry picked from commit 6ace838d61)
This commit is contained in:
Holger 2015-10-29 22:59:40 +01:00 committed by Steve Ebersole
parent 315e57c6aa
commit 9ffc80da5a
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 serFile;
private final boolean strict;
private final boolean serFileObsolete;
public CacheableFileXmlSource(Origin origin, File xmlFile, boolean strict) {
super( origin );
@ -40,6 +41,8 @@ public class CacheableFileXmlSource extends XmlSource {
this.serFile = determineCachedFile( xmlFile );
this.serFileObsolete = xmlFile.exists() && serFile.exists() && xmlFile.lastModified() > serFile.lastModified();
if ( strict ) {
if ( !serFile.exists() ) {
throw new MappingException(
@ -47,7 +50,7 @@ public class CacheableFileXmlSource extends XmlSource {
origin
);
}
if ( xmlFile.exists() && xmlFile.lastModified() > serFile.lastModified() ) {
if ( serFileObsolete ) {
throw new MappingException(
String.format( "Cached file [%s] could not be used as the mapping file is newer", origin.getName() ),
origin
@ -83,14 +86,19 @@ public class CacheableFileXmlSource extends XmlSource {
}
}
else {
try {
return readSerFile();
if ( !serFileObsolete ) {
try {
return readSerFile();
}
catch ( SerializationException e ) {
log.unableToDeserializeCache( serFile.getName(), e );
}
catch ( FileNotFoundException e ) {
log.cachedFileNotFound( serFile.getName(), e );
}
}
catch ( SerializationException e ) {
log.unableToDeserializeCache( serFile.getName(), e );
}
catch ( FileNotFoundException e ) {
log.cachedFileNotFound( serFile.getName(), e );
else {
log.cachedFileObsolete( serFile );
}
log.readingMappingsFromFile( xmlFile.getPath() );

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.",
id = 472)
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() );
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());
}
}