Search in sources :

Example 1 with FileTimeStampChecker

use of org.hibernate.jpamodelgen.util.FileTimeStampChecker in project hibernate-orm by hibernate.

the class JpaDescriptorParser method mappingFilesUnchanged.

private boolean mappingFilesUnchanged(Collection<String> mappingFileNames) {
    boolean mappingFilesUnchanged = false;
    FileTimeStampChecker fileStampCheck = new FileTimeStampChecker();
    for (String mappingFile : mappingFileNames) {
        try {
            URL url = this.getClass().getResource(mappingFile);
            if (url == null) {
                continue;
            }
            File file = new File(url.toURI());
            context.logMessage(Diagnostic.Kind.OTHER, "Check file  " + mappingFile);
            if (file.exists()) {
                fileStampCheck.add(mappingFile, file.lastModified());
            }
        } catch (URISyntaxException e) {
            // in doubt return false
            return false;
        }
    }
    FileTimeStampChecker serializedTimeStampCheck = loadTimeStampCache();
    if (serializedTimeStampCheck.equals(fileStampCheck)) {
        context.logMessage(Diagnostic.Kind.OTHER, "XML parsing will be skipped due to unchanged xml files");
        mappingFilesUnchanged = true;
    } else {
        saveTimeStampCache(fileStampCheck);
    }
    return mappingFilesUnchanged;
}
Also used : FileTimeStampChecker(org.hibernate.jpamodelgen.util.FileTimeStampChecker) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URL(java.net.URL)

Example 2 with FileTimeStampChecker

use of org.hibernate.jpamodelgen.util.FileTimeStampChecker in project hibernate-orm by hibernate.

the class JpaDescriptorParser method loadTimeStampCache.

private FileTimeStampChecker loadTimeStampCache() {
    FileTimeStampChecker serializedTimeStampCheck = new FileTimeStampChecker();
    File file = null;
    try {
        file = getSerializationTmpFile();
        if (file.exists()) {
            ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
            serializedTimeStampCheck = (FileTimeStampChecker) in.readObject();
            in.close();
        }
    } catch (Exception e) {
        // ignore - if the de-serialization failed we just have to keep parsing the xml
        context.logMessage(Diagnostic.Kind.OTHER, "Error de-serializing  " + file);
    }
    return serializedTimeStampCheck;
}
Also used : FileTimeStampChecker(org.hibernate.jpamodelgen.util.FileTimeStampChecker) File(java.io.File) FileInputStream(java.io.FileInputStream) URISyntaxException(java.net.URISyntaxException) XmlParsingException(org.hibernate.jpamodelgen.util.xml.XmlParsingException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 FileTimeStampChecker (org.hibernate.jpamodelgen.util.FileTimeStampChecker)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 URL (java.net.URL)1 XmlParsingException (org.hibernate.jpamodelgen.util.xml.XmlParsingException)1