Skip to content
This repository has been archived by the owner on Aug 17, 2020. It is now read-only.

Simplified object-relational mapping framework which supports InMemory, SQL and NoSQL databases

License

Notifications You must be signed in to change notification settings

dzikoysk-playground/pandaorm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Panda ORM

Object-Relational Mapping extracted from Panda project

Supported databases

  • InMemory database
  • SQL databases (without relations)
  • NoSQL databases

Supported layers

  • Services
  • Repositories
  • Entities

Example

public static void main(String... args) {
    AutomatedDataSpace space = AutomatedDataSpace.initialize(new InMemoryDataController())
            .createCollection()
                .name("users")
                .entity(User.class)
                .service(UserService.class)
                .repository(UserRepository.class)
                .append()
            .createCollection()
                .name("special-users")
                .entity(User.class)
                .service(SpecialUserService.class)
                .repository(UserRepository.class)
                .append()
            .collect();

    DataCollection collection = space.getCollection("users");
    UserService service = collection.getService(UserService.class);

    User user = service.createUser("onlypanda");
    user.setName("updated panda");

    Optional<User> foundByUser = service.findUserByName("updated panda");
    User foundById = service.findUserByNameOrId("fake username", user.getId());

    AtomicBoolean succeed = new AtomicBoolean(false);
    DataTransaction transaction = user.transaction(() -> {
                user.setName("variant panda");
                user.setName("transactional panda");
            })
            .success((attempt, time) -> {
                succeed.set(true);
            });
    transaction.commit();
}

@Service
static class SpecialUserService {

    @Autowired
    public SpecialUserService(UserService service, @Berry("special-users") UserRepository repository) {
        Assertions.assertNotEquals(repository, service.repository);
    }

}

@Service
static class UserService {

    private final UserRepository repository;

    @Autowired
    public UserService(@Berry("users") UserRepository repository) {
        this.repository = repository;
    }

    public User createUser(String name) {
        return repository.createUser(name);
    }

    public Optional<User> findUserByName(String name) {
        return repository.findUserByName(name);
    }

    public User findUserByNameOrId(String name, UUID id) {
        return repository.findByNameOrId(name, id);
    }

}

@Repository
interface UserRepository extends InMemoryDataRepository<User> {

    User createUser(@As("name") String name);

    Optional<User> findUserByName(String name);

    User findByNameOrId(String name, UUID id);

}

@Entity
public interface User extends DataEntity {

    void setName(String name);

    String getName();

    @Id
    @Generated
    UUID getId();

}

About

Simplified object-relational mapping framework which supports InMemory, SQL and NoSQL databases

Topics

Resources

License

Stars

Watchers

Forks

Languages