Skip to content

Commit b1a670a

Browse files
authored
Merge pull request #5 from canermastan/release/0.3.0
🚀 feat: Add comprehensive database integration system (v0.3.0)
2 parents e21df5d + 0abb330 commit b1a670a

36 files changed

+6677
-458
lines changed

README.md

Lines changed: 155 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,34 @@
22

33
Jazzy is a lightweight web framework for Java. It provides a minimal and easy-to-understand API for developing fast web applications with a structure inspired by Laravel and Spring Boot.
44

5-
## 🚀 Latest Updates (v0.2.0)
5+
## 🚀 Latest Updates (v0.3.0)
66

7-
**NEW: Enterprise-Level Dependency Injection System!**
7+
**NEW: Database Integration & ORM System!**
88

9-
Jazzy Framework 0.2 introduces a comprehensive Spring-like dependency injection system with zero configuration:
9+
Jazzy Framework 0.3 introduces comprehensive database integration with Spring Data JPA-like features:
1010

11-
- 🔧 **Zero Configuration DI**: Automatic component discovery
12-
- 📦 **Spring-like Annotations**: @Component, @Named, @Primary, @PostConstruct, @PreDestroy
13-
- 🔌 **Constructor Injection**: Clean, testable dependency injection
14-
- ⚖️ **Multiple Implementations**: Handle conflicts with @Named and @Primary
15-
- 🔄 **Lifecycle Management**: Proper initialization and cleanup
16-
- 📊 **Scope Management**: @Singleton and @Prototype support
17-
- 🔗 **Framework Integration**: Seamless integration with routing and controllers
11+
- 🗄️ **Hibernate Integration**: Full JPA/Hibernate support with automatic configuration
12+
- 🔍 **Spring Data JPA-like Repositories**: Automatic query generation from method names
13+
- 📝 **Custom Query Support**: @Query annotation for HQL/JPQL and native SQL
14+
- 🔄 **Transaction Management**: Automatic transaction handling
15+
- 🏗️ **Entity Management**: Automatic entity discovery and configuration
16+
- 📊 **Connection Pooling**: HikariCP integration for production-ready performance
17+
- 🎯 **Method Name Parsing**: `findByEmail`, `countByActive`, `existsByName` etc.
18+
-**Performance Optimized**: Database-level filtering instead of memory operations
1819

1920
## Version History
2021

2122
| Version | Release Date | Key Features |
2223
|---------|-------------|--------------|
24+
| **0.3.0** | 2025 | 🆕 **Database Integration** - Hibernate/JPA, Spring Data JPA-like repositories, automatic query generation, transaction management |
2325
| **0.2.0** | 2025 | 🆕 **Dependency Injection System**, Spring-like annotations, automatic component discovery, lifecycle management |
2426
| **0.1.0** | 2025 | Core framework with routing, request/response handling, JSON utilities, validation system, metrics |
2527

2628
### 🔮 Upcoming Features (Roadmap)
2729

2830
| Planned Version | Features |
2931
|----------------|----------|
30-
| **0.3.0** | 🗄️ **Database Integration** - jOOQ integration, connection pooling, transaction management |
32+
| **0.4.0** | 🔐 **Security & Authentication** - JWT support, role-based access control, security filters |
3133

3234
## Features
3335

@@ -48,111 +50,166 @@ Jazzy Framework 0.2 introduces a comprehensive Spring-like dependency injection
4850
- **Scope Management**: @Singleton (default) and @Prototype scopes
4951
- **Framework Integration**: DI works seamlessly with controllers and routing
5052

53+
### Database Integration (v0.3+)
54+
- **Hibernate/JPA Integration**: Full ORM support with automatic configuration
55+
- **Spring Data JPA-like Repositories**: Familiar repository pattern with automatic implementation
56+
- **Method Name Parsing**: Automatic query generation from method names
57+
- **Custom Queries**: @Query annotation for HQL/JPQL and native SQL queries
58+
- **Transaction Management**: Automatic transaction handling with proper rollback
59+
- **Entity Discovery**: Automatic entity scanning and configuration
60+
- **Connection Pooling**: HikariCP for production-ready database connections
61+
5162
## Quick Start
5263

53-
### Basic Application (v0.1 style)
64+
### Database Application (v0.3 style)
5465

