Git Product home page Git Product logo

daoism's Introduction

daoism

An example implementation of the DAO pattern for Java. Built around a technology agnostic interface that allows to plug-in different persistence technologies (IPersistenceProvider) and is shipped with a JPA 2 implementation of this provider. Offers generic CRUD tests out-of-the-box, just extend the CrudTest base class.

This code has been developed for small scale systems with some ~100 domain classes and up to some million entities managed by any ORM like persistence technology. The used abstractions should allow to plug-in different persistence technologies (document storage) as well. The JPA implementation of the persistence provider has been tested quite thoroughly. Everybody who wants to start building a system based on JPA can use this code directly or might get inspirations from it. Read this article for more details on this particular DAO pattern implementation.

You can also take a look at the javadoc

The test code shows some basic use cases of the API and comes with integration of hibernate and eclipse link on top of an H2 database. Spring is used to wire up the objects but any managed or unmanaged environment will work.

        // wired by Spring but maybe obtained in any other way, of course
        @Autowired
        VServerDao dao;

        VServer vServer1 = new VServer()
        VServer vServer2 = new VServer();


        dao.persist(vServer1);

        List<VServer> vServers = new LinkedList<VServer>();
        vServers.add(vServer1);
        vServers.add(vServer2);
        vServers.add(createValidEntity());
        vServers.add(createValidEntity());

        vServers = dao.persistAll(vServers);

        vServer1 = dao.findById(vServer1.getId());

        final String vServer1Id = vServer1.getId();
        dao.runTransactional(new UnitOfWork() {
            @Override
            public void execute() throws Exception {
                dao.findById(vServer1Id, Options.Refresh().Lock(LockType.PessimisticWrite));
            }
        });



        dao.findById(vServer1.getId());
        try {
            dao.findById(vServer1Id, Options.Refresh().Lock(LockType.PessimisticWrite));
        } catch (TransactionRequiredException e) {
            // this exception should be thrown because no transaction context is available
        }


        List<VServer> byUUid = dao.findAll(Queries.VServer.ByUuid(vServer1.getUuid()));
        byUUid = dao.findAll(Query.Named(Queries.VServer.ByUuid).set("UUID").to(vServer1.getUuid()));
        long howManyVServers = dao.countAll();


        modifyEntity(vServer1);
        dao.persist(vServer1);
        dao.isSameVersion(vServer1, dao.findById(vServer1.getId()));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.