Reputation: 3127
I am using services and the code generator to manage the interface to my database and execute the queries. It's really good, I love this approach but with many queries the implementing class is very long. This is my interface:
@ProxyGen
@VertxGen
public interface DatabaseService {
@GenIgnore
static DatabaseService create(MySQLPool dbClient, Handler<AsyncResult<DatabaseService>> readyHandler) {
return new DatabaseServiceImpl(dbClient, readyHandler);
}
@GenIgnore
static DatabaseService createProxy(Vertx vertx, String address) {
return new DatabaseServiceVertxEBProxy(vertx, address);
}
// ====== DESKTOP ====== //
@Fluent
DatabaseService listNonPreviste(Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService addNonPreviste(String descr, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService deleteNonPreviste(String id, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService editNonPreviste(String id, String value, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService checkDeleteNonPreviste(String id, Handler<AsyncResult<Integer>> handler);
@Fluent
DatabaseService listModifiche(String anno, String mese, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService addModifiche(String operatore, String motivazione, String campo, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService listLavorazioni(Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService addLavorazioni(String descr, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService deleteLavorazioni(String id, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService editLavorazioni(String id, String value, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService checkDeleteLavorazioni(String id, Handler<AsyncResult<Integer>> handler);
@Fluent
DatabaseService listComponenti(Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService addComponenti(String descr, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService deleteComponenti(String id, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService editComponenti(String id, String value, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService checkDeleteComponenti(String id, Handler<AsyncResult<Integer>> handler);
@Fluent
DatabaseService listRelazioniComponenti(String id, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService listNonRelazioniComponenti(String id, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService addRelazioniComponenti(String componente, String lavorazione, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService deleteRelazioniComponenti(String componente, String lavorazione, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService listOperatori(Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService addOperatori(String nome, String cognome, String ufficio, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService deleteOperatori(String id, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService checkDeleteOperatori(String id, Handler<AsyncResult<Integer>> handler);
@Fluent
DatabaseService editOperatori(String id, String field, String value, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService listRelazioniOperatori(String id, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService listNonRelazioniOperatori(String id, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService addRelazioniOperatori(String operatore, String componente, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService deleteRelazioniOperatori(String operatore, String componente, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService totaleOreMeseOperatore(String id, String data, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService riassuntoGiornalieroOperatore(String id, String data, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService listCommesseAperte(Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService listCommesseChiuse(Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService addCommessa(String codice, String descrizione, String matricola, String quantita, String conclusa, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService deleteCommessa(String id, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService checkDeleteCommessa(String id, Handler<AsyncResult<Integer>> handler);
@Fluent
DatabaseService editCommessa(String id, String field, String value, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService riassuntoCommessaOre(String commessa, String ufficio, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService riassuntoCommessaLavorazioni(String commessa, String lavorazione, String ufficio, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService riassuntoCommessaComponenti(String commessa, String componente, String ufficio, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService commessaLavorazioniOre(String commessa, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService commessaComponentiOre(String commessa, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService listOre(String mese, String anno, String officina, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService addOre(List<String> params, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService addOreConID(List<String> params, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService deleteOre(String id, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService listOreNote(String id, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService listOreNonpreviste(String id, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService editNote(String testo, String id, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService editOreNonPreviste(String nonprevId, String oraId, Handler<AsyncResult<Boolean>> handler);
}
The class DatabaseServiceImpl
implements the interface and is very very long. Is there any way to "split" this interface? Or somehow have the implementing class "smaller" because it's getting very big.
It's still good because all the database logic is in these 2 files so the DB logic is separated from the rest, but classes are getting big and a bit hard to maintain. Thanks, I am using java 12
I have splitted the interface for example like this:
@Fluent
DatabaseService listNonPreviste(Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService addNonPreviste(String descr, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService deleteNonPreviste(String id, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService editNonPreviste(String id, String value, Handler<AsyncResult<Boolean>> handler);
@Fluent
DatabaseService checkDeleteNonPreviste(String id, Handler<AsyncResult<Integer>> handler);
@Fluent
DatabaseService listModifiche(String anno, String mese, Handler<AsyncResult<JsonArray>> handler);
@Fluent
DatabaseService addModifiche(String operatore, String motivazione, String campo, Handler<AsyncResult<Boolean>> handler);
Because there are 2 logical units called "Modifiche" and "Nonpreviste". I'd like to create two classes Modifiche
and Nonpreviste
that implement only the methods that I require.
Upvotes: 0
Views: 58
Reputation: 306
I'm not splitting Interface and its implementation in that similar case becase storage type can be changed and implementation too but methods will be same. Simply devide implementation on commands.
DBImpls class {
NonPrevisteCommands nonPrevisteCommands;
ModificheComands modificheComands;
....
DBImpls() {
this.nonPrevisteCommands = new NonPrevisteCommands();
this.modificheComands = new ModificheComands();
......
}
DatabaseService listNonPreviste(Handler<AsyncResult<JsonArray>> handler){
return this.nonPrevisteCommands.listNonPreviste(handler);
}
DatabaseService addNonPreviste(String descr, Handler<AsyncResult<Boolean>> handler){
return this.nonPrevisteCommands.addNonPreviste(descr, handler);
}
.....
DatabaseService listModifiche(String anno, String mese, Handler<AsyncResult<JsonArray>> handler) {
return this.modificheCommands.listModifiche(descr, handler);
}
......
}
Upvotes: 1