Skip to content

Commit 8d20ac3

Browse files
committed
Change SQLDatabaseConnectionImpl#synchronizeModel behaviour
1 parent e10c4fc commit 8d20ac3

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

api/src/main/java/me/zort/sqllib/api/data/QueryResult.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public interface QueryResult {
1313
@Nullable
1414
String getRejectMessage();
1515

16+
QueryResult noChangesResult = successful();
17+
1618
static QueryResult successful() {
1719
return new QueryResult() {
1820
@Override

core/src/main/java/me/zort/sqllib/SQLDatabaseConnectionImpl.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public void enableCaching(CacheManager cacheManager) {
183183
* <i>Warning:</i> This tries to update all tables that are part of mapping
184184
* proxies. Should be used carefully.
185185
*
186-
* @return True if synchronization was successful
186+
* @return True if there were any changes
187187
*/
188188
@ApiStatus.Experimental
189189
@Override
@@ -192,7 +192,7 @@ public boolean synchronizeModel() {
192192
.stream().flatMap(i -> i.getTableSchemas(
193193
getOptions().getNamingStrategy(),
194194
this instanceof SQLiteDatabaseConnectionImpl).stream())
195-
.allMatch(schema -> synchronizeModel(schema, schema.getTable()));
195+
.anyMatch(schema -> synchronizeModel(schema, schema.getTable()));
196196
}
197197

198198
/**
@@ -202,13 +202,14 @@ public boolean synchronizeModel() {
202202
*
203203
* @param entitySchema Entity schema
204204
* @param table Table name
205-
* @return True if synchronization was successful
205+
* @return True if there were any changes
206206
*/
207207
@ApiStatus.Experimental
208208
@Override
209209
public boolean synchronizeModel(TableSchema entitySchema, String table) {
210-
return getSchemaSynchronizer().synchronize(this, entitySchema,
211-
getSchemaBuilder(table).buildTableSchema()).isSuccessful();
210+
QueryResult result = getSchemaSynchronizer().synchronize(this, entitySchema,
211+
getSchemaBuilder(table).buildTableSchema());
212+
return result != QueryResult.noChangesResult && result.isSuccessful();
212213
}
213214

214215
/**
@@ -219,7 +220,7 @@ public boolean synchronizeModel(TableSchema entitySchema, String table) {
219220
*
220221
* @param entity The entity (model) class
221222
* @param table Table name
222-
* @return True if synchronization was successful
223+
* @return True if there were any changes
223224
*/
224225
@ApiStatus.Experimental
225226
@Override

core/src/main/java/me/zort/sqllib/model/SQLSchemaSynchronizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public QueryResult synchronize(SQLDatabaseConnection source, TableSchema from, T
2727
}
2828
}
2929
}
30-
return query.length() == 0 ? QueryResult.successful() : source.exec(query.toString());
30+
return query.length() == 0 ? QueryResult.noChangesResult : source.exec(query.toString());
3131
}
3232
}

src/test/java/me/zort/sqllib/test/TestCase2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public void test2_Synchronization() {
8383
assertEquals(2, dbSchema.getDefinitions().length);
8484
assertEquals("nickname VARCHAR(255) PRIMARY KEY", dbSchema.getDefinitions()[0]);
8585
assertEquals("points INTEGER", dbSchema.getDefinitions()[1]);
86-
assertTrue(connection.synchronizeModel(schema, "users"));
87-
assertTrue(connection.synchronizeModel());
86+
assertFalse(connection.synchronizeModel(schema, "users"));
87+
assertFalse(connection.synchronizeModel());
8888
}
8989

9090
@Timeout(5)

0 commit comments

Comments
 (0)