Skip to content

Commit bdc785a

Browse files
authored
Merge pull request eugenp#1 from eugenp/master
Sync Up
2 parents 08f58c5 + 0d85d1a commit bdc785a

405 files changed

Lines changed: 188480 additions & 1042 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

activejdbc/pom.xml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>activejdbc</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<name>activejdbc</name>
9+
<url>http://maven.apache.org</url>
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<activejdbc.version>1.4.13</activejdbc.version>
13+
<environments>development.test,development</environments>
14+
</properties>
15+
<build>
16+
<plugins>
17+
<plugin>
18+
<groupId>org.apache.maven.plugins</groupId>
19+
<artifactId>maven-compiler-plugin</artifactId>
20+
<version>3.6.0</version>
21+
<configuration>
22+
<source>1.8</source>
23+
<target>1.8</target>
24+
<encoding>UTF-8</encoding>
25+
</configuration>
26+
</plugin>
27+
<plugin>
28+
<groupId>org.javalite</groupId>
29+
<artifactId>activejdbc-instrumentation</artifactId>
30+
<version>${activejdbc.version}</version>
31+
<executions>
32+
<execution>
33+
<phase>process-classes</phase>
34+
<goals>
35+
<goal>instrument</goal>
36+
</goals>
37+
</execution>
38+
</executions>
39+
</plugin>
40+
<plugin>
41+
<groupId>org.javalite</groupId>
42+
<artifactId>db-migrator-maven-plugin</artifactId>
43+
<version>${activejdbc.version}</version>
44+
<configuration>
45+
<configFile>${project.basedir}/src/main/resources/database.properties</configFile>
46+
<environments>${environments}</environments>
47+
</configuration>
48+
<dependencies>
49+
<dependency>
50+
<groupId>mysql</groupId>
51+
<artifactId>mysql-connector-java</artifactId>
52+
<version>5.1.34</version>
53+
</dependency>
54+
</dependencies>
55+
</plugin>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-surefire-plugin</artifactId>
59+
<version>2.18.1</version>
60+
<configuration>
61+
<reportFormat>brief</reportFormat>
62+
<trimStackTrace>true</trimStackTrace>
63+
<useFile>false</useFile>
64+
<includes>
65+
<include>**/*Spec*.java</include>
66+
<include>**/*Test*.java</include>
67+
</includes>
68+
<excludes>
69+
<exclude>**/helpers/*</exclude>
70+
<exclude>**/*$*</exclude>
71+
</excludes>
72+
</configuration>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
<dependencies>
77+
<dependency>
78+
<groupId>junit</groupId>
79+
<artifactId>junit</artifactId>
80+
<version>4.12</version>
81+
<scope>test</scope>
82+
</dependency>
83+
<dependency>
84+
<groupId>org.javalite</groupId>
85+
<artifactId>activejdbc</artifactId>
86+
<version>${activejdbc.version}</version>
87+
<exclusions>
88+
<exclusion>
89+
<groupId>opensymphony</groupId>
90+
<artifactId>oscache</artifactId>
91+
</exclusion>
92+
</exclusions>
93+
</dependency>
94+
<dependency>
95+
<groupId>mysql</groupId>
96+
<artifactId>mysql-connector-java</artifactId>
97+
<version>5.1.34</version>
98+
</dependency>
99+
<dependency>
100+
<groupId>org.slf4j</groupId>
101+
<artifactId>slf4j-simple</artifactId>
102+
<version>1.7.9</version>
103+
</dependency>
104+
</dependencies>
105+
<repositories>
106+
<repository>
107+
<id>snapshots1</id>
108+
<name>JavaLite Snapshots1</name>
109+
<url>http://repo.javalite.io/</url>
110+
<snapshots>
111+
<enabled>true</enabled>
112+
<updatePolicy>always</updatePolicy>
113+
<checksumPolicy>warn</checksumPolicy>
114+
</snapshots>
115+
</repository>
116+
</repositories>
117+
<pluginRepositories>
118+
<pluginRepository>
119+
<id>snapshots2</id>
120+
<name>JavaLite Snapshots2</name>
121+
<url>http://repo.javalite.io/</url>
122+
<snapshots>
123+
<enabled>true</enabled>
124+
<updatePolicy>always</updatePolicy>
125+
<checksumPolicy>warn</checksumPolicy>
126+
</snapshots>
127+
</pluginRepository>
128+
</pluginRepositories>
129+
</project>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.baeldung;
2+
3+
4+
import com.baeldung.model.Employee;
5+
import com.baeldung.model.Role;
6+
import org.javalite.activejdbc.Base;
7+
import org.javalite.activejdbc.LazyList;
8+
import org.javalite.activejdbc.Model;
9+
10+
public class ActiveJDBCApp
11+
{
12+
public static void main( String[] args )
13+
{
14+
try {
15+
Base.open();
16+
ActiveJDBCApp app = new ActiveJDBCApp();
17+
app.create();
18+
app.update();
19+
app.delete();
20+
app.deleteCascade();
21+
} catch (Exception e) {
22+
e.printStackTrace();
23+
} finally {
24+
Base.close();
25+
}
26+
}
27+
28+
protected void create() {
29+
Employee employee = new Employee("Hugo","C","M","BN");
30+
employee.saveIt();
31+
employee.add(new Role("Java Developer","BN"));
32+
LazyList<Model> all = Employee.findAll();
33+
System.out.println(all.size());
34+
}
35+
36+
protected void update() {
37+
Employee employee = Employee.findFirst("first_name = ?","Hugo");
38+
employee.set("last_namea","Choi").saveIt();
39+
employee = Employee.findFirst("last_name = ?","Choi");
40+
System.out.println(employee.getString("first_name") + " " + employee.getString("last_name"));
41+
}
42+
43+
protected void delete() {
44+
Employee employee = Employee.findFirst("first_name = ?","Hugo");
45+
employee.delete();
46+
employee = Employee.findFirst("last_name = ?","Choi");
47+
if(null == employee){
48+
System.out.println("No such Employee found!");
49+
}
50+
}
51+
52+
protected void deleteCascade() {
53+
create();
54+
Employee employee = Employee.findFirst("first_name = ?","Hugo");
55+
employee.deleteCascade();
56+
employee = Employee.findFirst("last_name = ?","C");
57+
if(null == employee){
58+
System.out.println("No such Employee found!");
59+
}
60+
}
61+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.model;
2+
3+
4+
import org.javalite.activejdbc.Model;
5+
6+
public class Employee extends Model {
7+
8+
public Employee(){
9+
10+
}
11+
12+
public Employee(String firstName, String lastName, String gender, String createdBy) {
13+
set("first_name1",firstName);
14+
set("last_name",lastName);
15+
set("gender",gender);
16+
set("created_by",createdBy);
17+
}
18+
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.model;
2+
3+
4+
import org.javalite.activejdbc.Model;
5+
import org.javalite.activejdbc.annotations.Table;
6+
7+
@Table("EMP_ROLES")
8+
public class Role extends Model {
9+
10+
public Role(){
11+
12+
}
13+
14+
public Role(String role,String createdBy){
15+
set("role_name",role);
16+
set("created_by",createdBy);
17+
}
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# noinspection SqlNoDataSourceInspectionForFile
2+
3+
create table organisation.employees
4+
(
5+
id int not null auto_increment
6+
primary key,
7+
first_name varchar(100) not null,
8+
last_name varchar(100) not null,
9+
gender varchar(1) not null,
10+
created_at datetime not null,
11+
updated_at datetime null,
12+
created_by varchar(100) not null,
13+
updated_by varchar(100) null
14+
)ENGINE = InnoDB DEFAULT CHARSET = utf8;
15+
16+
create table organisation.emp_roles
17+
(
18+
id int not null auto_increment primary key,
19+
employee_id int not null,
20+
role_name varchar(100) not null,
21+
created_at datetime not null,
22+
updated_at datetime null,
23+
created_by varchar(100) not null,
24+
updated_by varchar(100) null
25+
)ENGINE = InnoDB DEFAULT CHARSET = utf8;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
development.driver=com.mysql.jdbc.Driver
2+
development.username=root
3+
development.password=123456
4+
development.url=jdbc:mysql://localhost/organisation
5+
6+
7+
development.test.driver=com.mysql.jdbc.Driver
8+
development.test.username=root
9+
development.test.password=123456
10+
development.test.url=jdbc:mysql://localhost/organisation_test
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.baeldung;
2+
3+
import com.baeldung.model.Employee;
4+
import com.baeldung.model.Role;
5+
import org.javalite.activejdbc.test.DBSpec;
6+
import org.junit.Test;
7+
8+
import java.util.List;
9+
10+
public class ActiveJDBCAppTest extends DBSpec
11+
{
12+
@Test
13+
public void ifEmployeeCreated_thenIsValid() {
14+
Employee employee = new Employee("B", "N", "M", "BN");
15+
the(employee).shouldBe("valid");
16+
}
17+
18+
@Test
19+
public void ifEmployeeCreatedWithRoles_thenShouldPersist() {
20+
Employee employee = new Employee("B", "N", "M", "BN");
21+
employee.saveIt();
22+
employee.add(new Role("Java Developer","BN"));
23+
employee.add(new Role("Lead Java Developer","BN"));
24+
a(Role.count()).shouldBeEqual(2);
25+
List<Role> roles = employee.getAll(Role.class).orderBy("created_at");
26+
the(roles.get(0).getRoleName()).shouldBeEqual("Java Developer");
27+
the(roles.get(1).getRoleName()).shouldBeEqual("Lead Java Developer");
28+
}
29+
30+
@Test
31+
public void ifEmployeeCreatedWithRoles_whenNameUpdated_thenShouldShowNewName() {
32+
Employee employee = new Employee("Binesh", "N", "M", "BN");
33+
employee.saveIt();
34+
employee.add(new Role("Java Developer","BN"));
35+
employee.add(new Role("Lead Java Developer","BN"));
36+
employee = Employee.findFirst("first_name = ?", "Binesh");
37+
employee.set("last_name","Narayanan").saveIt();
38+
Employee updated = Employee.findFirst("first_name = ?", "Binesh");
39+
the(updated.getLastName()).shouldBeEqual("Narayanan");
40+
}
41+
42+
@Test
43+
public void ifEmployeeCreatedWithRoles_whenDeleted_thenShouldNotBeFound() {
44+
Employee employee = new Employee("Binesh", "N", "M", "BN");
45+
employee.saveIt();
46+
employee.add(new Role("Java Developer","BN"));
47+
employee.delete();
48+
employee = Employee.findFirst("first_name = ?", "Binesh");
49+
the(employee).shouldBeNull();
50+
}
51+
}

apache-poi/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
### Relevant Articles:
22
- [Microsoft Word Processing in Java with Apache POI](http://www.baeldung.com/java-microsoft-word-with-apache-poi)
33
- [Working with Microsoft Excel in Java](http://www.baeldung.com/java-microsoft-excel)
4+
- [Creating a MS PowerPoint Presentation in Java](https://github.com/eugenp/tutorials/tree/master/apache-poi)

core-java-8/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@
3434
- [Copy a File with Java](http://www.baeldung.com/java-copy-file)
3535
- [Generating Prime Numbers in Java](http://www.baeldung.com/java-generate-prime-numbers)
3636
- [Static and Default Methods in Interfaces in Java](http://www.baeldung.com/java-static-default-methods)
37+
- [Iterable to Stream in Java](http://www.baeldung.com/java-iterable-to-stream)
38+
- [Converting String to Stream of chars](http://www.baeldung.com/java-string-to-stream)
39+
- [How to Iterate Over a Stream With Indices](http://www.baeldung.com/java-stream-indices)
40+
- [Efficient Word Frequency Calculator in Java](http://www.baeldung.com/java-word-frequency)
41+
- [Primitive Type Streams in Java 8](http://www.baeldung.com/java-8-primitive-streams)
42+
- [Fail-Safe Iterator vs Fail-Fast Iterator](http://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator)

core-java-8/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@
101101
<version>1.19</version>
102102
</dependency>
103103

104+
<dependency>
105+
<groupId>com.codepoetics</groupId>
106+
<artifactId>protonpack</artifactId>
107+
<version>${protonpack.version}</version>
108+
</dependency>
109+
110+
<dependency>
111+
<groupId>io.vavr</groupId>
112+
<artifactId>vavr</artifactId>
113+
<version>${vavr.version}</version>
114+
</dependency>
115+
116+
<dependency>
117+
<groupId>one.util</groupId>
118+
<artifactId>streamex</artifactId>
119+
<version>${streamex.version}</version>
120+
</dependency>
104121
</dependencies>
105122

106123
<build>
@@ -267,6 +284,9 @@
267284
<collections-generic.version>4.01</collections-generic.version>
268285
<commons-codec.version>1.10</commons-codec.version>
269286
<lombok.version>1.16.12</lombok.version>
287+
<vavr.version>0.9.0</vavr.version>
288+
<protonpack.version>1.13</protonpack.version>
289+
<streamex.version>0.6.5</streamex.version>
270290

271291
<!-- testing -->
272292
<assertj.version>3.6.1</assertj.version>

0 commit comments

Comments
 (0)