Skip to content

Commit a03f3ef

Browse files
committed
initial commit
0 parents  commit a03f3ef

File tree

9 files changed

+464
-0
lines changed

9 files changed

+464
-0
lines changed

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# java-cli-bloop-sbt-orientdb-client-graph-edge-query
2+
3+
## Description
4+
A java bloop-sbt build, that connects to orientdb database.
5+
6+
Creates a new database `Health` and adds document `Doctor`.
7+
8+
Creates self joins with `edges`. Uses sql to query incoming
9+
and outgoing edges.
10+
11+
Compiled and ran from build server `bloop`.
12+
13+
# Build note
14+
Dependencies must be compatable with jdk8 or less.
15+
16+
## Tech stack
17+
- bloop
18+
- bloop-sbt
19+
20+
## Docker stack
21+
- orientdb:latest
22+
- hseeberger/scala-bloop-sbt:11.0.2-oraclelinux7_1.3.5_2.12.10
23+
24+
## To run
25+
`sudo ./install.sh -u`
26+
- [OrientDB studio](http://localhost:2480/studio/index.html)
27+
- user: admin
28+
- password: admin
29+
30+
## To stop (optional)
31+
`sudo ./install.sh -d`
32+
33+
## For help
34+
`sudo ./install.sh -h`
35+
36+
## Credit
37+
- [Edge querries](https://stackoverflow.com/questions/49798428/orientdb-query-for-getting-all-vertices-connected-by-edge-of-specyfic-type)
38+
- [Source based on](https://gist.github.com/Jaquitori/b9158b0979a8f815c5270cff0e785b00)
39+
- [Create init database](https://orientdb.com/docs/last/java/Document-API-Database.html)
40+
- [Default logins](https://orientdb.com/docs/last/java/Document-API-Database.html)

docker-compose.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: '3'
2+
services:
3+
java-srv:
4+
build:
5+
context: java-srv
6+
ports:
7+
- "80:8080"
8+
depends_on:
9+
- db
10+
links:
11+
- "db:db"
12+
13+
db:
14+
image: orientdb
15+
ports:
16+
- 2424:2424
17+
- 2480:2480
18+
# volumes:
19+
# - ./db/config:/orientdb/config
20+
# - ./db/databases:/orientdb/databases
21+
# - ./db/backup:/orientdb/backup
22+
environment:
23+
ORIENTDB_ROOT_PASSWORD: "rootpwd"

general.log

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[2022-10-21 13:25:07 INFO]: install::setup-logging ended
2+
================
3+
[2022-10-21 13:25:07 INFO]: install::start-up started
4+
[2022-10-21 13:25:07 INFO]: install::start-up build image
5+
[2022-10-21 13:25:07 INFO]: install::start-up running image
6+
[2022-10-21 13:25:07 INFO]: install::start-up ended
7+
================
8+
[2022-10-21 13:28:22 INFO]: install::root-check started
9+
[2022-10-21 13:28:22 INFO]: install::root-check ended
10+
================
11+
[2022-10-21 13:28:22 INFO]: install::docker-check started
12+
[2022-10-21 13:28:22 INFO]: install::docker-check ended
13+
================
14+
[2022-10-21 13:28:22 INFO]: install::docker-compose-check started
15+
[2022-10-21 13:28:22 INFO]: install::docker-compose-check ended
16+
================
17+
[2022-10-21 13:28:22 INFO]: install::tear-down started
18+
[2022-10-21 13:28:22 INFO]: install::tear-down stoping services
19+
[2022-10-21 13:28:22 INFO]: install::tear-down ended
20+
================

install.sh

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/usr/bin/env bash
2+
basefile="install"
3+
logfile="general.log"
4+
timestamp=`date '+%Y-%m-%d %H:%M:%S'`
5+
6+
if [ "$#" -ne 1 ]; then
7+
msg="[ERROR]: $basefile failed to receive enough args"
8+
echo "$msg"
9+
echo "$msg" >> $logfile
10+
exit 1
11+
fi
12+
13+
function setup-logging(){
14+
scope="setup-logging"
15+
info_base="[$timestamp INFO]: $basefile::$scope"
16+
17+
echo "$info_base started" >> $logfile
18+
19+
echo "$info_base removing old logs" >> $logfile
20+
21+
rm -f $logfile
22+
23+
echo "$info_base ended" >> $logfile
24+
25+
echo "================" >> $logfile
26+
}
27+
28+
function root-check(){
29+
scope="root-check"
30+
info_base="[$timestamp INFO]: $basefile::$scope"
31+
32+
echo "$info_base started" >> $logfile
33+
34+
#Make sure the script is running as root.
35+
if [ "$UID" -ne "0" ]; then
36+
echo "[$timestamp ERROR]: $basefile::$scope you must be root to run $0" >> $logfile
37+
echo "==================" >> $logfile
38+
echo "You must be root to run $0. Try the following"
39+
echo "sudo $0"
40+
exit 1
41+
fi
42+
43+
echo "$info_base ended" >> $logfile
44+
echo "================" >> $logfile
45+
}
46+
47+
function docker-check() {
48+
scope="docker-check"
49+
info_base="[$timestamp INFO]: $basefile::$scope"
50+
cmd=`docker -v`
51+
52+
echo "$info_base started" >> $logfile
53+
54+
if [ -z "$cmd" ]; then
55+
echo "$info_base docker not installed"
56+
echo "$info_base docker not installed" >> $logfile
57+
fi
58+
59+
echo "$info_base ended" >> $logfile
60+
echo "================" >> $logfile
61+
62+
}
63+
64+
function docker-compose-check() {
65+
scope="docker-compose-check"
66+
info_base="[$timestamp INFO]: $basefile::$scope"
67+
cmd=`docker-compose -v`
68+
69+
echo "$info_base started" >> $logfile
70+
71+
if [ -z "$cmd" ]; then
72+
echo "$info_base docker-compose not installed"
73+
echo "$info_base docker-compose not installed" >> $logfile
74+
fi
75+
76+
echo "$info_base ended" >> $logfile
77+
echo "================" >> $logfile
78+
79+
}
80+
function usage() {
81+
echo ""
82+
echo "Usage: "
83+
echo ""
84+
echo "-u: start."
85+
echo "-d: tear down."
86+
echo "-h: Display this help and exit."
87+
echo ""
88+
}
89+
function start-up(){
90+
91+
scope="start-up"
92+
docker_img_name=`head -n 1 README.md | sed 's/# //'`
93+
info_base="[$timestamp INFO]: $basefile::$scope"
94+
95+
echo "$info_base started" >> $logfile
96+
97+
echo "$info_base build image" >> $logfile
98+
99+
sudo docker-compose up --build
100+
101+
echo "$info_base running image" >> $logfile
102+
103+
echo "$info_base ended" >> $logfile
104+
105+
echo "================" >> $logfile
106+
}
107+
function tear-down(){
108+
109+
scope="tear-down"
110+
info_base="[$timestamp INFO]: $basefile::$scope"
111+
112+
echo "$info_base started" >> $logfile
113+
114+
echo "$info_base stoping services" >> $logfile
115+
116+
sudo docker-compose down
117+
118+
echo "$info_base ended" >> $logfile
119+
120+
echo "================" >> $logfile
121+
}
122+
123+
root-check
124+
docker-check
125+
docker-compose-check
126+
127+
while getopts ":udh" opts; do
128+
case $opts in
129+
u)
130+
setup-logging
131+
start-up ;;
132+
d)
133+
tear-down ;;
134+
h)
135+
usage
136+
exit 0 ;;
137+
/?)
138+
usage
139+
exit 1 ;;
140+
esac
141+
done

java-srv/Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM eed3si9n/sbt
2+
3+
# install bloop server
4+
RUN apk update \
5+
&& wget -O /usr/bin/coursier https://git.io/coursier-cli && chmod +x /usr/bin/coursier \
6+
&& coursier install --dir /usr/bin bloop --only-prebuilt=true \
7+
&& coursier bootstrap bloop --standalone -o bloop
8+
9+
WORKDIR /tmp
10+
11+
COPY bin/ .
12+
13+
RUN sbt bloopInstall
14+
15+
RUN bloop compile root
16+
17+
RUN bloop run root
18+
19+
CMD [""]

java-srv/bin/build.sbt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
lazy val root = (project in file("."))
2+
.settings(
3+
// Project name (artifact name in Maven)
4+
name := "(java-cli-sbt)",
5+
6+
// orgnization name (e.g., the package name of the project)
7+
organization := "example",
8+
9+
version := "1.0-SNAPSHOT",
10+
11+
// project description
12+
description := "Orientdb Project",
13+
14+
// Do not append Scala versions to the generated artifacts
15+
crossPaths := false,
16+
17+
// This forbids including Scala related libraries into the dependency
18+
autoScalaLibrary := false,
19+
20+
libraryDependencies ++= Seq(
21+
"org.projectlombok" % "lombok" % "1.18.8",
22+
"com.orientechnologies" % "orientdb-core" % "3.0.5",
23+
"com.orientechnologies" % "orientdb-client" % "3.0.5",
24+
"com.orientechnologies" % "orientdb-object" % "3.0.5",
25+
"com.orientechnologies" % "orientdb-graphdb" % "3.0.5",
26+
"javax.annotation" % "javax.annotation-api" % "1.3.2"
27+
),
28+
29+
mainClass := Some("example.Main")
30+
)

java-srv/bin/project/plugins.sbt

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
2+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
3+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
4+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
5+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
6+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
7+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
8+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
9+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
10+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
11+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
12+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
13+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
14+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
15+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
16+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
17+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
18+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
19+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
20+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
21+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
22+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
23+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
24+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
25+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
26+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
27+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
28+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
29+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
30+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
31+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
32+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
33+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
34+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
35+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
36+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
37+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
38+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
39+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
40+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
41+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
42+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
43+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
44+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
45+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
46+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
47+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
48+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
49+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
50+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
51+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
52+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
53+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
54+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
55+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package example;
2+
3+
import com.orientechnologies.orient.core.db.ODatabaseType;
4+
import com.orientechnologies.orient.core.db.ODatabaseSession;
5+
import com.orientechnologies.orient.core.db.OrientDB;
6+
import com.orientechnologies.orient.core.db.OrientDBConfig;
7+
8+
import example.dto.Doctor;
9+
10+
public class Main {
11+
12+
public static void main(String[] args) {
13+
14+
final String DATABASE = "Health";
15+
16+
OrientDB orient = new OrientDB("plocal:db", OrientDBConfig.defaultConfig());
17+
orient.create(DATABASE, ODatabaseType.PLOCAL);
18+
ODatabaseSession db = orient.open(DATABASE, "admin", "admin");
19+
20+
Doctor doctor = new Doctor(db);
21+
22+
final String[] doctors = new String[]{
23+
"Adam", "Bill", "Charlie"
24+
};
25+
for (String name : doctors)
26+
doctor.insert(name);
27+
28+
doctor.findAll();
29+
doctor.findInEdge();
30+
doctor.findOutEdge();
31+
doctor.findBothEdge();
32+
33+
db.close();
34+
orient.close();
35+
36+
}
37+
38+
}

0 commit comments

Comments
 (0)