5566
```java
56-
// App.java
57-
package examples.basic;
58-
59-
import jazzyframework.core.Config;
60-
import jazzyframework.core.Server;
61-
import jazzyframework.routing.Router;
62-
63-
public class App
64-
{
65-
public static void main( String[] args )
66-
{
67-
Config config = new Config();
68-
config.setEnableMetrics(true); // "/metrics" endpoint is automatically added
69-
config.setServerPort(8088);
70-
71-
Router router = new Router();
72-
73-
// User routes
74-
router.GET("/users/{id}", "getUserById", UserController.class);
75-
router.GET("/users", "getAllUsers", UserController.class);
76-
router.POST("/users", "createUser", UserController.class);
77-
router.PUT("/users/{id}", "updateUser", UserController.class);
78-
router.DELETE("/users/{id}", "deleteUser", UserController.class);
79-
80-
// Start the server
81-
Server server = new Server(router, config);
82-
server.start(config.getServerPort());
83-
}
67+
// Entity
68+
@Entity
69+
@Table(name = "users")
70+
public class User {
71+
@Id
72+
@GeneratedValue(strategy = GenerationType.IDENTITY)
73+
private Long id;
74+
75+
@Column(unique = true)
76+
private String email;
77+
78+
private String name;
79+
private String password;
80+
private boolean active = true;
81+
82+
// getters and setters...
8483
}
85-
```
86-
87-
### With Dependency Injection (v0.2 style)
8884

89-
```java
90-
// Repository Component
91-
@Component
92-
public class UserRepository {
93-
private final List<User> users = new ArrayList<>();
85+
// Repository with automatic query generation
86+
public interface UserRepository extends BaseRepository<User, Long> {
87+
// Automatic query: SELECT u FROM User u WHERE u.email = :email
88+
Optional<User> findByEmail(String email);
9489

95-
@PostConstruct
96-
public void init() {
97-
System.out.println("UserRepository initialized");
98-
}
90+
// Automatic query: SELECT u FROM User u WHERE u.active = :active
91+
List<User> findByActive(boolean active);
9992

100-
public List<User> findAll() {
101-
return new ArrayList<>(users);
102-
}
93+
// Automatic query: SELECT COUNT(u) FROM User u WHERE u.active = :active
94+
long countByActive(boolean active);
95+
96+
// Custom query with @Query annotation
97+
@Query("SELECT u FROM User u WHERE u.email = :email AND u.active = true")
98+
Optional<User> findActiveUserByEmail(String email);
99+
100+
// Native SQL query
101+
@Query(value = "SELECT * FROM users WHERE email = ?1", nativeQuery = true)
102+
Optional<User> findByEmailNative(String email);
103+
104+
// Update query
105+
@Query("UPDATE User u SET u.active = :active WHERE u.email = :email")
106+
@Modifying
107+
int updateUserActiveStatus(String email, boolean active);
103108
}
104109

105-
// Service Component
110+
// Service
106111
@Component
107112
public class UserService {
108-
private final UserRepository repository;
113+
private final UserRepository userRepository;
114+
115+
public UserService(UserRepository userRepository) {
116+
this.userRepository = userRepository;
117+
}
118+
119+
public User createUser(String name, String email, String password) {
120+
// Check if user already exists
121+
if (userRepository.findByEmail(email).isPresent()) {
122+
throw new IllegalArgumentException("User with email " + email + " already exists");
123+
}
124+
125+
User user = new User();
126+
user.setName(name);
127+
user.setEmail(email);
128+
user.setPassword(password);
129+
130+
return userRepository.save(user);
131+
}
109132

110-
// Constructor injection - DI container automatically injects UserRepository
111-
public UserService(UserRepository repository) {
112-
this.repository = repository;
133+
public Optional<User> findByEmail(String email) {
134+
return userRepository.findByEmail(email);
113135
}
114136

115-
public List<User> getAllUsers() {
116-
return repository.findAll();
137+
public List<User> findAllUsers() {
138+
return userRepository.findAll();
117139
}
118140
}
119141

120-
// Controller Component
142+
// Controller
121143
@Component
122144
public class UserController {
123145
private final UserService userService;
124146

125-
// Constructor injection - DI container automatically injects UserService
126147
public UserController(UserService userService) {
127148
this.userService = userService;
128149
}
129-
130-
public Response getUsers(Request request) {
131-
return Response.json(userService.getAllUsers());
150+
151+
public Response createUser(Request request) {
152+
User user = request.toObject(User.class);
153+
User createdUser = userService.createUser(user.getName(), user.getEmail(), user.getPassword());
154+
return Response.json(JSON.of("result", createdUser));
155+
}
156+
157+
public Response getUserByEmail(Request request) {
158+
String email = request.query("email");
159+
Optional<User> user = userService.findByEmail(email);
160+
161+
if (user.isPresent()) {
162+
return Response.json(Map.of("user", user.get()));
163+
} else {
164+
return Response.json(Map.of("error", "User not found")).status(404);
165+
}
132166
}
133167
}
134168

135-
// Application - DI works automatically!
169+
// Main class
136170
public class App {
137171
public static void main(String[] args) {
138172
Config config = new Config();
173+
config.setEnableMetrics(true);
174+
config.setServerPort(8080);
175+
139176
Router router = new Router();
140177

141-
// Define routes - controllers will be created with DI
142-
router.GET("/users", "getUsers", UserController.class);
178+
// User routes
179+
router.GET("/users", "getAllUsers", UserController.class);
180+
router.GET("/users/search", "getUserByEmail", UserController.class);
181+
router.POST("/users", "createUser", UserController.class);
143182

144-
// DI is automatically enabled and configured
145183
Server server = new Server(router, config);
146-
server.start(8080);
184+
server.start(config.getServerPort());
147185
}
148186
}
149187
```
150188

