Giter Site home page Giter Site logo

home3ee's Introduction

JAVA EE homework assignment #3 by Oleksiy Grechnyev

A toy DAO for the SQL textbook database which demonstrates the ORM problem. Only getAll() is implemenmted.

Includes both hand-written DAOs (CustomerDao, etc.) and the universal reflection-based DAO (ORMDao).

You must edit the configuration file scripts/connection.xml, at the very least you need SQL username & password. The init scripts (run if runinit=true) create the database, they are for MySQL/MariaDB only and require mysql executable in your path, versions for both Windows and Linux/Unix are included. To run tests, execute "mvn test" in the project directory, or run ORMTest class from your IDE. You can also run the class agrechnev.main.Main to print the output of a few queries to stdout.

Idea: I created simple Dao concept (AbstractDao), with getAll() only. It can work as both master and slave DAO, to create request of the type

SELECT * FROM master LEFT JOIN slave ON <link conditions>;

Multiple joins are not implemented.

I hand-coded DAOs for Customer (master only) and Order, Salesrep (slave only) as an example.

I also created a reflection-based Dao ORMDao which works for any entity class. It uses links table from an EntityLinkTable object, which is read from scripts/link.xml. Some notation on the one-to-many links:

S (from "set") = Parent entity with a "Set<ClassL> children;" field; table has the id COLUMN_S
L (from "link") = A child entity with an "ClassS parent;" field; table has a foreign key COLUMN_L

Currently the cases of two different links between a pair of table (e.g. Office<->Salesrep) are not fully supported, DAO only processes one link.

Only a few field types are currently supported in OrmDAO, new one can be added easily.

Other notes on this project:

I've used two different XML parsers as an exercise.

I've used reflections to create a universal toString() for Entity descendants, with toShortString() used to print collections to avoid infinite toString() recursion (or at least, to make it less likely).

My unit tests validate the toString() output of sorted collections, not a very beautiful solution, but it works.

home3ee's People

Contributors

agrechnev avatar

Watchers

James Cloos avatar

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.