Giter Club home page Giter Club logo

ezyfox-db's Introduction

Build Status Dependency Status Coverage Status Maven Central Javadoc

#Synopsis

A SQL convenience library for Java built on top of Hibernate

#Code Example

1. Load session factory configuration

Lets say you want to load hibernate configration file:

hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost/test?useSSL=false&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
hibernate.connection.username=root
hibernate.connection.password=123
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.connection.pool_size=10
hibernate.jdbc.batch_size=25
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
net.sf.ehcache.configurationResourceName=/ehcache.xml
hibernate.cache.use_structured_entries=false
hibernate.generate_statistics=true

You can do like this:

SessionFactoryProvider.getInstance()
    .loader()
    .context(Context.class)
    .setProperties("hibernate_h2.properties")
    .addAnnotatedClass(GameUser.class)
    .load();

2. Save a list of entities

  List<GameUser> users = new ArrayList<>();
  for(int i = 0 ; i < 5 ; i++) {
      GameUser user = new GameUser();
      user.setId(id ++);
      user.setName("dungtv14#" + id);
      user.setMoney(123456);
      user.setLastLoginTime(new Date());
      user.setLastLogoutTime(new Date());
      user.setIp("1.2.3.4");
      users.add(user);
  }
  new QueryExecutor().execute(Context.class, new SaveCollection().batchSize(3).entities(users));

3. Fetch list of entities

  List<GameUser> users = new QueryExecutor()
      .execute(Context.class, new FetchListByEntity()
      .entityType(GameUser.class)
      .from(1)
      .size(3));

4. Fetch list of entities and sort to list of pages

  List<Page> pages = new QueryExecutor()
      .execute(Context.class, new FetchPagesByEntity()
      .entityType(GameUser.class)
      .from(1)
      .pageCount(2)
      .pageSize(2));

5. Fetch an entity by id

  GameUser user = new QueryExecutor()
      .execute(Context.class, new FetchById().id(1)
      .entityType(GameUser.class));

#Motivation

Read, write, update data from a SQL database always spend a lot of time, and we think using Hibernate is a good choice, but we still need to design our library for easy-to-use purpose

#Installation

	<dependency>
		<groupId>com.tvd12</groupId>
		<artifactId>ezyfox-db</artifactId>
		<version>1.0.0</version>
	</dependency>

#API Reference

http://www.javadoc.io/doc/com.tvd12/ezyfox-db

#Tests

mvn test

#Contributors

#License

  • Apache License, Version 2.0

ezyfox-db's People

Contributors

tvd12 avatar

Watchers

James Cloos avatar  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.