Lightweight Spring-based library for mapping Java POJO to Database without JPA.
<dependency>
<groupId>com.jtouzy</groupId>
<artifactId>fastrecord</artifactId>
<version>{$fastrecord.version}</version>
</dependency>
Entity class :
@Entity
public Event {
@Id
private String id;
private String title;
// /!\ Getters and setters must be implemented but ignored for demo
}
Usage in program :
@Autowired
Statement statementProcessor;
// Find all events (SELECT event.id, event.title FROM event)
List<Event> events = statementProcessor.queryFrom(Event.class).findAll();
// Insert new event
Event event = new Event();
statementProcessor.insert(event).execute();
// Update event
event = statementProcessor.queryFrom(Event.class).eq("event_id", 1).findOne();
statementProcessor.update(event).execute();
// Delete event
statementProcessor.delete(event).execute();
Repository class :
@Service
public class EventRepository extends BaseSimpleIdRepository<Event,Integer> {
public EventRepository() {
super(Event.class);
}
}
Usage in program :
@Autowired
EventRepository eventRepository;
// Find an event with it's ID using Java8 optionals (SELECT event.id, event.title FROM event where event.id = ?)
Optional<Event> optionalEvent = eventRepository.findById(1);
// Find all events (SELECT event.id, event.title FROM event)
List<Event> events = eventRepository.findAll();