Architecture Diagram
Core Components
Model
Manages database connections and SQL operations using JDBC
View
Two Swing-based views: login interface and SQL editor interface
Controller
Coordinates user actions, connects views to model logic
Package Structure
The application is organized into a clear package hierarchy:com.app (Root Package)
com.app (Root Package)
Contains the
Main.java entry point that bootstraps the entire application.com.app.Model
com.app.Model
Contains
Model.java - the data access layer that handles all database operations including:- Connection management
- Query execution
- Metadata retrieval
com.app.View
com.app.View
Contains two view classes:
View.java- Login interface for database connectionSqlEditorView.java- Main SQL editor interface with query execution
com.app.Controller
com.app.Controller
Contains
Controller.java which orchestrates interactions between the model and views.Component Interaction Flow
Application Initialization
Main.java creates instances of Model, View, SqlEditorView, and Controller. The editor view is initially hidden.User Authentication
The Controller registers event listeners on the login view. When the user clicks “Connect”, the Controller validates credentials and calls
Model.conectar().Database Connection
The Model establishes a JDBC connection to the MySQL database and retrieves available tables using
Model.obtenerTablasDeBaseDatos().Editor Display
Upon successful connection, the Controller hides the login view and displays the SqlEditorView with the table list populated.
Data Flow
UI to Database
All database operations follow this unidirectional flow, ensuring data consistency and clear responsibility boundaries.
Database to UI
When loading tables or refreshing data:- Controller initiates a request (e.g.,
refrescarTablas()) - Model queries MySQL metadata using
DatabaseMetaData - Model returns a
List<String>of table names - Controller passes the list to the view
- View updates the UI components (JList, JTable)
Asynchronous Operations with SwingWorker
All potentially long-running database operations are executed asynchronously using SwingWorker to prevent UI freezing.
- Loading databases:
obtenerTodasLasBasesDatos() - Connecting to database:
conectar() - Executing queries:
ejecutarConsulta() - Refreshing table list:
obtenerTablasDeBaseDatos()
SwingWorker Pattern Example
- UI remains responsive during database operations
- Proper thread safety (UI updates only on EDT)
- Clean error handling with user feedback
Key Architectural Benefits
Separation of Concerns
Each component has a single, well-defined responsibility
Testability
Model can be tested independently of UI components
Maintainability
Changes to UI don’t affect business logic and vice versa
Scalability
New views or database operations can be added without restructuring
Next Steps
MVC Pattern Deep Dive
Learn how the MVC pattern is implemented in detail
Component Documentation
Explore each component’s methods and responsibilities