Skip to content

Commit 5e6a2bf

Browse files
committed
Refactor internal methods from getters to accessors (plus some finals)
1 parent f11ffc5 commit 5e6a2bf

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

ebean-migration/src/main/java/io/ebean/migration/MigrationRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected void run(Connection connection, boolean checkStateOnly) {
101101
MigrationTable table = new MigrationTable(migrationConfig, connection, checkStateOnly, platform);
102102
table.createIfNeededAndLock();
103103
try {
104-
List<LocalMigrationResource> migrations = resources.getVersions();
104+
List<LocalMigrationResource> migrations = resources.versions();
105105
runMigrations(migrations, table, checkStateOnly);
106106
connection.commit();
107107
if (!checkStateOnly) {
@@ -152,7 +152,7 @@ private void runMigrations(List<LocalMigrationResource> localVersions, Migration
152152
private LocalMigrationResource getInitVersion() {
153153
LocalMigrationResources initResources = new LocalMigrationResources(migrationConfig);
154154
if (initResources.readInitResources()) {
155-
List<LocalMigrationResource> initVersions = initResources.getVersions();
155+
List<LocalMigrationResource> initVersions = initResources.versions();
156156
if (!initVersions.isEmpty()) {
157157
return initVersions.get(initVersions.size() - 1);
158158
}

ebean-migration/src/main/java/io/ebean/migration/runner/LocalMigrationResources.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Loads the DB migration resources and sorts them into execution order.
1818
*/
19-
public class LocalMigrationResources {
19+
public final class LocalMigrationResources {
2020

2121
private static final System.Logger log = MigrationSchema.log;
2222

@@ -134,11 +134,10 @@ private LocalMigrationResource createScriptMigration(Resource resource, String f
134134
/**
135135
* Return the list of migration resources in version order.
136136
*/
137-
public List<LocalMigrationResource> getVersions() {
137+
public List<LocalMigrationResource> versions() {
138138
return versions;
139139
}
140140

141-
142141
/**
143142
* Filter used to find the migration scripts.
144143
*/

ebean-migration/src/main/java/io/ebean/migration/runner/MigrationMetaRow.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,25 @@ public String toString() {
5858
/**
5959
* Return the id for this migration.
6060
*/
61-
int getId() {
61+
int id() {
6262
return id;
6363
}
6464

6565
/**
6666
* Return the normalised version for this migration.
6767
*/
68-
String getVersion() {
68+
String version() {
6969
return version;
7070
}
7171

7272
/**
7373
* Return the checksum for this migration.
7474
*/
75-
int getChecksum() {
75+
int checksum() {
7676
return checksum;
7777
}
7878

79-
String getType() {
79+
String type() {
8080
return type;
8181
}
8282

ebean-migration/src/main/java/io/ebean/migration/runner/MigrationScriptRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Runs the DDL migration scripts.
1212
*/
13-
class MigrationScriptRunner {
13+
final class MigrationScriptRunner {
1414

1515
private final Connection connection;
1616

ebean-migration/src/main/java/io/ebean/migration/runner/MigrationTable.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public int size() {
121121
/**
122122
* Returns the versions that are already applied.
123123
*/
124-
public Set<String> getVersions() {
124+
public Set<String> versions() {
125125
return migrations.keySet();
126126
}
127127

@@ -188,7 +188,7 @@ public void unlockMigrationTable() throws SQLException {
188188
*/
189189
private void readExistingMigrations() throws SQLException {
190190
for (MigrationMetaRow metaRow : platform.readExistingMigrations(sqlTable, connection)) {
191-
addMigration(metaRow.getVersion(), metaRow);
191+
addMigration(metaRow.version(), metaRow);
192192
}
193193
}
194194

@@ -207,14 +207,14 @@ void createTable() throws IOException, SQLException {
207207
* Return the create table script.
208208
*/
209209
String createTableDdl() throws IOException {
210-
String script = ScriptTransform.replace("${table}", sqlTable, getCreateTableScript());
210+
String script = ScriptTransform.replace("${table}", sqlTable, createTableScript());
211211
return ScriptTransform.replace("${pk_table}", sqlPrimaryKey(), script);
212212
}
213213

214214
/**
215215
* Return the create table script.
216216
*/
217-
private String getCreateTableScript() throws IOException {
217+
private String createTableScript() throws IOException {
218218
// supply a script to override the default table create script
219219
String script = readResource("migration-support/create-table.sql");
220220
if (script == null && platformName != null && !platformName.isEmpty()) {
@@ -233,15 +233,15 @@ private String getCreateTableScript() throws IOException {
233233
}
234234

235235
private String readResource(String location) throws IOException {
236-
Enumeration<URL> resources = getClassLoader().getResources(location);
236+
Enumeration<URL> resources = classLoader().getResources(location);
237237
if (resources.hasMoreElements()) {
238238
URL url = resources.nextElement();
239239
return IOUtils.readUtf8(url);
240240
}
241241
return null;
242242
}
243243

244-
private ClassLoader getClassLoader() {
244+
private ClassLoader classLoader() {
245245
return Thread.currentThread().getContextClassLoader();
246246
}
247247

@@ -331,7 +331,7 @@ private boolean patchInsertMigration(LocalMigrationResource local, int checksum)
331331
* Return true if the migration should be skipped.
332332
*/
333333
boolean skipMigration(int checksum, LocalMigrationResource local, MigrationMetaRow existing) throws SQLException {
334-
boolean matchChecksum = (existing.getChecksum() == checksum);
334+
boolean matchChecksum = (existing.checksum() == checksum);
335335
if (matchChecksum) {
336336
log.log(TRACE, "skip unchanged migration {0}", local.location());
337337
return true;
@@ -352,7 +352,7 @@ boolean skipMigration(int checksum, LocalMigrationResource local, MigrationMetaR
352352
* Return true if the checksum is reset on the existing migration.
353353
*/
354354
private boolean patchResetChecksum(MigrationMetaRow existing, int newChecksum) throws SQLException {
355-
if (isResetOnVersion(existing.getVersion())) {
355+
if (isResetOnVersion(existing.version())) {
356356
if (!checkStateOnly) {
357357
existing.resetChecksum(newChecksum, connection, updateChecksumSql);
358358
}
@@ -428,16 +428,13 @@ private MigrationMetaRow createInitMetaRow() {
428428
* Create the MigrationMetaRow for this migration.
429429
*/
430430
private MigrationMetaRow createMetaRow(LocalMigrationResource migration, int checksum, long exeMillis) {
431-
432431
int nextId = 1;
433432
if (lastMigration != null) {
434-
nextId = lastMigration.getId() + 1;
433+
nextId = lastMigration.id() + 1;
435434
}
436-
437435
String type = migration.type();
438436
String runVersion = migration.key();
439437
String comment = migration.comment();
440-
441438
return new MigrationMetaRow(nextId, type, runVersion, comment, checksum, envUserName, runOn, exeMillis);
442439
}
443440

@@ -464,17 +461,17 @@ private void addMigration(String key, MigrationMetaRow metaRow) {
464461
return;
465462
}
466463
lastMigration = metaRow;
467-
if (metaRow.getVersion() == null) {
464+
if (metaRow.version() == null) {
468465
throw new IllegalStateException("No runVersion in db migration table row? " + metaRow);
469466
}
470467

471468
migrations.put(key, metaRow);
472-
if (VERSION_TYPE.equals(metaRow.getType()) || BOOTINIT_TYPE.equals(metaRow.getType())) {
473-
MigrationVersion rowVersion = MigrationVersion.parse(metaRow.getVersion());
469+
if (VERSION_TYPE.equals(metaRow.type()) || BOOTINIT_TYPE.equals(metaRow.type())) {
470+
MigrationVersion rowVersion = MigrationVersion.parse(metaRow.version());
474471
if (currentVersion == null || rowVersion.compareTo(currentVersion) > 0) {
475472
currentVersion = rowVersion;
476473
}
477-
if (BOOTINIT_TYPE.equals(metaRow.getType())) {
474+
if (BOOTINIT_TYPE.equals(metaRow.type())) {
478475
dbInitVersion = rowVersion;
479476
}
480477
}
@@ -555,6 +552,9 @@ public int runNonTransactional() {
555552
return scriptRunner.runNonTransactional();
556553
}
557554

555+
/**
556+
* Return the count of migrations that were run.
557+
*/
558558
public int count() {
559559
return executionCount;
560560
}

ebean-migration/src/test/java/io/ebean/migration/MigrationTableTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testMigrationTableBase() throws Exception {
5252
try (Connection conn = dataSource.getConnection()) {
5353
MigrationTable table = new MigrationTable(config, conn, false, platform);
5454
table.createIfNeededAndLock();
55-
assertThat(table.getVersions()).containsExactly("hello", "1.1", "1.2", "1.2.1", "m2_view");
55+
assertThat(table.versions()).containsExactly("hello", "1.1", "1.2", "1.2.1", "m2_view");
5656

5757
List<String> rawVersions = new ArrayList<>();
5858
try (PreparedStatement stmt = conn.prepareStatement("select mversion from db_migration order by id")) {
@@ -79,7 +79,7 @@ public void testMigrationTableRepeatableOk() throws Exception {
7979
try (Connection conn = dataSource.getConnection()) {
8080
MigrationTable table = new MigrationTable(config, conn, false, platform);
8181
table.createIfNeededAndLock();
82-
assertThat(table.getVersions()).containsExactly("1.1");
82+
assertThat(table.versions()).containsExactly("1.1");
8383
table.unlockMigrationTable();
8484
conn.rollback();
8585
}
@@ -92,7 +92,7 @@ public void testMigrationTableRepeatableOk() throws Exception {
9292
try (Connection conn = dataSource.getConnection()) {
9393
MigrationTable table = new MigrationTable(config, conn, false, platform);
9494
table.createIfNeededAndLock();
95-
assertThat(table.getVersions()).containsExactly("1.1", "1.2", "m2_view");
95+
assertThat(table.versions()).containsExactly("1.1", "1.2", "m2_view");
9696
table.unlockMigrationTable();
9797
conn.rollback();
9898
}
@@ -110,7 +110,7 @@ public void testMigrationTableRepeatableFail() throws Exception {
110110
try (Connection conn = dataSource.getConnection()) {
111111
MigrationTable table = new MigrationTable(config, conn, false, platform);
112112
table.createIfNeededAndLock();
113-
assertThat(table.getVersions()).containsExactly("1.1");
113+
assertThat(table.versions()).containsExactly("1.1");
114114
table.unlockMigrationTable();
115115
conn.rollback();
116116
}
@@ -143,7 +143,7 @@ public void testMigrationTableRepeatableFail() throws Exception {
143143
// we expect, that 1.1 and 1.2 is executed (but not the R__ script)
144144
MigrationTable table = new MigrationTable(config, conn, false, platform);
145145
table.createIfNeededAndLock();
146-
assertThat(table.getVersions()).containsExactly("1.1", "1.2");
146+
assertThat(table.versions()).containsExactly("1.1", "1.2");
147147
conn.rollback();
148148
}
149149
}

0 commit comments

Comments
 (0)