Skip to content

Instantly share code, notes, and snippets.

View jeevan-patil's full-sized avatar
🎯
Focusing

Jeevan Patil jeevan-patil

🎯
Focusing
View GitHub Profile
@jeevan-patil
jeevan-patil / ProjectServiceImpl.java
Last active July 29, 2017 10:08
Project Service Implementation which publishes the event.
@Service
public class ProjectServiceImpl implements ProjectService {
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
@Override
public void createProject(Project project) {
// save project entity in the database and publish an event to send mail to project owner
publishProjectCreatedEvent(project);
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
@Component
public class EntityCreatedEventListener implements ApplicationListener<EntityCreatedEvent> {
@Autowired
private EmailService emailService;
@jeevan-patil
jeevan-patil / EntityCreatedEvent.java
Created July 29, 2017 09:42
Generic EntityCreatedEvent class.
import org.springframework.context.ApplicationEvent;
public class EntityCreatedEvent<T> extends ApplicationEvent {
private T entity;
public EntityCreatedEvent(Object source, T entity) {
super(source);
this.entity = entity;
}
@jeevan-patil
jeevan-patil / Project.java
Last active July 29, 2017 09:40
Project Entity
package xyz.jeevan.api.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* Projects mongo document.
*/
@Document(collection = "projects")
public class Project {
@jeevan-patil
jeevan-patil / hikaricp-config.xml
Created July 29, 2017 08:44
HikariCP connection pool configuration
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="mercatus_connection_pool" />
<property name="dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"/>
<property name="maximumPoolSize" value="50" />
<property name="maxLifetime" value="60000" />
<property name="idleTimeout" value="30000" />
<property name="dataSourceProperties">
<props>
<prop key="url">${jdbc.url}</prop>
<prop key="user">${jdbc.username}</prop>
@jeevan-patil
jeevan-patil / hikaricp-dependency.xml
Created July 29, 2017 08:43
HikariCP Connection Pool Dependency for Java7
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java7</artifactId>
<version>2.4.12</version>
</dependency>
@jeevan-patil
jeevan-patil / c3p0-depencency.xml
Created July 29, 2017 08:41
c3p0 connection pool dependency
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
@jeevan-patil
jeevan-patil / c3p0-config.xml
Created July 29, 2017 08:41
c3p0 connection pool configuration
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="minPoolSize" value="10"/>
<property name="maxPoolSize" value="50"/>
<property name="acquireIncrement" value="1"/>
<property name="idleConnectionTestPeriod" value="1000"/>
<property name="maxStatements" value="250"/>
@jeevan-patil
jeevan-patil / dbcp2-pool-config.xml
Created July 29, 2017 08:39
DBCP2 Connection Pool Configurations
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="initialSize" value="10" />
<property name="maxTotal" value="50" />
</bean>
@jeevan-patil
jeevan-patil / dbcp2-dependency.xml
Created July 29, 2017 08:38
DBCP2 Connection Pool Dependency
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>