151-
That's it! The DI container automatically:
152-
- Discovers all `@Component` classes
153-
- Resolves dependencies between them
154-
- Creates instances with proper injection
155-
- Manages lifecycle callbacks
189+
### Configuration (application.properties)
190+
191+
```properties
192+
# Database Configuration
193+
jazzy.datasource.url=jdbc:h2:mem:testdb
194+
jazzy.datasource.username=sa
195+
jazzy.datasource.password=
196+
jazzy.datasource.driver-class-name=org.h2.Driver
197+
198+
# JPA/Hibernate Configuration
199+
jazzy.jpa.hibernate.ddl-auto=create-drop
200+
jazzy.jpa.show-sql=true
201+
jazzy.jpa.hibernate.dialect=org.hibernate.dialect.H2Dialect
202+
203+
# H2 Console (for development)
204+
jazzy.h2.console.enabled=true
205+
jazzy.h2.console.path=/h2-console
206+
```
207+
208+
That's it! The framework automatically:
209+
- Discovers entities and repositories
210+
- Creates repository implementations with query parsing
211+
- Manages database connections and transactions
212+
- Provides Spring Data JPA-like functionality
156213

157214
## Documentation
158215

@@ -174,6 +231,11 @@ Complete documentation for Jazzy Framework is available on our GitHub Pages site
174231
- [Dependency Injection Guide](https://canermastan.github.io/jazzy-framework/dependency-injection)
175232
- [DI Examples](https://canermastan.github.io/jazzy-framework/di-examples)
176233

234+
**Database Integration (v0.3+):**
235+
- [Database Integration Guide](https://canermastan.github.io/jazzy-framework/database-integration)
236+
- [Repository Pattern](https://canermastan.github.io/jazzy-framework/repositories)
237+
- [Query Methods](https://canermastan.github.io/jazzy-framework/query-methods)
238+
177239
## Development
178240

179241
Jazzy is developed with Maven. After cloning the project, you can use the following commands:
@@ -190,6 +252,9 @@ mvn exec:java -Dexec.mainClass="examples.basic.App"
190252

191253
# Run the DI example application (v0.2+)
192254
mvn exec:java -Dexec.mainClass="examples.di.App"
255+
256+
# Run the database example application (v0.3+)
257+
mvn exec:java -Dexec.mainClass="examples.database.DatabaseExampleApp"
193258
```
194259

195260
## Project Structure
@@ -199,6 +264,7 @@ mvn exec:java -Dexec.mainClass="examples.di.App"
199264
- `RequestHandler.java`: HTTP request processor with DI integration
200265
- `Config.java`: Configuration management
201266
- `Metrics.java`: Performance metrics
267+
- `PropertyLoader.java`: Configuration property management (v0.3+)
202268
- `routing/`: Routing system
203269
- `Router.java`: Route management with DI container support
204270
- `Route.java`: Route data structure
@@ -213,11 +279,21 @@ mvn exec:java -Dexec.mainClass="examples.di.App"
213279
- `ComponentScanner.java`: Automatic component scanning
214280
- `BeanDefinition.java`: Bean metadata and lifecycle management
215281
- `annotations/`: DI annotations (@Component, @Named, @Primary, etc.)
282+
- `data/`: Database integration system (v0.3+)
283+
- `BaseRepository.java`: Base repository interface
284+
- `BaseRepositoryImpl.java`: Default repository implementation
285+
- `RepositoryFactory.java`: Repository proxy creation
286+
- `QueryMethodParser.java`: Method name to query parsing
287+
- `HibernateConfig.java`: Hibernate/JPA configuration
288+
- `EntityScanner.java`: Automatic entity discovery
289+
- `RepositoryScanner.java`: Repository interface scanning
290+
- `annotations/`: Database annotations (@Query, @Modifying, @QueryHint)
216291
- `controllers/`: System controllers
217292
- `MetricsController.java`: Metrics reporting
218293
- `examples/`: Example applications
219-
- `basic/`: A simple web API example (v0.1 style)
220-
- `di/`: Dependency injection example (v0.2 style)
294+
- `basic/`: Basic framework usage examples
295+
- `di/`: Dependency injection examples (v0.2+)
296+
- `database/`: Database integration examples (v0.3+)
221297

222298
## Tests
223299

0 commit comments

Comments
 (0)