GithubHelp home page GithubHelp logo

hellojavaer / ddal-demos Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 31 KB

This project lists some useful demos to show how to use DDAL in different scenes. If you want to know more about DDAL see DDAL wiki.

Home Page: https://github.com/hellojavaer/ddal

License: MIT License

Java 100.00%
ddal database demo scene ddal-demos ddr

ddal-demos's Introduction

ddal-demos

  • This project lists some useful demos to show how to use DDAL in different scenes. If you want to know more about DDAL see DDAL wiki.

Demo0

    1. design a scene
Assume that you need to route 'base' schema and 'user' table,
and the schema's route rule is "{#scName}_{#format('%02d', #sdValue % 2)}",
the table's route rule is "{#tbName}_{#format('%04d', #sdValue % 8)}"

By useing the route rule, we can get the following physical tables:
base_00.user_0000;
base_00.user_0002;
base_00.user_0004;
base_00.user_0005;
base_01.user_0001;
base_01.user_0003;
base_01.user_0005;
base_01.user_0007;
    1. initialize database and table

use InitDatabaseSqlBuilder to build the following sql

CREATE DATABASE IF NOT EXISTS `base_00` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
use base_00;
CREATE TABLE sequence (
  id bigint(20) NOT NULL AUTO_INCREMENT,
  schema_name varchar(32) NOT NULL,
  table_name varchar(64) NOT NULL,
  begin_value bigint(20) NOT NULL,
  next_value bigint(20) NOT NULL,
  end_value bigint(20) DEFAULT NULL,
  step int(11),
  skip_n_steps int(11),
  select_order int(11) NOT NULL,
  version bigint(20) NOT NULL DEFAULT '0',
  deleted tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (id),
  KEY idx_table_name_schema_name_deleted_select_order (table_name,schema_name,deleted,select_order) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO sequence(id,schema_name,table_name,begin_value,next_value,end_value,step,skip_n_steps,select_order,version,deleted)
  VALUES(1, 'base', 'user', 0, 0, NULL, NULL, NULL, 0, 0, 0);
CREATE TABLE `user_0000`(`id` bigint(20) NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), KEY `idx_name` (`name`) USING BTREE ) ENGINE=InnoDB;
CREATE TABLE `user_0002`(`id` bigint(20) NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), KEY `idx_name` (`name`) USING BTREE ) ENGINE=InnoDB;
CREATE TABLE `user_0004`(`id` bigint(20) NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), KEY `idx_name` (`name`) USING BTREE ) ENGINE=InnoDB;
CREATE TABLE `user_0006`(`id` bigint(20) NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), KEY `idx_name` (`name`) USING BTREE ) ENGINE=InnoDB;

CREATE DATABASE IF NOT EXISTS `base_01` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
use base_01;
CREATE TABLE `user_0001`(`id` bigint(20) NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), KEY `idx_name` (`name`) USING BTREE ) ENGINE=InnoDB;
CREATE TABLE `user_0003`(`id` bigint(20) NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), KEY `idx_name` (`name`) USING BTREE ) ENGINE=InnoDB;
CREATE TABLE `user_0005`(`id` bigint(20) NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), KEY `idx_name` (`name`) USING BTREE ) ENGINE=InnoDB;
CREATE TABLE `user_0007`(`id` bigint(20) NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), KEY `idx_name` (`name`) USING BTREE ) ENGINE=InnoDB;

    1. modify database config in file 'db.properties'
jdbc.url=jdbc:mysql://127.0.0.1:3306/base_00?verifyServerCertificate=false&useSSL=true
jdbc.w.username=w_base
jdbc.w.password=password
jdbc.r0.username=r_base
jdbc.r0.password=password
    1. run and check test cases
org.hellojavaer.ddal.demos.demo0.UserDaoTest.testForCRUD
org.hellojavaer.ddal.demos.demo0.UserDaoTest.scanQueryAll
org.hellojavaer.ddal.demos.demo0.UserDaoTest.groupRouteInfo

Demo1

    1. initialize database and table
CREATE DATABASE `acl` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
use acl;
CREATE TABLE `role`(`id` bigint(20) NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `idx_name` (`name`) USING BTREE ) ENGINE=InnoDB;
    1. modify database config in file 'db.properties'
jdbc.url=jdbc:mysql://127.0.0.1:3306/base_00?verifyServerCertificate=false&useSSL=true
jdbc.w.username=w_base
jdbc.w.password=password
jdbc.r0.username=r_base
jdbc.r0.password=password
    1. run and check test cases
org.hellojavaer.ddal.demos.demo1.RoleDaoTest.testForCRUD
org.hellojavaer.ddal.demos.demo1.RoleDaoTest.testLoadBalance

License

ddal-demos is licensed under MIT License.

ddal-demos's People

Contributors

hellojavaer avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

wuce7758

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.