Skip to content

Instantly share code, notes, and snippets.

View sivaprasadreddy's full-sized avatar
:octocat:
Learning and practicing...

K. Siva Prasad Reddy sivaprasadreddy

:octocat:
Learning and practicing...
View GitHub Profile
@sivaprasadreddy
sivaprasadreddy / PersistenceConfig.java
Created March 2, 2014 05:24
PersistenceConfig.java
package com.sivalabs.springapp.config;
import java.util.Properties;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
package com.sivalabs.springapp.config;
import java.util.Properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@sivaprasadreddy
sivaprasadreddy / application.properties
Created March 2, 2014 05:22
application.properties with DB, Hibernate and Email configuration
################### DataSource Configuration ##########################
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test
jdbc.username=root
jdbc.password=admin
init-db=false
@sivaprasadreddy
sivaprasadreddy / pom.xml
Last active August 29, 2015 13:56
SpringApp pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sivalabs</groupId>
<artifactId>spring-javaconfig</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>SpringApp JavaConfig Demo</name>
<properties>
@sivaprasadreddy
sivaprasadreddy / CleanMoneyTransferService
Last active January 1, 2016 15:59
CleanMoneyTransferService
class FundTransferTxn
{
private Account sourceAccount;
private Account targetAccount;
private BigDecimal amount;
private boolean allowDuplicateTxn;
//setters & getters
}
public class CleanMoneyTransferService
@sivaprasadreddy
sivaprasadreddy / UglyMoneyTransferService
Last active January 1, 2016 15:59
UglyMoneyTransferService
public class UglyMoneyTransferService
{
public void transferFunds(Account source, Account target, BigDecimal amount, boolean allowDuplicateTxn) throws IllegalArgumentException, RuntimeException {
Connection conn = null;
try {
conn = DBUtils.getConnection();
PreparedStatement pstmt = conn.prepareStatement("Select * from accounts where acno = ?");
pstmt.setString(1, source.getAcno());
ResultSet rs = pstmt.executeQuery();
Account sourceAccount = null;
@sivaprasadreddy
sivaprasadreddy / AES.java
Created November 26, 2012 11:48 — forked from ymnk/AES.java
JSch examples
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/**
* This program will demonstrate how to use "aes128-cbc".
*
*/
import com.jcraft.jsch.*;
import java.awt.*;
import javax.swing.*;
public class AES{
@sivaprasadreddy
sivaprasadreddy / RESTEasyDemo-Custom-ExceptionHandlers-output.xml
Created June 12, 2012 10:03
RESTEasyDemo Custom ExceptionHandlers output
case 1 : GET http://localhost:8080/resteasy-demo/rest/users/0
Response :
<response>
<status>failed</status>
<message>User Id[0] should not be less than 1.</message>
<internalError>null</internalError>
</response>
case 2: GET http://localhost:8080/resteasy-demo/rest/users/100
Response :
@sivaprasadreddy
sivaprasadreddy / RESTEasyDemo-Throwing-Custom-Exceptions.java
Created June 12, 2012 10:00
RESTEasy Demo Throwing Custom Exceptions
@Path("/{id}")
@GET
public Response getUserXMLById(@PathParam("id") Integer id)
{
if(id==null || id < 1 ){
throw new ApplicationException("User Id["+id+"] should not be less than 1.");
}
User user = userService.getById(id);
if(user==null ){
@sivaprasadreddy
sivaprasadreddy / RESTEasyDemo-Custom-ExceptionHandlers.java
Created June 12, 2012 09:59
RESTEasy Demo Custom ExceptionHandlers
/**
* ResourceNotFoundExceptionHandler.java
*/
package com.sivalabs.resteasydemo;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.springframework.stereotype.Component;