implements IUserDAO{
7 |
8 | private static final long serialVersionUID = 1L;
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-db/src/main/java/com/bahadirakin/model/Car.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.model;
2 |
3 | // Generated 06.Eki.2012 16:08:28 by Hibernate Tools 3.4.0.CR1
4 |
5 | import javax.persistence.Column;
6 | import javax.persistence.Entity;
7 | import javax.persistence.FetchType;
8 | import javax.persistence.GeneratedValue;
9 | import static javax.persistence.GenerationType.IDENTITY;
10 | import javax.persistence.Id;
11 | import javax.persistence.JoinColumn;
12 | import javax.persistence.ManyToOne;
13 | import javax.persistence.Table;
14 | import javax.xml.bind.annotation.XmlRootElement;
15 | import javax.xml.bind.annotation.XmlTransient;
16 |
17 | /**
18 | * Car generated by hbm2java
19 | */
20 | @Entity
21 | @Table(name = "car")
22 | @XmlRootElement
23 | public class Car extends AbstractEntity {
24 |
25 | private static final long serialVersionUID = 1L;
26 | private Integer id;
27 | private User user;
28 | private String liecencePlate;
29 | private String model;
30 |
31 | public Car() {
32 | }
33 |
34 | public Car(User user, String liecencePlate) {
35 | this.user = user;
36 | this.liecencePlate = liecencePlate;
37 | }
38 |
39 | public Car(User user, String liecencePlate, String model) {
40 | this.user = user;
41 | this.liecencePlate = liecencePlate;
42 | this.model = model;
43 | }
44 |
45 | @Id
46 | @GeneratedValue(strategy = IDENTITY)
47 | @Column(name = "id", unique = true, nullable = false)
48 | public Integer getId() {
49 | return this.id;
50 | }
51 |
52 | public void setId(Integer id) {
53 | this.id = id;
54 | }
55 |
56 | @ManyToOne(fetch = FetchType.LAZY)
57 | @JoinColumn(name = "userId", nullable = false)
58 | @XmlTransient
59 | public User getUser() {
60 | return this.user;
61 | }
62 |
63 | public void setUser(User user) {
64 | this.user = user;
65 | }
66 |
67 | @Column(name = "liecencePlate", nullable = false, length = 50)
68 | public String getLiecencePlate() {
69 | return this.liecencePlate;
70 | }
71 |
72 | public void setLiecencePlate(String liecencePlate) {
73 | this.liecencePlate = liecencePlate;
74 | }
75 |
76 | @Column(name = "model", length = 50)
77 | public String getModel() {
78 | return this.model;
79 | }
80 |
81 | public void setModel(String model) {
82 | this.model = model;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-db/src/main/java/com/bahadirakin/model/IEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Bahadır AKIN
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.bahadirakin.model;
17 |
18 | import java.io.Serializable;
19 |
20 | /**
21 | * All database entities must implements this interface, which represents the
22 | * minimum requirements to meet.
23 | *
24 | *
25 | * A database entity always has Integer
surrogate key (system ID).
26 | * It must also be {@link Serializable}, {@link Cloneable} and
27 | * {@link Comparable}
28 | *
29 | *
30 | * @author Bahadır AKIN
31 | *
32 | */
33 | public interface IEntity extends Serializable, Cloneable, Comparable {
34 |
35 | public Integer getId();
36 |
37 | public void setId(Integer id);
38 |
39 | boolean isNew();
40 | }
41 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-db/src/main/java/com/bahadirakin/rest/App.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.rest;
2 |
3 | /**
4 | * Hello world!
5 | *
6 | */
7 | public class App
8 | {
9 | public static void main( String[] args )
10 | {
11 | System.out.println( "Hello World!" );
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-db/src/main/resources/hibernate.cfg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 | com.mysql.jdbc.Driver
7 | jdbc:mysql://localhost:3306/dbrest?useUnicode=true&characterEncoding=UTF-8
8 | dbrest
9 | root
10 |
11 | org.hibernate.dialect.MySQLDialect
12 | org.hibernate.context.ThreadLocalSessionContext
13 |
14 |
15 | 2
16 |
17 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-db/src/main/resources/hibernate.reveng.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-db/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=INFO,Stdout
2 |
3 | log4j.appender.Stdout=org.apache.log4j.ConsoleAppender
4 | log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout
5 | log4j.appender.Stdout.layout.conversionPattern=%-5p (%d{dd.MMM.yyyy - HH:mm:ss}) [%-26.26c{1}] - %m%n
6 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-db/src/test/java/com/bahadirakin/rest/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.rest;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | rest-main
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.jsdt.core.javascriptValidator
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.wst.common.project.facet.core.builder
20 |
21 |
22 |
23 |
24 | org.eclipse.wst.validation.validationbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.eclipse.jem.workbench.JavaEMFNature
36 | org.eclipse.wst.common.modulecore.ModuleCoreNature
37 | org.eclipse.jdt.core.javanature
38 | org.eclipse.m2e.core.maven2Nature
39 | org.eclipse.wst.common.project.facet.core.nature
40 | org.eclipse.wst.jsdt.core.jsNature
41 |
42 |
43 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/.settings/.jsdtscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/resources=UTF-8
3 | encoding/=UTF-8
4 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4 | org.eclipse.jdt.core.compiler.compliance=1.5
5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8 | org.eclipse.jdt.core.compiler.source=1.5
9 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/.settings/org.eclipse.wst.common.component:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | uses
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/.settings/org.eclipse.wst.jsdt.ui.superType.container:
--------------------------------------------------------------------------------
1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/.settings/org.eclipse.wst.jsdt.ui.superType.name:
--------------------------------------------------------------------------------
1 | Window
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | rest-tutorial
8 | bahadirakin-tutorial
9 | 1.0.0.1-SNAPSHOT
10 |
11 |
12 | rest-main
13 | war
14 |
15 | rest-main Maven Webapp
16 | http://maven.apache.org
17 |
18 |
19 |
20 |
21 | bahadirakin-tutorial
22 | rest-db
23 | ${project.version}
24 |
25 |
26 |
27 | com.sun.jersey
28 | jersey-server
29 | 1.14
30 |
31 |
32 | com.sun.jersey
33 | jersey-servlet
34 | 1.14
35 |
36 |
37 |
38 | rest-main
39 |
40 |
41 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/src/main/java/com/bahadirakin/services/HelloWorldService.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.services;
2 |
3 | import javax.ws.rs.GET;
4 | import javax.ws.rs.Path;
5 | import javax.ws.rs.PathParam;
6 | import javax.ws.rs.Produces;
7 | import javax.ws.rs.QueryParam;
8 | import javax.ws.rs.core.MediaType;
9 | import javax.ws.rs.core.Response;
10 |
11 | @Path("hello")
12 | public class HelloWorldService {
13 |
14 | @GET
15 | @Produces(MediaType.TEXT_PLAIN)
16 | public String saySimpleHello() {
17 | return "Hello, World!";
18 | }
19 |
20 | @GET
21 | @Produces(MediaType.TEXT_XML)
22 | @Path("/{to}")
23 | public String sayXmlHello(@PathParam("to") String to) {
24 | return "Hello, " + to + "!";
25 | }
26 |
27 | @GET
28 | @Produces(MediaType.TEXT_HTML)
29 | @Path("/query")
30 | public Response sayHelloAgain(@QueryParam("to") String to) {
31 | return Response.ok("Hello, " + to + "!", MediaType.TEXT_HTML).build();
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/src/main/resources/hibernate.cfg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 | com.mysql.jdbc.Driver
7 | jdbc:mysql://localhost:3306/dbrest?useUnicode=true&characterEncoding=UTF-8
8 | dbrest
9 | root
10 |
11 | org.hibernate.dialect.MySQLDialect
12 | org.hibernate.context.ThreadLocalSessionContext
13 |
14 |
15 | 2
16 |
17 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=INFO,Stdout
2 |
3 | log4j.appender.Stdout=org.apache.log4j.ConsoleAppender
4 | log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout
5 | log4j.appender.Stdout.layout.conversionPattern=%-5p (%d{dd.MMM.yyyy - HH:mm:ss}) [%-26.26c{1}] - %m%n
6 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | RESTful Web Services - Tutorial
7 |
8 | Jersey Servlet
9 | com.sun.jersey.spi.container.servlet.ServletContainer
10 |
11 | com.sun.jersey.config.property.packages
12 | com.bahadirakin.services
13 |
14 | 1
15 |
16 |
17 | Jersey Servlet
18 | /rest/*
19 |
20 |
21 |
--------------------------------------------------------------------------------
/rest-tutorial/rest-main/src/main/webapp/index.jsp:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World!
4 |
5 |
6 |
--------------------------------------------------------------------------------
/retrolambda-sample/src/main/java/com/bahadirakin/User.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin;
2 |
3 | /**
4 | * Created by bhdrkn on 11/06/15.
5 | */
6 | public class User {
7 |
8 | private final String username;
9 | private final String email;
10 | private final String password;
11 |
12 |
13 | public User(String username, String email, String password) {
14 | this.username = username;
15 | this.email = email;
16 | this.password = password;
17 | }
18 |
19 | public String getUsername() {
20 | return username;
21 | }
22 |
23 | public String getEmail() {
24 | return email;
25 | }
26 |
27 | public String getPassword() {
28 | return password;
29 | }
30 |
31 | @Override
32 | public String toString() {
33 | return "User{" +
34 | "username='" + username + '\'' +
35 | ", email='" + email + '\'' +
36 | ", password='" + password + '\'' +
37 | '}';
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/simple-smpp-routing/assembly.xml:
--------------------------------------------------------------------------------
1 |
5 | bin
6 |
7 | zip
8 |
9 |
10 |
11 | ${project.basedir}/src/main/resources/conf
12 | /conf
13 |
14 | *.properties
15 | *.xml
16 |
17 |
18 |
19 | ${project.basedir}/src/main/resources/bin
20 | /
21 |
22 | *.sh
23 | *.bat
24 |
25 |
26 |
27 | ${project.basedir}/src/main/resources
28 | /
29 |
30 | logback.xml
31 | import.sql
32 |
33 |
34 |
35 |
36 |
37 | /lib
38 |
39 | ${project.groupId}:${project.artifactId}
40 |
41 |
42 |
43 | /
44 |
45 | ${project.groupId}:${project.artifactId}
46 |
47 |
48 |
49 | false
50 |
--------------------------------------------------------------------------------
/simple-smpp-routing/src/main/java/com/bahadirakin/App.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin;
2 |
3 | import org.springframework.context.support.AbstractApplicationContext;
4 | import org.springframework.context.support.ClassPathXmlApplicationContext;
5 |
6 | import java.io.IOException;
7 |
8 | public class App {
9 | public static void main(String[] args) throws IOException {
10 | System.out.println("Application is going to be started");
11 | final AbstractApplicationContext applContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
12 | applContext.registerShutdownHook();
13 | System.out.println("Application is started");
14 |
15 | System.in.read();
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/simple-smpp-routing/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
14 |
16 |
17 |
18 |
19 | classpath*:conf/database.properties
20 | classpath*:conf/endpoint.properties
21 |
22 |
23 |
24 |
25 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/simple-smpp-routing/src/main/resources/bin/run.bat:
--------------------------------------------------------------------------------
1 | java -cp .;conf/*;lib/*;../* com.bahadirakin.App
--------------------------------------------------------------------------------
/simple-smpp-routing/src/main/resources/bin/run.sh:
--------------------------------------------------------------------------------
1 | java -cp .:conf/*:lib/*:../* com.bahadirakin.App
--------------------------------------------------------------------------------
/simple-smpp-routing/src/main/resources/conf/database.properties:
--------------------------------------------------------------------------------
1 | # Database Connection Properties
2 |
3 | # H2
4 | database.jdbc.driverClassName=org.h2.Driver
5 | database.jdbc.url=jdbc:h2:~/h2SpringJpaTutorialDb;AUTO_SERVER=TRUE
6 | database.jdbc.username=bhdrkn
7 | database.jdbc.password=1q2w3e
8 | hibernate.default_schema=H2SPRINGJPATUTORIALDB.PUBLIC
9 |
10 | # Postgresql
11 | # database.jdbc.driverClassName=org.postgresql.Driver
12 | # database.jdbc.url=jdbc:postgresql://localhost:5432/bulksmsdb?characterEncoding=UTF-8
13 | # database.jdbc.username=bhdrkn
14 | # database.jdbc.password=1q2w3e
15 | # hibernate.default_schema=public
16 |
17 | # MySql
18 | # database.jdbc.driverClassName=com.mysql.jdbc.Driver
19 | # database.jdbc.url=jdbc:mysql://localhost:3306/bulksmsdb?characterEncoding=UTF-8
20 | # database.jdbc.username=bhdrkn
21 | # database.jdbc.password=1q2w3e
22 | # hibernate.default_schema=bulksmsdb
23 |
24 | # Connection Pool properties
25 | database.c3p0.maxPoolSize=5
26 | database.c3p0.acquireIncrement=1
27 | database.c3p0.maxStatements=0
28 | database.c3p0.maxStatementsPerConnection=0
29 | database.c3p0.initialPoolSize=1
30 | database.c3p0.idleConnectionTestPeriod=1000
31 | database.c3p0.maxIdleTime=21600
32 | database.c3p0.unreturnedConnectionTimeout=1000
33 | database.c3p0.debugUnreturnedConnectionStackTraces=true
34 |
35 | # Hibernate Properties
36 | # https://docs.jboss.org/hibernate/core/4.2/manual/en-US/html/ch03.html#configuration-optional-properties
37 | hibernate.ejb.naming_strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy
38 | hibernate.hbm2ddl.auto=create-drop
39 | hibernate.showSql=true
40 | hibernate.formatSql=true
41 | hibernate.generate_statistics=true
42 | hibernate.max_fetch_depth=3
43 | hibernate.default_batch_fetch_size=16
44 | hibernate.jdbc.batch_size=20
45 | hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
46 | hibernate.cache.use_query_cache=true
47 | hibernate.cache.use_second_level_cache=false
--------------------------------------------------------------------------------
/simple-smpp-routing/src/main/resources/import.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO SHORTMESSAGE(DESTINATIONADDRESS, DESTINATIONNPI, DESTINATIONTON, MESSAGE, PRIORITYFLAG, SOURCEADDRESS, SOURCENPI, SOURCETON, VERSION) VALUES('05551234567',1,1,'HELLO, WORLD!',1,'05321234567',1,1,1);
--------------------------------------------------------------------------------
/simple-smpp-routing/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | %d{HH:mm:ss.SSS} %-5level [%thread] %logger - %msg%n
8 | UTF-8
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 | ${logPath}/BulkSms-.%d{yyyy-MM-dd}.log.zip
18 |
19 |
20 |
21 | 30
22 |
23 |
24 |
25 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n
26 |
27 | UTF-8
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/simple-smpp-routing/src/test/java/com/bahadirakin/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-cxf/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Eclipse #
3 | ###########
4 | .classpath
5 | /.settings
6 | .project
7 | /target
8 |
9 | # Compiled source #
10 | ###################
11 | *.com
12 | *.class
13 | *.dll
14 | *.exe
15 | *.o
16 | *.so
17 |
18 | # Packages #
19 | ############
20 | # it's better to unpack these files and commit the raw source
21 | # git has its own built in compression methods
22 | *.7z
23 | *.dmg
24 | *.gz
25 | *.iso
26 | *.jar
27 | *.rar
28 | *.tar
29 | *.zip
30 |
31 | # Logs and databases #
32 | ######################
33 | *.log
34 | *.sql
35 | *.sqlite
36 |
37 | # OS generated files #
38 | ######################
39 | .DS_Store
40 | .DS_Store?
41 | ._*
42 | .Spotlight-V100
43 | .Trashes
44 | ehthumbs.db
45 | Thumbs.db
46 |
47 |
--------------------------------------------------------------------------------
/spring-cxf/src/main/java/com/bahadirakin/model/HelloWorldMessage.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | import javax.xml.bind.annotation.XmlAccessType;
6 | import javax.xml.bind.annotation.XmlAccessorType;
7 | import javax.xml.bind.annotation.XmlElement;
8 | import javax.xml.bind.annotation.XmlType;
9 |
10 | @XmlType(name = "helloWorldMessage", namespace = "http://model.bahadirakin.com")
11 | @XmlAccessorType(XmlAccessType.FIELD)
12 | public class HelloWorldMessage implements Serializable {
13 |
14 | private static final long serialVersionUID = 1L;
15 |
16 | @XmlElement(name = "message", namespace = "http://model.bahadirakin.com", nillable = false, required = true, type = String.class)
17 | private String message;
18 |
19 | public HelloWorldMessage() {
20 | super();
21 | }
22 |
23 | public HelloWorldMessage(String message) {
24 | super();
25 | this.message = message;
26 | }
27 |
28 | public String getMessage() {
29 | return message;
30 | }
31 |
32 | public void setMessage(String message) {
33 | this.message = message;
34 | }
35 |
36 | @Override
37 | public int hashCode() {
38 | final int prime = 31;
39 | int result = 1;
40 | result = prime * result + ((message == null) ? 0 : message.hashCode());
41 | return result;
42 | }
43 |
44 | @Override
45 | public boolean equals(Object obj) {
46 | if (this == obj)
47 | return true;
48 | if (obj == null)
49 | return false;
50 | if (getClass() != obj.getClass())
51 | return false;
52 | HelloWorldMessage other = (HelloWorldMessage) obj;
53 | if (message == null) {
54 | if (other.message != null)
55 | return false;
56 | } else if (!message.equals(other.message))
57 | return false;
58 | return true;
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return "HelloWorldMessage [message=" + message + "]";
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/spring-cxf/src/main/java/com/bahadirakin/producer/MessageProducer.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.producer;
2 |
3 | import java.io.Serializable;
4 |
5 | import com.bahadirakin.model.HelloWorldMessage;
6 | import com.bahadirakin.model.Person;
7 |
8 | /**
9 | *
10 | * @author bhdrkn
11 | *
12 | */
13 | public interface MessageProducer extends Serializable{
14 |
15 | HelloWorldMessage produceHelloWorldMessage(final Person person);
16 | }
17 |
--------------------------------------------------------------------------------
/spring-cxf/src/main/java/com/bahadirakin/producer/MessageProducerImpl.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.producer;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | import com.bahadirakin.model.HelloWorldMessage;
7 | import com.bahadirakin.model.Person;
8 |
9 | /**
10 | *
11 | * @author bhdrkn
12 | *
13 | */
14 | public class MessageProducerImpl implements MessageProducer {
15 |
16 | /**
17 | *
18 | */
19 | private static final long serialVersionUID = 1L;
20 | private static final Logger logger = LoggerFactory
21 | .getLogger(MessageProducerImpl.class);
22 |
23 | private static final String DEFAULT_HELLOWORLD_MESSAGE_FORMAT = "Hello to %s,%s";
24 |
25 | @Override
26 | public HelloWorldMessage produceHelloWorldMessage(Person person) {
27 | if (person == null) {
28 | logger.info("Person is null");
29 | return new HelloWorldMessage("Hello to everyone");
30 | }
31 |
32 | logger.info("Saying hello to person: {}", person);
33 | return new HelloWorldMessage(String.format(
34 | DEFAULT_HELLOWORLD_MESSAGE_FORMAT, person.getSurname(),
35 | person.getName()));
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/spring-cxf/src/main/java/com/bahadirakin/service/HelloWorldService.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.service;
2 |
3 | import java.io.Serializable;
4 |
5 | import javax.jws.WebMethod;
6 | import javax.jws.WebParam;
7 | import javax.jws.WebResult;
8 | import javax.jws.WebService;
9 | import javax.jws.soap.SOAPBinding;
10 | import javax.jws.soap.SOAPBinding.ParameterStyle;
11 |
12 | import com.bahadirakin.model.HelloWorldMessage;
13 | import com.bahadirakin.model.Person;
14 |
15 | @WebService(name="HelloWorldService", targetNamespace="http://service.bahadirakin.com")
16 | @SOAPBinding(parameterStyle=ParameterStyle.BARE)
17 | public interface HelloWorldService extends Serializable{
18 |
19 | @WebMethod(operationName="sayHelloWorldTo", action="sayHelloWorldTo")
20 | @WebResult(name="helloWorldMessage", partName="helloWorldMessage", targetNamespace="http://model.bahadirakin.com")
21 | HelloWorldMessage sayHelloWorldTo(@WebParam(partName = "person", name = "person", targetNamespace = "http://model.bahadirakin.com/" ) Person person);
22 | }
23 |
--------------------------------------------------------------------------------
/spring-cxf/src/main/java/com/bahadirakin/service/HelloWorldServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.service;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | import com.bahadirakin.model.HelloWorldMessage;
7 | import com.bahadirakin.model.Person;
8 | import com.bahadirakin.producer.MessageProducer;
9 |
10 | public class HelloWorldServiceImpl implements HelloWorldService {
11 |
12 | private static final long serialVersionUID = 1L;
13 | private static final Logger logger = LoggerFactory
14 | .getLogger(HelloWorldMessage.class);
15 |
16 | private MessageProducer messageProducer;
17 |
18 | public HelloWorldServiceImpl(MessageProducer messageProducer) {
19 | super();
20 | logger.info("Hello world service is created");
21 | this.messageProducer = messageProducer;
22 | }
23 |
24 | @Override
25 | public HelloWorldMessage sayHelloWorldTo(Person person) {
26 | logger.info("Saying hello world to {}", person);
27 | return messageProducer.produceHelloWorldMessage(person);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/spring-cxf/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/spring-cxf/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | spring-cxf
7 |
8 |
9 | contextConfigLocation
10 | classpath*:applicationContext.xml
11 |
12 |
13 |
14 | org.springframework.web.context.ContextLoaderListener
15 |
16 |
17 |
18 | CXFServlet
19 | org.apache.cxf.transport.servlet.CXFServlet
20 | 1
21 |
22 |
23 |
24 | CXFServlet
25 | /*
26 |
27 |
28 |
--------------------------------------------------------------------------------
/spring-hazelcast/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.bahadirakin
7 | spring-hazelcast
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | spring-hazelcast
12 | Demo project for Hazelcast and Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.2.3.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | com.bahadirakin.hazelcast.SpringHazelcastApplication
24 | 1.7
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-data-jpa
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-web
35 |
36 |
37 |
38 |
39 | com.hazelcast
40 | hazelcast
41 | 3.4.1
42 |
43 |
44 |
45 | com.h2database
46 | h2
47 | runtime
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-starter-test
52 | test
53 |
54 |
55 |
56 |
57 |
58 |
59 | org.springframework.boot
60 | spring-boot-maven-plugin
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/spring-hazelcast/src/main/java/com/bahadirakin/hazelcast/UserMapStore.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.hazelcast;
2 |
3 | import com.bahadirakin.hazelcast.dao.UserRepository;
4 | import com.bahadirakin.hazelcast.domain.User;
5 | import com.hazelcast.core.MapStore;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 | import org.springframework.transaction.annotation.Transactional;
9 |
10 | import java.util.Collection;
11 | import java.util.HashMap;
12 | import java.util.Map;
13 | import java.util.Set;
14 |
15 | @Service
16 | @Transactional
17 | public class UserMapStore implements MapStore {
18 |
19 | @Autowired
20 | private UserRepository userRepository;
21 |
22 | @Override
23 | public void store(String key, User value) {
24 | userRepository.save(value);
25 | }
26 |
27 | @Override
28 | public void storeAll(Map map) {
29 | for (Map.Entry userEntry : map.entrySet()) {
30 | this.store(userEntry.getKey(), userEntry.getValue());
31 | }
32 | }
33 |
34 | @Override
35 | public void delete(String key) {
36 | userRepository.deleteByUsername(key);
37 | }
38 |
39 | @Override
40 | public void deleteAll(Collection keys) {
41 | for (String key : keys) {
42 | this.delete(key);
43 | }
44 | }
45 |
46 | @Override
47 | public User load(String key) {
48 | return userRepository.findByUsername(key);
49 | }
50 |
51 | @Override
52 | public Map loadAll(Collection keys) {
53 | final Map users = new HashMap<>();
54 | for (String key : keys) {
55 | users.put(key, load(key));
56 | }
57 |
58 | return users;
59 | }
60 |
61 | @Override
62 | public Set loadAllKeys() {
63 | return userRepository.findAllUsernames();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/spring-hazelcast/src/main/java/com/bahadirakin/hazelcast/dao/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.hazelcast.dao;
2 |
3 | import com.bahadirakin.hazelcast.domain.User;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.data.jpa.repository.Query;
6 |
7 | import java.util.Set;
8 |
9 | public interface UserRepository extends JpaRepository {
10 |
11 | User findByUsername(final String username);
12 |
13 | void deleteByUsername(String key);
14 |
15 | @Query("SELECT user.username FROM User user")
16 | Set findAllUsernames();
17 | }
18 |
--------------------------------------------------------------------------------
/spring-hazelcast/src/main/java/com/bahadirakin/hazelcast/domain/User.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.hazelcast.domain;
2 |
3 | import javax.persistence.*;
4 | import java.io.Serializable;
5 |
6 | @Entity
7 | @Access(AccessType.FIELD)
8 | public class User implements Serializable{
9 |
10 | @Id
11 | @GeneratedValue(strategy = GenerationType.AUTO)
12 | private Long id;
13 |
14 | @Column
15 | private String username;
16 |
17 | @Column
18 | private String password;
19 |
20 | @Column
21 | private String email;
22 |
23 | public Long getId() {
24 | return id;
25 | }
26 |
27 | public void setId(Long id) {
28 | this.id = id;
29 | }
30 |
31 | public String getUsername() {
32 | return username;
33 | }
34 |
35 | public void setUsername(String username) {
36 | this.username = username;
37 | }
38 |
39 | public String getPassword() {
40 | return password;
41 | }
42 |
43 | public void setPassword(String password) {
44 | this.password = password;
45 | }
46 |
47 | public String getEmail() {
48 | return email;
49 | }
50 |
51 | public void setEmail(String email) {
52 | this.email = email;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/spring-hazelcast/src/main/java/com/bahadirakin/hazelcast/rest/UserRestService.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.hazelcast.rest;
2 |
3 | import com.bahadirakin.hazelcast.domain.User;
4 | import com.hazelcast.core.HazelcastInstance;
5 | import com.hazelcast.core.IMap;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.web.bind.annotation.PathVariable;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RequestMethod;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | @RestController
13 | public class UserRestService {
14 |
15 | private IMap userMap;
16 |
17 | @Autowired
18 | public UserRestService(HazelcastInstance hazelcastInstance){
19 | this.userMap = hazelcastInstance.getMap("userMap");
20 | }
21 |
22 | @RequestMapping(method = RequestMethod.GET, value = "/user/{username}")
23 | public User getUserWithUsername(@PathVariable(value = "username") final String username) {
24 | return userMap.get(username);
25 | }
26 |
27 | @RequestMapping(method = RequestMethod.PUT, value = "/user/{username}")
28 | public void updateUserWithUsername(@PathVariable(value = "username") final String username, final User user) {
29 | assert username.equals(user.getUsername());
30 | userMap.put(username, user);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/spring-hazelcast/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bhdrkn/Java-Examples/3b3cc50211e3313a0dbbeb7d342220fbd0f7cf80/spring-hazelcast/src/main/resources/application.properties
--------------------------------------------------------------------------------
/spring-hazelcast/src/main/resources/import.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO user (id, username, password, email) VALUES (1, 'bhdrkn', '1q2w3e', 'bhdrkn[at]gmail.com');
--------------------------------------------------------------------------------
/spring-hazelcast/src/test/java/com/bahadirakin/hazelcast/SpringHazelcastApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.hazelcast;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.test.context.web.WebAppConfiguration;
6 | import org.springframework.boot.test.SpringApplicationConfiguration;
7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
8 |
9 | @RunWith(SpringJUnit4ClassRunner.class)
10 | @SpringApplicationConfiguration(classes = SpringHazelcastApplication.class)
11 | @WebAppConfiguration
12 | public class SpringHazelcastApplicationTests {
13 |
14 | @Test
15 | public void contextLoads() {
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spring-hibernate-5/src/main/java/com/bahadirakin/SpringHibernate5Application.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin;
2 |
3 | import org.springframework.boot.CommandLineRunner;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | public class SpringHibernate5Application implements CommandLineRunner {
9 |
10 | public static void main(String[] args) {
11 | SpringApplication.run(SpringHibernate5Application.class, args);
12 | }
13 |
14 | @Override
15 | public void run(String... strings) throws Exception {
16 | System.out.println("Hello, World!");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/spring-hibernate-5/src/main/java/com/bahadirakin/entity/User.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.entity;
2 |
3 | import org.hibernate.envers.Audited;
4 |
5 | import javax.persistence.*;
6 |
7 | @Entity
8 | @Table(name = "T_USER")
9 | @Access(AccessType.FIELD)
10 | @Audited
11 | public class User {
12 |
13 | @Id
14 | @GeneratedValue(strategy = GenerationType.AUTO)
15 | private Long id;
16 |
17 | @Column(name = "C_USERNAME", unique = true)
18 | private String username;
19 |
20 | @Column(name = "C_PASSWORD")
21 | private String password;
22 |
23 | @Column(name = "C_EMAIL")
24 | private String email;
25 |
26 | public Long getId() {
27 | return id;
28 | }
29 |
30 | public void setId(Long id) {
31 | this.id = id;
32 | }
33 |
34 | public String getUsername() {
35 | return username;
36 | }
37 |
38 | public void setUsername(String username) {
39 | this.username = username;
40 | }
41 |
42 | public String getPassword() {
43 | return password;
44 | }
45 |
46 | public void setPassword(String password) {
47 | this.password = password;
48 | }
49 |
50 | public String getEmail() {
51 | return email;
52 | }
53 |
54 | public void setEmail(String email) {
55 | this.email = email;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/spring-hibernate-5/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bhdrkn/Java-Examples/3b3cc50211e3313a0dbbeb7d342220fbd0f7cf80/spring-hibernate-5/src/main/resources/application.properties
--------------------------------------------------------------------------------
/spring-hibernate-5/src/test/java/com/bahadirakin/SpringHibernate5ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.SpringApplicationConfiguration;
6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
7 |
8 | @RunWith(SpringJUnit4ClassRunner.class)
9 | @SpringApplicationConfiguration(classes = SpringHibernate5Application.class)
10 | public class SpringHibernate5ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-jpa/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Eclipse #
3 | ###########
4 | .classpath
5 | /.settings
6 | .project
7 | /target
8 |
9 | # Compiled source #
10 | ###################
11 | *.com
12 | *.class
13 | *.dll
14 | *.exe
15 | *.o
16 | *.so
17 |
18 | # Packages #
19 | ############
20 | # it's better to unpack these files and commit the raw source
21 | # git has its own built in compression methods
22 | *.7z
23 | *.dmg
24 | *.gz
25 | *.iso
26 | *.jar
27 | *.rar
28 | *.tar
29 | *.zip
30 |
31 | # Logs and databases #
32 | ######################
33 | *.log
34 | *.sql
35 | *.sqlite
36 |
37 | # OS generated files #
38 | ######################
39 | .DS_Store
40 | .DS_Store?
41 | ._*
42 | .Spotlight-V100
43 | .Trashes
44 | ehthumbs.db
45 | Thumbs.db
46 |
47 |
--------------------------------------------------------------------------------
/spring-jpa/src/main/java/com/bahadirakin/App.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.context.support.AbstractApplicationContext;
6 | import org.springframework.context.support.ClassPathXmlApplicationContext;
7 |
8 | import com.bahadirakin.model.Car;
9 | import com.bahadirakin.service.CarService;
10 | import com.bahadirakin.service.ICarService;
11 |
12 |
13 | /**
14 | * Hello world!
15 | *
16 | */
17 | public class App {
18 | public static void main(String[] args) throws InterruptedException {
19 | System.out.println("Application is going to be started");
20 | final AbstractApplicationContext applContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
21 | applContext.registerShutdownHook();
22 | System.out.println("Application is started");
23 |
24 | final ICarService carService = (ICarService) applContext.getBean("carService");
25 | final List cars = carService.getAllCars();
26 |
27 | if(cars == null || cars.isEmpty()){
28 | System.out.println("Cars is empty.");
29 |
30 | }else{
31 | System.out.println("Cars: " + cars);
32 | }
33 |
34 | Thread.sleep(10000);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/spring-jpa/src/main/java/com/bahadirakin/dao/CarDao.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.dao;
2 |
3 | import java.util.List;
4 |
5 | import javax.persistence.EntityManager;
6 | import javax.persistence.PersistenceContext;
7 |
8 | import org.springframework.transaction.annotation.Propagation;
9 | import org.springframework.transaction.annotation.Transactional;
10 |
11 | import com.bahadirakin.model.Car;
12 |
13 | @Transactional(propagation = Propagation.MANDATORY, rollbackFor = Exception.class, value = "transactionManager")
14 | public class CarDao implements ICarDao {
15 |
16 | private static final long serialVersionUID = 1L;
17 |
18 | @PersistenceContext(unitName = "entityManagerFactory")
19 | private EntityManager entityManager;
20 |
21 | public EntityManager getEntityManager() {
22 | return entityManager;
23 | }
24 |
25 | public void setEntityManager(EntityManager entityManager) {
26 | this.entityManager = entityManager;
27 | }
28 |
29 | /* (non-Javadoc)
30 | * @see com.bahadirakin.dao.ICarDao#detach(java.lang.Object)
31 | */
32 | @Override
33 | public void detach(Object arg0) {
34 | entityManager.detach(arg0);
35 | }
36 |
37 | /* (non-Javadoc)
38 | * @see com.bahadirakin.dao.ICarDao#findAll()
39 | */
40 | @Override
41 | public List findAll() {
42 | System.out.println(entityManager);
43 | return entityManager.createQuery("SELECT car FROM Car car").getResultList();
44 | }
45 |
46 | /* (non-Javadoc)
47 | * @see com.bahadirakin.dao.ICarDao#merge(com.bahadirakin.model.Car)
48 | */
49 | @Override
50 | public Car merge(Car arg0) {
51 | return entityManager.merge(arg0);
52 | }
53 |
54 | /* (non-Javadoc)
55 | * @see com.bahadirakin.dao.ICarDao#persist(com.bahadirakin.model.Car)
56 | */
57 | @Override
58 | public void persist(Car arg0) {
59 | entityManager.persist(arg0);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/spring-jpa/src/main/java/com/bahadirakin/dao/ICarDao.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.dao;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import com.bahadirakin.model.Car;
7 |
8 | public interface ICarDao extends Serializable{
9 |
10 | void detach(Object arg0);
11 |
12 | List findAll();
13 |
14 | Car merge(Car arg0);
15 |
16 | void persist(Car arg0);
17 |
18 | }
--------------------------------------------------------------------------------
/spring-jpa/src/main/java/com/bahadirakin/model/Car.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | import javax.persistence.Column;
6 | import javax.persistence.Entity;
7 | import javax.persistence.GeneratedValue;
8 | import javax.persistence.Id;
9 | import javax.persistence.Table;
10 |
11 | @Entity
12 | @Table(name = "car")
13 | public class Car implements Serializable {
14 |
15 | private static final long serialVersionUID = 1L;
16 |
17 | @Id
18 | @GeneratedValue
19 | private Long id;
20 |
21 | @Column(name = "brand")
22 | private String brand;
23 |
24 | @Column(name = "year")
25 | private int year;
26 |
27 | @Column(name = "color")
28 | private String color;
29 |
30 | @Column(name = "price")
31 | private Double price;
32 |
33 | public Car() {
34 | }
35 |
36 | public Long getId() {
37 | return id;
38 | }
39 |
40 | public void setId(Long id) {
41 | this.id = id;
42 | }
43 |
44 | public String getBrand() {
45 | return brand;
46 | }
47 |
48 | public void setBrand(String brand) {
49 | this.brand = brand;
50 | }
51 |
52 | public int getYear() {
53 | return year;
54 | }
55 |
56 | public void setYear(int year) {
57 | this.year = year;
58 | }
59 |
60 | public String getColor() {
61 | return color;
62 | }
63 |
64 | public void setColor(String color) {
65 | this.color = color;
66 | }
67 |
68 | public Double getPrice() {
69 | return price;
70 | }
71 |
72 | public void setPrice(Double price) {
73 | this.price = price;
74 | }
75 |
76 | @Override
77 | public String toString() {
78 | return "Car [id=" + id + ", brand=" + brand + ", year=" + year
79 | + ", color=" + color + ", price=" + price + "]";
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/spring-jpa/src/main/java/com/bahadirakin/service/CarService.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.service;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.beans.factory.annotation.Qualifier;
7 | import org.springframework.stereotype.Component;
8 | import org.springframework.stereotype.Service;
9 | import org.springframework.transaction.annotation.Propagation;
10 | import org.springframework.transaction.annotation.Transactional;
11 |
12 | import com.bahadirakin.dao.ICarDao;
13 | import com.bahadirakin.model.Car;
14 |
15 | @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, value = "transactionManager")
16 | public class CarService implements ICarService {
17 |
18 | private static final long serialVersionUID = 1L;
19 |
20 | private ICarDao carDao;
21 |
22 | /*
23 | * (non-Javadoc)
24 | *
25 | * @see com.bahadirakin.service.ICarService#delete(java.lang.Object)
26 | */
27 | @Override
28 | public void delete(Object arg0) {
29 | carDao.detach(arg0);
30 | }
31 |
32 | /*
33 | * (non-Javadoc)
34 | *
35 | * @see com.bahadirakin.service.ICarService#getAllCars()
36 | */
37 | @Override
38 | public List getAllCars() {
39 | return carDao.findAll();
40 | }
41 |
42 | /*
43 | * (non-Javadoc)
44 | *
45 | * @see
46 | * com.bahadirakin.service.ICarService#updateCar(com.bahadirakin.model.Car)
47 | */
48 | @Override
49 | public Car updateCar(Car arg0) {
50 | return carDao.merge(arg0);
51 | }
52 |
53 | /*
54 | * (non-Javadoc)
55 | *
56 | * @see
57 | * com.bahadirakin.service.ICarService#createNewCar(com.bahadirakin.model
58 | * .Car)
59 | */
60 | @Override
61 | public void createNewCar(Car arg0) {
62 | carDao.persist(arg0);
63 | }
64 |
65 | public ICarDao getCarDao() {
66 | return carDao;
67 | }
68 |
69 | public void setCarDao(ICarDao carDao) {
70 | this.carDao = carDao;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/spring-jpa/src/main/java/com/bahadirakin/service/ICarService.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.service;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import org.springframework.stereotype.Service;
7 |
8 | import com.bahadirakin.model.Car;
9 |
10 | public interface ICarService extends Serializable{
11 |
12 | void delete(Object arg0);
13 |
14 | List getAllCars();
15 |
16 | Car updateCar(Car arg0);
17 |
18 | void createNewCar(Car arg0);
19 |
20 | }
--------------------------------------------------------------------------------
/spring-jpa/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/spring-jpa/src/main/resources/environment/persistance-dev.properties:
--------------------------------------------------------------------------------
1 | # JDBC Bilgileri
2 | jdbc.driverClassName=org.h2.Driver
3 | jdbc.url=jdbc\:h2\:~/h2SpringJpaTutorialDb;AUTO_SERVER\=TRUE
4 | jdbc.username=bhdrkn
5 | jdbc.password=1q2w3e
6 |
7 | hibernate.default_schema=H2SPRINGJPATUTORIALDB.PUBLIC
8 |
9 | # https://docs.jboss.org/hibernate/core/4.2/manual/en-US/html/ch03.html#configuration-optional-properties
10 | hibernate.ejb.naming_strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy
11 | hibernate.hbm2ddl.auto=create
12 | hibernate.showSql=true
13 | hibernate.formatSql=true
14 | hibernate.generate_statistics=true
15 | hibernate.max_fetch_depth=3
16 | hibernate.default_batch_fetch_size=16
17 | hibernate.jdbc.batch_size=20
18 | hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
19 | hibernate.cache.use_query_cache=true
20 | hibernate.cache.use_second_level_cache=false
--------------------------------------------------------------------------------
/spring-jpa/src/main/resources/environment/persistance-prod.properties:
--------------------------------------------------------------------------------
1 | # JDBC Bilgileri
2 | jdbc.driverClassName=org.postgresql.Driver
3 | jdbc.url=jdbc\:postgresql\://localhost\:5432/SpringJpaTutorialDb?characterEncoding\=UTF-8
4 | jdbc.username=bhdrkn
5 | jdbc.password=1q2w3e
6 |
7 | hibernate.default_schema=SpringJpaTutorialDb
8 |
9 | # https://docs.jboss.org/hibernate/core/4.2/manual/en-US/html/ch03.html#configuration-optional-properties
10 | hibernate.ejb.naming_strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy
11 | hibernate.hbm2ddl.auto=update
12 | hibernate.showSql=false
13 | hibernate.formatSql=false
14 | hibernate.generate_statistics=false
15 | hibernate.max_fetch_depth=3
16 | hibernate.default_batch_fetch_size=16
17 | hibernate.jdbc.batch_size=20
18 | hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
19 | hibernate.cache.use_query_cache=true
20 | hibernate.cache.use_second_level_cache=true
--------------------------------------------------------------------------------
/spring-jpa/src/main/resources/environment/persistance-uat.properties:
--------------------------------------------------------------------------------
1 | # JDBC Bilgileri
2 | jdbc.driverClassName=com.mysql.jdbc.Driver
3 | jdbc.url=jdbc\:mysql\://localhost\:3306/SpringJpaTutorialDb?characterEncoding\=UTF-8
4 | jdbc.username=bhdrkn
5 | jdbc.password=1q2w3e
6 |
7 | hibernate.default_schema=SpringJpaTutorialDb
8 |
9 | # https://docs.jboss.org/hibernate/core/4.2/manual/en-US/html/ch03.html#configuration-optional-properties
10 | hibernate.ejb.naming_strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy
11 | hibernate.hbm2ddl.auto=update
12 | hibernate.showSql=true
13 | hibernate.formatSql=true
14 | hibernate.generate_statistics=false
15 | hibernate.max_fetch_depth=3
16 | hibernate.default_batch_fetch_size=16
17 | hibernate.jdbc.batch_size=20
18 | hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
19 | hibernate.cache.use_query_cache=true
20 | hibernate.cache.use_second_level_cache=false
21 |
--------------------------------------------------------------------------------
/spring-jpa/src/test/java/com/bahadirakin/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-prime/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Eclipse #
3 | ###########
4 | .classpath
5 | /.settings
6 | .project
7 | /target
8 |
9 | # Compiled source #
10 | ###################
11 | *.com
12 | *.class
13 | *.dll
14 | *.exe
15 | *.o
16 | *.so
17 |
18 | # Packages #
19 | ############
20 | # it's better to unpack these files and commit the raw source
21 | # git has its own built in compression methods
22 | *.7z
23 | *.dmg
24 | *.gz
25 | *.iso
26 | *.jar
27 | *.rar
28 | *.tar
29 | *.zip
30 |
31 | # Logs and databases #
32 | ######################
33 | *.log
34 | *.sql
35 | *.sqlite
36 |
37 | # OS generated files #
38 | ######################
39 | .DS_Store
40 | .DS_Store?
41 | ._*
42 | .Spotlight-V100
43 | .Trashes
44 | ehthumbs.db
45 | Thumbs.db
46 |
47 |
--------------------------------------------------------------------------------
/spring-prime/src/main/java/com/bahadirakin/service/ICarService.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.service;
2 |
3 | import java.util.List;
4 |
5 | import com.bahadirakin.model.Car;
6 |
7 | public interface ICarService {
8 |
9 | List getAllCars();
10 |
11 | void saveCar(final Car car);
12 | }
13 |
--------------------------------------------------------------------------------
/spring-prime/src/main/java/com/bahadirakin/service/RandomCarService.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.service;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.UUID;
6 |
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | import com.bahadirakin.model.Car;
11 |
12 | public class RandomCarService implements ICarService {
13 |
14 | private static final Logger logger = LoggerFactory
15 | .getLogger(RandomCarService.class);
16 |
17 | private static final int RANDOM_LIST_SIZE = 25;
18 |
19 | private static final String[] COLORS = new String[] { "Black", "White",
20 | "Green", "Red", "Blue", "Orange", "Silver", "Yellow", "Brown",
21 | "Maroon" };
22 |
23 | private static final String[] BRANDS = new String[] { "BMW", "Mercedes",
24 | "Volvo", "Audi", "Renault", "Fiat", "Volkswagen", "Honda",
25 | "Jaguar", "Ford" };
26 |
27 | private List savedCars;
28 |
29 | public RandomCarService() {
30 | savedCars = new ArrayList<>();
31 | }
32 |
33 | @Override
34 | public List getAllCars() {
35 | final List list = new ArrayList();
36 | list.addAll(savedCars);
37 |
38 | for (int i = 0; i < RANDOM_LIST_SIZE; i++) {
39 | list.add(new Car(getRandomId(), getRandomBrand(), getRandomYear(),
40 | getRandomColor(), getRandomPrice()));
41 | }
42 |
43 | logger.info("Returning all the cars with size {}", list.size());
44 | return list;
45 | }
46 |
47 | @Override
48 | public void saveCar(Car car) {
49 | car.setId(getRandomId());
50 | savedCars.add(car);
51 | logger.info("Car is saved: {}", car);
52 | }
53 |
54 | private String getRandomId() {
55 | return UUID.randomUUID().toString().substring(0, 8);
56 | }
57 |
58 | private int getRandomYear() {
59 | return (int) (Math.random() * 50 + 1960);
60 | }
61 |
62 | private String getRandomColor() {
63 | return COLORS[(int) (Math.random() * COLORS.length)];
64 | }
65 |
66 | private String getRandomBrand() {
67 | return BRANDS[(int) (Math.random() * BRANDS.length)];
68 | }
69 |
70 | private int getRandomPrice() {
71 | return (int) (Math.random() * 100000);
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/spring-prime/src/main/java/com/bahadirakin/webapp/CarBean.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.webapp;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import javax.annotation.PostConstruct;
7 |
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.context.annotation.Scope;
12 | import org.springframework.stereotype.Component;
13 |
14 | import com.bahadirakin.model.Car;
15 | import com.bahadirakin.service.ICarService;
16 |
17 | @Component
18 | @Scope("request")
19 | public class CarBean implements Serializable {
20 |
21 | private static final long serialVersionUID = 1L;
22 | private static final Logger logger = LoggerFactory.getLogger(CarBean.class);
23 |
24 | @Autowired
25 | private ICarService carService;
26 | private Car car;
27 |
28 | private List cars;
29 |
30 | public CarBean() {
31 | super();
32 | }
33 |
34 | @PostConstruct
35 | public void init() {
36 | this.car = new Car();
37 | this.cars = carService.getAllCars();
38 | }
39 |
40 | public void save() {
41 | logger.info("new car is going to be saved: {} ", this.car);
42 | this.carService.saveCar(car);
43 | this.init();
44 | }
45 |
46 | public Car getCar() {
47 | return car;
48 | }
49 |
50 | public void setCar(Car car) {
51 | this.car = car;
52 | }
53 |
54 | public ICarService getCarService() {
55 | return carService;
56 | }
57 |
58 | public void setCarService(ICarService carService) {
59 | this.carService = carService;
60 | }
61 |
62 | public List getCars() {
63 | return cars;
64 | }
65 |
66 | public void setCars(List cars) {
67 | this.cars = cars;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/spring-prime/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/spring-prime/src/main/webapp/WEB-INF/faces-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 | org.springframework.web.jsf.el.SpringBeanFacesELResolver
11 |
12 |
13 | tr
14 | tr
15 |
16 |
17 | org.primefaces.application.DialogActionListener
18 | org.primefaces.application.DialogNavigationHandler
19 | org.primefaces.application.DialogViewHandler
20 |
21 |
22 |
23 |
24 | org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spring-prime/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
5 | spring-prime
6 |
7 |
8 |
9 |
10 | contextConfigLocation
11 | classpath*:applicationContext.xml
12 |
13 |
14 |
15 | javax.faces.PROJECT_STAGE
16 | Development
17 |
18 |
19 |
20 | javax.faces.DEFAULT_SUFFIX
21 | .xhtml
22 |
23 |
24 |
25 |
26 |
27 | org.springframework.web.context.ContextLoaderListener
28 |
29 |
30 |
31 | org.springframework.web.context.request.RequestContextListener
32 |
33 |
34 |
35 | com.sun.faces.config.ConfigureListener
36 |
37 |
38 |
39 |
40 |
41 | Faces Servlet
42 | javax.faces.webapp.FacesServlet
43 | 1
44 |
45 |
46 |
47 | Faces Servlet
48 | /faces/*
49 |
50 |
51 | Faces Servlet
52 | *.jsf
53 |
54 |
55 | Faces Servlet
56 | *.faces
57 |
58 |
59 | Faces Servlet
60 | *.xhtml
61 |
62 |
63 |
64 | index.xhtml
65 |
66 |
67 |
--------------------------------------------------------------------------------
/spring-prime/src/main/webapp/index.xhtml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/spring-quartz/src/main/java/com/bahadirakin/App.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.ConfigurableApplicationContext;
5 | import org.springframework.context.support.ClassPathXmlApplicationContext;
6 |
7 | import java.util.Date;
8 |
9 | /**
10 | * Hello world!
11 | */
12 | public class App {
13 | public static void main(String[] args) {
14 | final ApplicationContext applicationContext = new ClassPathXmlApplicationContext
15 | ("classpath*:application-context.xml");
16 |
17 | Thread shutdownThread = new Thread() {
18 |
19 | public void run() {
20 | if (applicationContext instanceof ConfigurableApplicationContext) {
21 | ((ConfigurableApplicationContext) applicationContext).close();
22 | }
23 | }
24 | };
25 | Runtime.getRuntime().addShutdownHook(shutdownThread);
26 |
27 | final SchedulerController schedulerController = applicationContext.getBean(SchedulerController.class);
28 | schedulerController.addJob(new DatabaseMonitor(new Date().toString(), "sql query"));
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/spring-quartz/src/main/java/com/bahadirakin/DatabaseJob.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin;
2 |
3 | import org.quartz.Job;
4 | import org.quartz.JobDataMap;
5 | import org.quartz.JobExecutionContext;
6 | import org.quartz.JobExecutionException;
7 |
8 | import java.io.Serializable;
9 |
10 | public class DatabaseJob implements Job, Serializable {
11 | @Override
12 | public void execute(JobExecutionContext context) throws JobExecutionException {
13 | final JobDataMap jobDataMap = context.getMergedJobDataMap();
14 | final String sqlQuery = jobDataMap.getString("sqlQuery");
15 | System.out.println("SqlQuery: " + sqlQuery);
16 | }
17 | }
--------------------------------------------------------------------------------
/spring-quartz/src/main/java/com/bahadirakin/DatabaseMonitor.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin;
2 |
3 | public class DatabaseMonitor {
4 |
5 | private Integer id;
6 | private String name;
7 | private String sqlQuery;
8 |
9 | public DatabaseMonitor() {
10 | }
11 |
12 | public DatabaseMonitor(String name, String sqlQuery) {
13 | this.name = name;
14 | this.sqlQuery = sqlQuery;
15 | }
16 |
17 | public Integer getId() {
18 | return id;
19 | }
20 |
21 | public void setId(Integer id) {
22 | this.id = id;
23 | }
24 |
25 | public String getName() {
26 | return name;
27 | }
28 |
29 | public void setName(String name) {
30 | this.name = name;
31 | }
32 |
33 | public String getSqlQuery() {
34 | return sqlQuery;
35 | }
36 |
37 | public void setSqlQuery(String sqlQuery) {
38 | this.sqlQuery = sqlQuery;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/spring-quartz/src/main/java/com/bahadirakin/SchedulerController.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin;
2 |
3 | import org.quartz.JobDataMap;
4 | import org.quartz.Scheduler;
5 | import org.quartz.SchedulerException;
6 | import org.quartz.impl.JobDetailImpl;
7 | import org.quartz.impl.triggers.CronTriggerImpl;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Component;
10 |
11 | import java.text.ParseException;
12 |
13 | @Component
14 | public class SchedulerController {
15 |
16 | @Autowired
17 | Scheduler scheduler;
18 |
19 | public void addJob(DatabaseMonitor databaseMonitor) {
20 |
21 | final JobDataMap jobDataMap = new JobDataMap();
22 | jobDataMap.put("sqlQuery", databaseMonitor.getSqlQuery());
23 | final JobDetailImpl jobDetail = new JobDetailImpl();
24 | jobDetail.setName(databaseMonitor.getName());
25 | jobDetail.setDurability(true);
26 | jobDetail.setJobDataMap(jobDataMap);
27 | jobDetail.setJobClass(DatabaseJob.class);
28 |
29 | try {
30 | final CronTriggerImpl trigger = new CronTriggerImpl();
31 | trigger.setCronExpression("0/2 * * * * ?");
32 | trigger.setName(databaseMonitor.getName());
33 | scheduler.scheduleJob(jobDetail, trigger);
34 | } catch (ParseException | SchedulerException e) {
35 | e.printStackTrace();
36 | }
37 | }
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/spring-rabbitmq/Vagrantfile:
--------------------------------------------------------------------------------
1 |
2 | Vagrant.configure(2) do |config|
3 | config.vm.box = "ubuntu/trusty64"
4 | config.vm.network "private_network", ip: "192.168.33.10"
5 | config.vm.provision "shell", inline: <<-SHELL
6 | echo 'deb http://www.rabbitmq.com/debian/ testing main' >/etc/apt/sources.list.d/rabbitmq.list
7 | wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
8 | apt-key add rabbitmq-signing-key-public.asc
9 | apt-get update
10 |
11 | apt-get install -q -y rabbitmq-server
12 |
13 | # RabbitMQ Plugins
14 | service rabbitmq-server stop
15 | rabbitmq-plugins enable rabbitmq_management
16 | SHELL
17 | config.vm.provision "file", source:"./rabbitmq.config", destination:"~/rabbitmq.config"
18 | config.vm.provision "shell", inline: <<-SHELL
19 | cp /home/vagrant/rabbitmq.config /etc/rabbitmq/rabbitmq.config
20 | # Start service
21 | service rabbitmq-server start
22 | rabbitmq-plugins list
23 | SHELL
24 | end
25 |
--------------------------------------------------------------------------------
/spring-rabbitmq/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.bahadirakin.amqp
7 | spring-rabbitmq
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | spring-rabbitmq
12 | Demo project for Spring amqp
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.2.4.RELEASE
18 |
19 |
20 |
21 |
22 |
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-amqp
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-maven-plugin
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/spring-rabbitmq/rabbitmq.config:
--------------------------------------------------------------------------------
1 | %% -*- mode: erlang -*-
2 | [
3 | {rabbit,
4 | [
5 | {tcp_listeners, [5672]},
6 | {log_levels, [{connection, info}, {channel, info}]},
7 | {loopback_users, []},
8 | {auth_mechanisms, ['PLAIN', 'AMQPLAIN']},
9 | {default_vhost, <<"/">>},
10 | {default_user, <<"guest">>},
11 | {default_pass, <<"guest">>},
12 | {default_permissions, [<<".*">>, <<".*">>, <<".*">>]},
13 | {default_user_tags, [administrator]}
14 | ]}
15 | ].
16 |
--------------------------------------------------------------------------------
/spring-rabbitmq/src/main/java/com/bahadirakin/amqp/consumer/HelloMessageConsumer.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.amqp.consumer;
2 |
3 | import com.bahadirakin.amqp.message.HelloMessage;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 |
7 | public class HelloMessageConsumer {
8 |
9 | private static final Logger logger = LoggerFactory.getLogger(HelloMessageConsumer.class);
10 |
11 | public void onHelloMessage(final HelloMessage message) {
12 | logger.info("{} from {}", message.getMessage(), message.getFrom());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/spring-rabbitmq/src/main/java/com/bahadirakin/amqp/message/HelloMessage.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.amqp.message;
2 |
3 | import java.io.Serializable;
4 |
5 | public class HelloMessage implements Serializable {
6 |
7 | private String message;
8 | private String from;
9 |
10 | public String getMessage() {
11 | return message;
12 | }
13 |
14 | public void setMessage(String message) {
15 | this.message = message;
16 | }
17 |
18 | public String getFrom() {
19 | return from;
20 | }
21 |
22 | public void setFrom(String from) {
23 | this.from = from;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-rabbitmq/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.rabbitmq.host=192.168.33.10
2 | spring.rabbitmq.port=5672
3 | spring.rabbitmq.username=guest
4 | spring.rabbitmq.password=guest
--------------------------------------------------------------------------------
/spring-rabbitmq/src/test/java/com/bahadirakin/amqp/SpringRabbitmqApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.amqp;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.SpringApplicationConfiguration;
6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
7 |
8 | @RunWith(SpringJUnit4ClassRunner.class)
9 | @SpringApplicationConfiguration(classes = SpringRabbitmqApplication.class)
10 | public class SpringRabbitmqApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-redis/Vagrantfile:
--------------------------------------------------------------------------------
1 | # -*- mode: ruby -*-
2 | # vi: set ft=ruby ts=2 sw=2 expandtab:
3 |
4 | Vagrant.configure(2) do |config|
5 | config.vm.box = "ubuntu/trusty64"
6 | config.vm.network "private_network", ip: "192.168.33.10"
7 | config.vm.provision "shell", inline: <<-SHELL
8 | apt-get update
9 | apt-get install build-essential
10 | apt-get install tcl8.5
11 |
12 | wget http://download.redis.io/releases/redis-stable.tar.gz
13 | tar xzf redis-stable.tar.gz
14 | cd redis-stable
15 | make
16 | make test
17 | make install
18 | cd utils
19 | ./install_server.sh
20 |
21 | update-rc.d redis_6379 defaults
22 | SHELL
23 | end
24 |
--------------------------------------------------------------------------------
/spring-redis/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.bahadirakin
7 | spring-redis
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | spring-redis
12 | Demo project for Redis
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.2.5.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | 1.8
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-redis
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-test
35 | test
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-maven-plugin
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/spring-redis/src/main/java/com/bahadirakin/redis/SomeLongBusiness.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.redis;
2 |
3 | public interface SomeLongBusiness {
4 |
5 | String doSomeHeavyWork(String input);
6 | }
7 |
--------------------------------------------------------------------------------
/spring-redis/src/main/java/com/bahadirakin/redis/SomeLongBusinessImpl.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.redis;
2 |
3 | import org.springframework.cache.annotation.Cacheable;
4 |
5 | public class SomeLongBusinessImpl implements SomeLongBusiness {
6 |
7 | @Cacheable(value = "resultCache2")
8 | @Override
9 | public String doSomeHeavyWork(String input) {
10 | try {
11 | Thread.sleep(5000);
12 | return "Result: " + input;
13 | } catch (InterruptedException e) {
14 | throw new RuntimeException(e);
15 | }
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/spring-redis/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.redis.host=192.168.33.10
2 | spring.redis.port=6379
--------------------------------------------------------------------------------
/spring-redis/src/test/java/com/bahadirakin/redis/SpringRedisApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.redis;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.SpringApplicationConfiguration;
6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
7 |
8 | @RunWith(SpringJUnit4ClassRunner.class)
9 | @SpringApplicationConfiguration(classes = SpringRedisApplication.class)
10 | public class SpringRedisApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/test-with-mockito/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Eclipse #
3 | ###########
4 | .classpath
5 | /.settings
6 | .project
7 | /target
8 |
9 | # Intellij
10 | .idea/
11 | *.iml
12 | *.iws
13 |
14 | # Compiled source #
15 | ###################
16 | *.com
17 | *.class
18 | *.dll
19 | *.exe
20 | *.o
21 | *.so
22 |
23 | # Packages #
24 | ############
25 | # it's better to unpack these files and commit the raw source
26 | # git has its own built in compression methods
27 | *.7z
28 | *.dmg
29 | *.gz
30 | *.iso
31 | *.jar
32 | *.rar
33 | *.tar
34 | *.zip
35 |
36 | # Logs and databases #
37 | ######################
38 | *.log
39 | *.sql
40 | *.sqlite
41 |
42 | # OS generated files #
43 | ######################
44 | .DS_Store
45 | .DS_Store?
46 | ._*
47 | .Spotlight-V100
48 | .Trashes
49 | ehthumbs.db
50 | Thumbs.db
51 |
52 |
--------------------------------------------------------------------------------
/test-with-mockito/src/main/java/com/bahadirakin/controllers/LoginController.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.controllers;
2 |
3 | import com.bahadirakin.entities.User;
4 | import com.bahadirakin.exceptions.UserNotFoundException;
5 | import com.bahadirakin.services.IUserService;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | import java.io.Serializable;
10 |
11 | /**
12 | * Created by bhdrkn on 08/11/14.
13 | */
14 | public class LoginController implements Serializable {
15 |
16 | private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
17 |
18 | private IUserService userService;
19 |
20 | public LoginController(IUserService userService) {
21 | this.userService = userService;
22 | }
23 |
24 | public String authenticate(final User user) {
25 |
26 | try {
27 | if (userService.authenticate(user)) {
28 | return "homePage";
29 | } else {
30 | return "errorPage?message=wrongPassword";
31 | }
32 | } catch (UserNotFoundException e) {
33 | logger.error("User not found for usernmae: {}", user.getUsername(), e);
34 | return "errorPage?message=userNotFound";
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/test-with-mockito/src/main/java/com/bahadirakin/entities/User.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.entities;
2 |
3 | /**
4 | * Created by bhdrkn on 08/11/14.
5 | */
6 | public class User {
7 |
8 | private Long id;
9 |
10 | private String username;
11 |
12 | private String password;
13 |
14 | public Long getId() {
15 | return id;
16 | }
17 |
18 | public void setId(Long id) {
19 | this.id = id;
20 | }
21 |
22 | public String getUsername() {
23 | return username;
24 | }
25 |
26 | public void setUsername(String username) {
27 | this.username = username;
28 | }
29 |
30 | public String getPassword() {
31 | return password;
32 | }
33 |
34 | public void setPassword(String password) {
35 | this.password = password;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/test-with-mockito/src/main/java/com/bahadirakin/exceptions/UserNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.exceptions;
2 |
3 | /**
4 | * Created by bhdrkn on 08/11/14.
5 | */
6 | public class UserNotFoundException extends Exception {
7 |
8 | public UserNotFoundException() {
9 | }
10 |
11 | public UserNotFoundException(String message) {
12 | super(message);
13 | }
14 |
15 | public UserNotFoundException(String message, Throwable cause) {
16 | super(message, cause);
17 | }
18 |
19 | public UserNotFoundException(Throwable cause) {
20 | super(cause);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test-with-mockito/src/main/java/com/bahadirakin/services/IUserService.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.services;
2 |
3 | import com.bahadirakin.entities.User;
4 | import com.bahadirakin.exceptions.UserNotFoundException;
5 |
6 | /**
7 | * Created by bhdrkn on 08/11/14.
8 | */
9 | public interface IUserService {
10 |
11 | boolean authenticate(final User user) throws UserNotFoundException;
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/user-application/Procfile:
--------------------------------------------------------------------------------
1 | web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war
2 |
--------------------------------------------------------------------------------
/user-application/src/main/java/com/bahadirakin/dao/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.dao;
2 |
3 | import com.bahadirakin.model.User;
4 | import org.springframework.data.mongodb.repository.MongoRepository;
5 |
6 | /**
7 | * Created by bhdrkn on 08/02/15.
8 | */
9 | public interface UserRepository extends MongoRepository {
10 |
11 | User findByEmail(final String email);
12 | User findByUsernameAndPassword(final String username, final String password);
13 | }
14 |
--------------------------------------------------------------------------------
/user-application/src/main/java/com/bahadirakin/model/User.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.model;
2 |
3 | import org.springframework.data.annotation.Id;
4 | import org.springframework.data.mongodb.core.index.Indexed;
5 | import org.springframework.data.mongodb.core.mapping.Document;
6 |
7 | import java.io.Serializable;
8 |
9 | /**
10 | * Created by bhdrkn on 08/02/15.
11 | */
12 | @Document(collection = "user")
13 | public class User implements Serializable {
14 |
15 | @Id
16 | private String id;
17 | @Indexed(unique = true)
18 | private String username;
19 | @Indexed(unique = true)
20 | private String email;
21 | private String password;
22 |
23 | public String getId() {
24 | return id;
25 | }
26 |
27 | public void setId(String id) {
28 | this.id = id;
29 | }
30 |
31 | public String getUsername() {
32 | return username;
33 | }
34 |
35 | public void setUsername(String username) {
36 | this.username = username;
37 | }
38 |
39 | public String getEmail() {
40 | return email;
41 | }
42 |
43 | public void setEmail(String email) {
44 | this.email = email;
45 | }
46 |
47 | public String getPassword() {
48 | return password;
49 | }
50 |
51 | public void setPassword(String password) {
52 | this.password = password;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/user-application/src/main/java/com/bahadirakin/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.service;
2 |
3 | import com.bahadirakin.model.User;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by bhdrkn on 08/02/15.
9 | */
10 | public interface UserService {
11 |
12 | User createUser(final User user);
13 |
14 | User updateUser(String id, final User user);
15 |
16 | User deleteUser(String id, final User user);
17 |
18 | User findUserById(final String id);
19 |
20 | List getAllUsers();
21 |
22 | User authenticate(final String username, final String password);
23 |
24 | void sendForgottenUsernameAndPasswordEmail(final String email);
25 | }
26 |
--------------------------------------------------------------------------------
/user-application/src/main/java/com/bahadirakin/service/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.service;
2 |
3 | import com.bahadirakin.dao.UserRepository;
4 | import com.bahadirakin.model.User;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Service;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * Created by bhdrkn on 08/02/15.
12 | */
13 | @Service
14 | public class UserServiceImpl implements UserService {
15 |
16 | private final UserRepository userRepository;
17 |
18 | @Autowired
19 | public UserServiceImpl(UserRepository userRepository) {
20 | this.userRepository = userRepository;
21 | }
22 |
23 | @Override
24 | public User createUser(User user) {
25 | return userRepository.save(user);
26 | }
27 |
28 | @Override
29 | public User updateUser(String id, User user) {
30 | final User dbUser = userRepository.findOne(id);
31 | dbUser.setUsername(user.getUsername());
32 | dbUser.setPassword(user.getPassword());
33 | dbUser.setEmail(user.getEmail());
34 | return userRepository.save(dbUser);
35 | }
36 |
37 | @Override
38 | public User deleteUser(String id, User user) {
39 | final User dbuser = this.authenticate(user.getUsername(), user.getPassword());
40 | if(dbuser== null || dbuser.getId().equals(id) == false){
41 | throw new RuntimeException("Wrong User");
42 | }
43 | userRepository.delete(user.getId());
44 | return user;
45 | }
46 |
47 | @Override
48 | public User findUserById(String id) {
49 | return userRepository.findOne(id);
50 | }
51 |
52 | @Override
53 | public List getAllUsers() {
54 | return userRepository.findAll();
55 | }
56 |
57 | @Override
58 | public User authenticate(String username, String password) {
59 | return userRepository.findByUsernameAndPassword(username, password);
60 | }
61 |
62 | @Override
63 | public void sendForgottenUsernameAndPasswordEmail(String email) {
64 | final User user = userRepository.findByEmail(email);
65 | // Sends email etc.
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/user-application/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/user-application/src/main/resources/mongodb.properties:
--------------------------------------------------------------------------------
1 | mongodb.hostaddress=ds031601.mongolab.com
2 | mongodb.port=31601
3 | mongodb.database=heroku_app33810136
4 | mongodb.username=
5 | mongodb.password=
6 |
7 |
--------------------------------------------------------------------------------
/user-application/src/main/resources/springDataContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/user-application/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | user-application
7 |
8 |
9 | contextConfigLocation
10 | classpath*:applicationContext.xml
11 |
12 |
13 |
14 | org.springframework.web.context.ContextLoaderListener
15 |
16 |
17 |
18 | mvc-servlet
19 | org.springframework.web.servlet.DispatcherServlet
20 |
21 | contextConfigLocation
22 | classpath*:applicationContext.xml
23 |
24 | 1
25 |
26 |
27 |
28 | mvc-servlet
29 | /
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/user-application/src/main/webapp/index.jsp:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World!
4 |
5 |
6 |
--------------------------------------------------------------------------------
/user-application/src/test/java/com/bahadirakin/dao/UserRepositoryTest.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.dao;
2 |
3 | import com.bahadirakin.dao.UserRepository;
4 | import com.bahadirakin.model.User;
5 | import org.junit.Assert;
6 | import org.junit.Before;
7 | import org.junit.BeforeClass;
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.test.context.ContextConfiguration;
12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 |
14 |
15 | /**
16 | * Created by bhdrkn on 08/02/15.
17 | */
18 | @RunWith(SpringJUnit4ClassRunner.class)
19 | @ContextConfiguration(value = {"classpath*:springDataContext-test.xml"})
20 | public class UserRepositoryTest {
21 |
22 | @Autowired
23 | UserRepository userRepository;
24 |
25 | static User user;
26 |
27 | @Before
28 | public void init() {
29 | if(user != null){
30 | return;
31 | }
32 | user = new User();
33 | user.setUsername("bhdrkn");
34 | user.setEmail("bhdrkn@gmail.com");
35 | user.setPassword("1q2w3e");
36 | user = userRepository.save(user);
37 | }
38 |
39 |
40 | @Test
41 | public void testFindByUsernameAndPassword() {
42 | final User user = userRepository.findByUsernameAndPassword("bhdrkn", "1q2w3e");
43 | Assert.assertNotNull(user);
44 | }
45 |
46 | @Test
47 | public void testNotFindByUsernameAndPassword() {
48 | final User user = userRepository.findByUsernameAndPassword("bhdrkn", "1");
49 | Assert.assertNull(user);
50 | }
51 |
52 | @Test
53 | public void testFindByEmail(){
54 | final User user = userRepository.findByEmail("bhdrkn@gmail.com");
55 | Assert.assertNotNull(user);
56 | }
57 |
58 | @Test
59 | public void testNotFindByEmail(){
60 | final User user = userRepository.findByEmail("asd");
61 | Assert.assertNull(user);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/user-application/src/test/java/com/bahadirakin/service/UserServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.bahadirakin.service;
2 |
3 | import com.bahadirakin.dao.UserRepository;
4 | import com.bahadirakin.model.User;
5 | import org.junit.Assert;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.junit.runners.JUnit4;
10 | import org.mockito.InjectMocks;
11 | import org.mockito.Mock;
12 | import org.mockito.Mockito;
13 | import org.mockito.MockitoAnnotations;
14 |
15 | /**
16 | * Created by bhdrkn on 08/02/15.
17 | */
18 | @RunWith(JUnit4.class)
19 | public class UserServiceTest {
20 |
21 | @Mock
22 | private UserRepository userRepository;
23 |
24 | private UserService userService;
25 |
26 | @Before
27 | public void init(){
28 | MockitoAnnotations.initMocks(this);
29 | userService = new UserServiceImpl(userRepository);
30 | }
31 |
32 | @Test
33 | public void testAuthentication(){
34 | final String username = "bhdrkn";
35 | final String password = "1q2w3e";
36 |
37 | final User mockUser = new User();
38 | mockUser.setId("1");
39 | mockUser.setUsername(username);
40 | mockUser.setPassword(password);
41 | mockUser.setEmail("bhdrkn@gmail.com");
42 |
43 | Mockito.when(userRepository.findByUsernameAndPassword(username,password)).thenReturn(mockUser);
44 |
45 | final User user = userService.authenticate(username, password);
46 | Assert.assertNotNull(user);
47 | }
48 |
49 | @Test
50 | public void testUnsuccessfulAuthentication(){
51 | final String username = "bhdrkn";
52 | final String password = "1q2w3e";
53 |
54 | Mockito.when(userRepository.findByUsernameAndPassword(username,password)).thenReturn(null);
55 |
56 | final User user = userService.authenticate(username, password);
57 | Assert.assertNull(user);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/user-application/src/test/resources/springDataContext-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------