Skip to content

Toy implementation of a minimal, generic Active Record pattern

License

Notifications You must be signed in to change notification settings

kaiwinter/JavaActiveRecord

Repository files navigation

Example

PersonAR is an Active Record which extends BaseAR. For a running example see the JavaActiveRecord-Example-Project or the unit tests of JavaActiveRecord.

// Saving an entity
PersonAR person = new PersonAR();
person.setName("First name");
person.setSurname("Last name");
person.save();
System.out.println("Saved Person with ID: " + person.getId());

// Loading by ID
PersonAR findById = PersonAR.findById(PersonAR.class, 1);
System.out.println("Person by ID: " + findById);

// Loading by custom field
Collection<PersonAR> findByField = PersonAR.findAllByField(PersonAR.class, "name", "First name");
System.out.println("Person by Name: " + findByField);

// Loading all
Collection<PersonAR> findAll = PersonAR.findAll(PersonAR.class);
System.out.println("All Persons: " + findAll);

About

Toy implementation of a minimal, generic Active Record pattern

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages