Skip to content

Commit dd875e2

Browse files
committed
initial commit
0 parents  commit dd875e2

31 files changed

+1442
-0
lines changed

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# java-cli-bloop-sbt-postgres-com-tbl-exp
2+
3+
## Description
4+
Creates a small database table
5+
called `dog`. This table, `dog`, has been normalized to 3NF.
6+
Two new tables have been added, `breedLookup` and `colorLookup`.
7+
Creates a new table `dog_expanded` that joins
8+
`dog`, `breedLookup` and `colorLookup`. Added clustered indexes on
9+
`dog`.breedId and `dog`.colorId. Turned `dog_expanded` into a view with an
10+
implicit index on `dog_expanded`.id. Using an common table expression with the aggregate function
11+
COUNT, create a new view `breed_count`. All output normally
12+
seen in a terminal will be in `java-srv/log` which will dump to the screen. The project may seem to hang but the logs from the container must be written to the project this can take up to 3 min.
13+
14+
Compiled and ran from build server `bloop`.
15+
16+
# Build note
17+
Dependencies must be compatable with jdk8 or less.
18+
19+
## Tech stack
20+
- bloop
21+
- java
22+
- bloop-sbt
23+
- log4j
24+
- postgres driver
25+
26+
## Docker stack
27+
- hseeberger/scala-bloop-sbt:11.0.2-oraclelinux7_1.3.5_2.12.10
28+
- postgres
29+
30+
## To run
31+
`sudo ./install.sh -u`
32+
Creates java-srv/log
33+
34+
## To stop
35+
`sudo ./install.sh -d`
36+
Removes java-srv/log
37+
38+
## For help
39+
`sudo ./install.sh -h`
40+
41+
## Credit
42+
https://github.com/htorun/dbtableprinter
43+
44+
## java-cli specific search
45+
- [Search by bloop-sbt](https://github.com/bearddan2000?tab=repositories&q=java-cli-sbt&type=&language=&sort=)
46+
- [Search by postgres](https://github.com/bearddan2000?tab=repositories&q=java-cli-postgres&type=&language=&sort=)
47+
- [Search by com](https://github.java-cli-com/bearddan2000?tab=repositories&q=java-cli-com&type=&language=&sort=)
48+
- [Search by tbl](https://github.com/bearddan2000?tab=repositories&q=java-cli-tbl&type=&language=&sort=)
49+
- [Search by exp](https://github.com/bearddan2000?tab=repositories&q=java-cli-exp&type=&language=&sort=)
50+
- [Search by log4j](https://github.com/bearddan2000?tab=repositories&q=java-cli-log4j&type=&language=&sort=)
51+
- [Search by driver](https://github.com/bearddan2000?tab=repositories&q=java-cli-driver&type=&language=&sort=)
52+
53+
## General search
54+
- [Search by java](https://github.com/bearddan2000?tab=repositories&q=java&type=&language=&sort=)
55+
- [Search by cli](https://github.com/bearddan2000?tab=repositories&q=cli&type=&language=&sort=)
56+
- [Search by bloop-sbt](https://github.com/bearddan2000?tab=repositories&q=gradle&type=&language=&sort=)
57+
- [Search by postgres](https://github.com/bearddan2000?tab=repositories&q=postgres&type=&language=&sort=)
58+
- [Search by com](https://github.com/bearddan2000?tab=repositories&q=com&type=&language=&sort=)
59+
- [Search by tbl](https://github.com/bearddan2000?tab=repositories&q=tbl&type=&language=&sort=)
60+
- [Search by exp](https://github.com/bearddan2000?tab=repositories&q=exp&type=&language=&sort=)
61+
- [Search by log4j](https://github.com/bearddan2000?tab=repositories&q=log4j&type=&language=&sort=)
62+
- [Search by driver](https://github.com/bearddan2000?tab=repositories&q=driver&type=&language=&sort=)

db/sql/00-create-table.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE SEQUENCE dog_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1;
2+
3+
CREATE TABLE "public"."dog" (
4+
"id" integer DEFAULT nextval('dog_id_seq') NOT NULL,
5+
"breedId" integer NOT NULL,
6+
"colorId" integer NOT NULL
7+
) WITH (oids = false);

db/sql/01-table-insert.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
INSERT INTO "animal"."public"."dog" ("breedId", "colorId")
2+
VALUES
3+
(1, 1),
4+
(1, 2),
5+
(1, 3),
6+
(2, 2),
7+
(3, 2),
8+
(3, 3),
9+
(4, 3),
10+
(4, 4);

db/sql/02-create-table.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE SEQUENCE breedLookup_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1;
2+
3+
CREATE TABLE "public"."breedLookup" (
4+
"id" integer DEFAULT nextval('breedLookup_id_seq') NOT NULL,
5+
"breed" text NOT NULL
6+
) WITH (oids = false);

db/sql/03-table-insert.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INSERT INTO "animal"."public"."breedLookup" (breed)
2+
VALUES
3+
('Am Bulldog'),
4+
('Blue Tick'),
5+
('Labrador'),
6+
('Gr Shepard');

db/sql/04-create-table.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE SEQUENCE colorLookup_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1;
2+
3+
CREATE TABLE "public"."colorLookup" (
4+
"id" integer DEFAULT nextval('colorLookup_id_seq') NOT NULL,
5+
"color" text NOT NULL
6+
) WITH (oids = false);

db/sql/05-table-insert.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INSERT INTO "animal"."public"."colorLookup" (color)
2+
VALUES
3+
('White'),
4+
('Grey'),
5+
('Black'),
6+
('Brown');

db/sql/06-create-table.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE "public"."dog_expanded" AS (
2+
SELECT a.id, b.breed, c.color
3+
FROM dog AS a
4+
JOIN "breedLookup" AS b ON b.id = a."breedId"
5+
JOIN "colorLookup" AS c ON c.id = a."colorId"
6+
);

db/sql/07-create-index.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE INDEX "IDX_breed" on dog("breedId");
2+
CREATE INDEX "IDX_color" on dog("colorId");

db/sql/08-create-view.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DROP TABLE "public"."dog_expanded";
2+
3+
CREATE VIEW "public"."dog_expanded" AS (
4+
SELECT a.id, b.breed, c.color
5+
FROM dog AS a
6+
JOIN "breedLookup" AS b ON b.id = a."breedId"
7+
JOIN "colorLookup" AS c ON c.id = a."colorId"
8+
);

db/sql/09-create-view.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE VIEW "public".breed_count AS
2+
WITH "CTE_Count" (id, val) AS (
3+
SELECT "breedId", COUNT(*)
4+
FROM dog
5+
GROUP BY "breedId"
6+
)
7+
8+
SELECT c.breed, b.val
9+
FROM dog as a
10+
JOIN "CTE_Count" as b ON b.id = a."breedId"
11+
JOIN "breedLookup" as c ON c.id = a."breedId"
12+
GROUP BY c.breed, b.val, a."breedId"
13+
ORDER BY a."breedId";

docker-compose.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '3'
2+
services:
3+
java-srv:
4+
build:
5+
context: java-srv
6+
volumes:
7+
- ./java-srv/log:/root/log
8+
depends_on:
9+
- db
10+
links:
11+
- "db:db"
12+
13+
db:
14+
image: postgres:alpine
15+
environment:
16+
- POSTGRES_DB=animal
17+
- POSTGRES_USER=maria
18+
- POSTGRES_HOST_AUTH_METHOD=trust
19+
volumes:
20+
- ./db/sql:/docker-entrypoint-initdb.d

general.log

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[2021-03-26 13:50:29 INFO]: install::setup-logging ended
2+
================
3+
[2021-03-26 13:50:29 INFO]: install::start-up started
4+
[2021-03-26 13:50:29 INFO]: install::start-up starting services
5+
[2021-03-26 13:50:29 INFO]: install::decompress started
6+
[2021-03-26 13:50:29 INFO]: install::decompress changing directory to db
7+
[2021-03-26 13:50:29 INFO]: install::decompress decompress db/data_dump.tar.gz
8+
[2021-03-26 13:50:29 INFO]: install::decompress removing data_dump.tar.gz
9+
[2021-03-26 13:50:29 INFO]: install::decompress changing directory back
10+
[2021-03-26 13:50:29 INFO]: install::decompress ended
11+
================

0 commit comments

Comments
 (0)