001package io.ebeaninternal.dbmigration.model; 002 003import io.ebean.migration.MigrationVersion; 004import io.ebeaninternal.dbmigration.migration.Migration; 005import io.ebeaninternal.dbmigration.migrationreader.MigrationXmlReader; 006 007import java.io.File; 008 009/** 010 * Migration XML resource that holds the changes to be applied. 011 */ 012public class MigrationResource implements Comparable<MigrationResource> { 013 014 private final File migrationFile; 015 016 private final MigrationVersion version; 017 018 /** 019 * Construct with a migration xml file. 020 */ 021 public MigrationResource(File migrationFile, MigrationVersion version) { 022 this.migrationFile = migrationFile; 023 this.version = version; 024 } 025 026 @Override 027 public String toString() { 028 return migrationFile.getName(); 029 } 030 031 /** 032 * Return the version associated with this resource. 033 */ 034 public MigrationVersion version() { 035 return version; 036 } 037 038 /** 039 * Read and return the migration from the resource. 040 */ 041 public Migration read() { 042 return MigrationXmlReader.read(migrationFile); 043 } 044 045 /** 046 * Compare by underlying version. 047 */ 048 @Override 049 public int compareTo(MigrationResource other) { 050 return version.compareTo(other.version); 051 } 052}