Java

Java is a set of computer software and specifications developed by Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cross-platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones to enterprise servers and supercomputers.

Spring Logo

Spring Framework

The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform. A key element of Spring is infrastructural support at the application level: Spring focuses on the "plumbing" of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.

Hibernate Logo

Hibernate Framework

Hibernate ORM is an object-relational mapping framework for the Java language. It provides a framework for mapping an object-oriented domain model to a relational database.

Showing posts with label Java8. Show all posts
Showing posts with label Java8. Show all posts

Sunday, September 27, 2015

Lambda Expressions in Java 8

Lambda Expressions:
  • Lambda expression is an anonymous function without any declarations. 
  • Lambda Expression are useful to write shorthand code and hence saves the effort of writing lengthy code. 
  • It promotes developer productivity, better readable and reliable code.
  • Lambda expressions can be converted to functional interfaces.
  • Lambda expressions can access effectively final variables from the enclosing scope..
Syntax of Lambda expression:
(arguments) -> {body}

Example of Lambda expression:
public class LambdaExpressions
{
  public static void main(String[] args)
  {        
    // Old way
    Runnable runnable = new Runnable() {
        public void run() {
            System.out.println("With out using Lambda Expressions .... ");
        }
    };
    
    Thread thread = new Thread(runnable);    
    thread.start();
    
    // Using Lambda Expressions
    Runnable runnable2 = () -> { System.out.println("With using Lambda Expressions .... ");};
    
    Thread thread2 = new Thread(runnable2);    
    thread2.start();    
  }
}
Output:
With out using Lambda Expressions .... 
With using Lambda Expressions .... 
Lambda expression arguments can contain zero or more arguments.
List<String> names = new ArrayList<String>();
names.add("Ranga");
names.add("Reddy");
names.add("Vasu");
names.add("Raja");
names.add("Viond");
names.add("Manoj");

new Thread(() -> { System.out.println("Empty arguments.");}) {      // empty arguments          
}.run();;
        
names.forEach(name -> System.out.println(name));            // one argument with out specifying data type 
names.forEach((name) -> System.out.println(name));          // one argument with out specifying data type
names.forEach((String name) -> System.out.println(name));   // one argument with specifying data type
Note: We can omit the datatype of the parameters in a lambda expression. And also we can omit the parentheses if there is only one parameter.

Lambda expression body can contain any number of statements or with out statement also.
If body contains more than one statement then curly braces is mandatory otherwise it is optional.
List<String> names = new ArrayList<String>();
names.add("Ranga");
names.add("Reddy");
names.add("Vasu");
names.add("Raja");
names.add("Viond");
names.add("Manoj");
        
names.forEach(((name) -> System.out.println(name))); // with out braces
        
names.forEach((name) -> {                            // with braces 
    System.out.println(name);
    System.out.println("Hello Mr. "+name);          
});

Sunday, August 23, 2015

Method References in Java8


Method References:
  • Method references refers to methods or constructors without invoking them.
  • We can use lambda expressions to create anonymous methods. 
  • Sometimes, however, a lambda expression does nothing but call an existing method. 
  • In those cases, it's often clearer to refer to the existing method by name.
  • Using Method references refer to the existing method by name, they are compact, easy-to-read lambda expressions for methods that already have a name.
  • In java, method references can be specified by using double colon (::) operator.
  • Method reference can be expressed using the lambda expression syntax (->) in order to make it simple :: operator can be used.
Syntax:
           <class_name or instance_name>::<method_name>
Example:
/**
 * @author Ranga Reddy
 * @version 1.0
 */
public class MethodReferenceExample {
    public static void main(String[] args) {
        
        // with out using method reference
        new Thread(
                () -> {System.out.println("Hello, Mr. Ranga"); }
        ) {
            
        }.run();;
        
        // with using method reference
        new Thread(MethodReferenceExample:: sayHello) {
            
        }.run();
        
    }
    
    public static void sayHello() {
        System.out.println("Hello, Mr. Ranga");
    }
}
Types of Method References:
There are four types of method references:

Method Reference Type
Syntax
Example
Reference to a static method
ClassName::staticMethodName
String::valueOf
Reference to a bound non-static method
ObjectName::instanceMethodName
s::toString
Reference to an instance method of an arbitrary object of a particular type
ClassName::instanceMethodName
Object::toString
Reference to a constructor
ClassName::new
String::new
Reference to a static method:
We can call static method references by using ContainingClass::staticMethodName
Example:
public class MethodReferenceExample {
    public static void main(String[] args) {        
        // Reference to a Static Method     
        new Thread(MethodReferenceExample::sayHello).start();
    }       
    public static void sayHello() {     
        System.out.println("Hello, Mr. Ranga");
    }
}
Reference to a bound non-static method:
We can call non-static method using ObjectName:: instanceMethodName
Example:

public class MethodReferenceExample {
    public static void main(String[] args) {
        // Reference to an Instance Method of a Particular Object
        String name = "My name is Ranga Reddy";
        printName(name::toString);      
    }
    
    private static void printName(Supplier<String> supplier) {
        System.out.println(supplier.get());
    }
}
Reference to an instance method of an arbitrary object of a particular type:
We can call non-static method using ClassName:: instanceMethodName

Example:
public class MethodReferenceExample {
    public static void main(String[] args) {
        // Reference to an Instance Method of an Arbitrary Object of a Particular Type
        String[] names = { "Ranga", "Reddy", "Vinod", "Raja", "Manu", "Teja", "Vasu" };     
        Arrays.sort(names, String::compareToIgnoreCase);
        System.out.println(Arrays.toString(names));     
    }
}
Reference to a bound non-static method:
We can call non-static method using ClassName:: new
Example:
@FunctionalInterface
interface EmployeeFactory {
    Employee getEmployee(long id, String name, Integer age);
}

class Employee {
    private long id;
    private String name;
    private int age;
        
    public Employee() {     
        this(1, "Ranga", 27);
    }
    
    public Employee(long id, String name, int age) {
        super();
        this.id = id;
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Employee [id=" + id + ", name=" + name + ", age=" + age + "]";
    }   
}

public class MethodReferenceExample {
    public static void main(String[] args) {                
        // Reference to constructor
        EmployeeFactory employeeFactory = Employee :: new;
        Employee employee = employeeFactory.getEmployee(1, "Ranga Reddy",27);
        System.out.println(employee);       
    }
}
When to use method references:
When a lambda expression is invoking already defined method, then we can replace it with reference to that method.
When we can't use method references:
We can't pass arguments to the method references. So that places we can't use method references.
References:
  1. https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html
  2. http://java8.in/java-8-method-references/
  3. http://www.informit.com/articles/article.aspx?p=2191424

Wednesday, August 19, 2015

Spring Data Cassandra - CRUD Operations

Hi, in this post we are going to see how to connect with Cassandra NoSQL database using Spring data.

Project Structure:
Tools and Technologies:
  • Java 8
  • Spring 3.2.8
  • Cassandra 2.1.8
  • Spring-Data-Cassandra 1.0.0
  • Maven 3.0.4
Cassandra Keyspace and Table Creation:
cqlsh> create keyspace "ranga" with replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};

cqlsh> CREATE TABLE employee(id int, name text, salary float, PRIMARY KEY(id));
Maven Configuration file:
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>org.springframework.samples</groupId>
<artifactId>CassandraCRUDOperations</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>

<!-- Java Version -->
<java.version>1.8</java.version>

<!-- Spring -->
<spring-framework.version>3.2.8.RELEASE</spring-framework.version>
<!-- 4.2.0.RELEASE -->

<!-- Cassandra -->
<cassandra.version>1.0.0.RELEASE</cassandra.version>

<!-- Logging -->
<logback.version>1.0.13</logback.version>
<slf4j.version>1.7.5</slf4j.version>

<!-- Test -->
<junit.version>4.11</junit.version>

</properties>

<dependencies>

<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-framework.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-framework.version}</version>
</dependency>

<!-- Spring Data Cassandra -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>${cassandra.version}</version>
</dependency>

<!-- Spring Test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-framework.version}</version>
<scope>test</scope>
</dependency>

<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

Cassandra database properties file:
src/main/resources/cassandra.properties
cassandra.contactpoints=localhost,127.0.0.1
cassandra.port=9042
cassandra.keyspace=ranga
Cassandra Template configuration file:
com/ranga/util/CassandraUtil.java
package com.ranga.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.config.CassandraSessionFactoryBean;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.convert.CassandraConverter;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;

/**
* Utility class for getting the CassandraOperations object.
* @author Ranga Reddy
* @version 1.0
*/


@Configuration
@PropertySource(value = { "classpath:cassandra.properties" })
public class CassandraUtil {

/**
* Constant String for Keyspace
*/

private static final String KEYSPACE = "cassandra.keyspace";
/**
* Constant String for ContactPoints
*/

private static final String CONTACTPOINTS = "cassandra.contactpoints";
/**
* Constant String for Port
*/

private static final String PORT = "cassandra.port";

@Autowired
private Environment environment;

public CassandraUtil() {
System.out.println("CassandraUtil()");
}

private String getKeyspaceName() {
return environment.getProperty(KEYSPACE);
}

private String getContactPoints() {
return environment
.getProperty(CONTACTPOINTS);
}

private int getPortNumber() {
return Integer.parseInt(environment
.getProperty(PORT));
}

@Bean
public CassandraClusterFactoryBean cluster() {
CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints(getContactPoints());
cluster.setPort(getPortNumber());
return cluster;
}

@Bean
public CassandraMappingContext mappingContext() {
return new BasicCassandraMappingContext();
}

@Bean
public CassandraConverter converter() {
return new MappingCassandraConverter(mappingContext());
}

@Bean
public CassandraSessionFactoryBean session() throws Exception {
CassandraSessionFactoryBean cassandraSessionFactoryBean = new CassandraSessionFactoryBean();
cassandraSessionFactoryBean.setCluster(cluster().getObject());
cassandraSessionFactoryBean.setKeyspaceName(getKeyspaceName());
cassandraSessionFactoryBean.setConverter(converter());
cassandraSessionFactoryBean.setSchemaAction(SchemaAction.NONE);
return cassandraSessionFactoryBean;
}

@Bean
public CassandraOperations cassandraTemplate() throws Exception {
return new CassandraTemplate(session().getObject());
}
}

com/ranga/util/MyCassandraTemplate.java
package com.ranga.util;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.cassandra.core.CassandraOperations;

/**
* Utility class for handling all CRUD Operations.
* @author Ranga Reddy
* @version 1.0
*/

public class MyCassandraTemplate {

@Autowired
private CassandraOperations cassandraTemplate;

/**
* Creating the entity.
* @param entity
* @return {@link Object}
*/

public <T> T create(T entity) {
return cassandraTemplate.insert(entity);
}

/**
* Creating the entity.
* @param entity
* @param claz
* @return T
*/

public <T> T create(T entity, Class<T> claz) {
return (T) cassandraTemplate.insert(entity);
}

/**
* Creating the list of entities.
* @param entity
*/

public <T> void createList(List<T> entities) {
cassandraTemplate.insert(entities);
}

/**
* Updating the entity.
* @param entity
* @param claz
* @return T
*/

public <T> T update(T entity) {
return (T) cassandraTemplate.update(entity);
}

/**
* Updating the list of entities.
* @param entity
* @param claz
* @return T
*/

public <T> void updateList(List<T> entities) {
cassandraTemplate.update(entities);
}

/**
* Updating the entity.
* @param entity
* @param claz
* @return T
*/

public <T> T update(T entity, Class<T> claz) {
return (T) cassandraTemplate.update(entity);
}

/**
* Get the Entity using Id.
* @param id
* @param claz
* @return T
*/

public <T> T findById(Object id, Class<T> claz) {
return cassandraTemplate.selectOneById(claz, id);
}

/**
* Delete the Entity using Id.
* @param id
* @param claz
*/

public <T> void deleteById(Object id, Class<T> claz) {
cassandraTemplate.deleteById(claz, id);
}

/**
* Delete the Entity using object.
* @param entity
*/

public void delete(Object entity) {
cassandraTemplate.delete(entity);
}

/**
* Deleting the list of entities
* @param entities
*/

public <T> void delete(List<T> entities) {
cassandraTemplate.delete(entities);
}

/**
* Deleting the all entities.
* @param claz
*/

public <T> void deleteAll(Class<T> claz) {
cassandraTemplate.deleteAll(claz);
}

/**
* Getting the all entities.
* @param claz
* @return List of entities
*/

public <T> List<T> findAll(Class<T> claz) {
return (List<T>) cassandraTemplate.selectAll(claz);
}

/**
* Getting the all entity values using specific id's data.
* @param ids
* @param claz
* @return
*/

public <T> List<T> findAll(List<Object> ids, Class<T> claz) {
return cassandraTemplate.selectBySimpleIds(claz, ids);
}

/**
* Getting the count of records.
* @param claz
* @return the count value.
*/

public <T> void truncate(Class<T> claz) {
cassandraTemplate.truncate(claz.getName());
}

/**
* Getting the count of records.
* @param claz
* @return the count value.
*/

public <T> long getCount(Class<T> claz) {
return cassandraTemplate.count(claz);
}


/**
* Checking the object exists or not.
* @param id
* @param claz
* @return true if the object exists in the database otherwise it will return false.
*/

public <T> boolean exists(Object id, Class<T> claz) {
return cassandraTemplate.exists(claz, id);
}

}
Entity Class:
com/ranga/entity/Employee.java
package com.ranga.entity;

import org.springframework.data.cassandra.mapping.Column;
import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;

/**
* Employee Entity class.
* @author Ranga Reddy
* @version 1.0
*/


@Table(value="employee")
public class Employee {

@PrimaryKey(value="id")
private int id;

@Column(value="name")
private String name;

@Column(value="salary")
private float salary;

/**
* Default Constructor
*/

public Employee() {
super();
}

/**
* Parameterized Constructor
* @param id
* @param name
* @param salary
*/

public Employee(int id, String name, float salary) {
super();
this.id = id;
this.name = name;
this.salary = salary;
}


/**
* @return the id
*/

public int getId() {
return id;
}

/**
* @param id the id to set
*/

public void setId(int id) {
this.id = id;
}

/**
* @return the name
*/

public String getName() {
return name;
}

/**
* @param name the name to set
*/

public void setName(String name) {
this.name = name;
}

/**
* @return the salary
*/

public float getSalary() {
return salary;
}

/**
* @param salary the salary to set
*/

public void setSalary(float salary) {
this.salary = salary;
}

@Override
public String toString() {
return "Employee [id=" + id + ", name=" + name + ", salary=" + salary
+ "]";
}

}
Service and Impl classes:
com/ranga/service/EmployeeService.java
package com.ranga.service;

import java.util.List;

import com.ranga.entity.Employee;

/**
* Service interface for Employee to perform CRUD operation.
* @author Ranga Reddy
* @version 1.0
*/

public interface EmployeeService {
/**
* Used to Create the Employee Information
* @param employee
* @return {@link Employee}
*/

public Employee createEmployee(Employee employee);

/**
* Getting the Employee Information using Id
* @param id
* @return {@link Employee}
*/

public Employee getEmployee(int id);

/**
* Used to Update the Employee Information
* @param employee
* @return {@link Employee}
*/


public Employee updateEmployee(Employee employee);

/**
* Deleting the Employee Information using Id
* @param id
*/

public void deleteEmployee(int id);

/**
* Getting the All Employees information
* @return
*/

public List<Employee> getAllEmployees();
}

com/ranga/service/EmployeeServiceImpl.java
package com.ranga.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.ranga.dao.EmployeeDAO;
import com.ranga.entity.Employee;

/**
* Service Impl class for Employee to perform CRUD operation.
* @author Ranga Reddy
* @version 1.0
*/

public class EmployeeServiceImpl implements EmployeeService {

@Autowired
private EmployeeDAO employeeDAO;

/**
*
*/

public EmployeeServiceImpl() {
super();
}

@Override
@Transactional
public Employee createEmployee(Employee employee) {
return employeeDAO.createEmployee(employee);
}

@Override
@Transactional
public Employee getEmployee(int id) {
return employeeDAO.getEmployee(id);
}

@Override
@Transactional
public Employee updateEmployee(Employee employee) {
return employeeDAO.updateEmployee(employee);
}

@Override
@Transactional
public void deleteEmployee(int id) {
employeeDAO.deleteEmployee(id);
}

@Override
@Transactional
public List<Employee> getAllEmployees() {
return employeeDAO.getAllEmployees();
}
}
DAO and Impl classes:
com/ranga/dao/EmployeeDAO.java
package com.ranga.dao;

import java.util.List;

import com.ranga.entity.Employee;

/**
* DAO interface for Employee to perform CRUD operation.
* @author Ranga Reddy
* @version 1.0
*/

public interface EmployeeDAO {
/**
* Used to Create the Employee Information
* @param employee
* @return {@link Employee}
*/

public Employee createEmployee(Employee employee);

/**
* Getting the Employee Information using Id
* @param id
* @return {@link Employee}
*/

public Employee getEmployee(int id);

/**
* Used to Update the Employee Information
* @param employee
* @return {@link Employee}
*/


public Employee updateEmployee(Employee employee);

/**
* Deleting the Employee Information using Id
* @param id
*/

public void deleteEmployee(int id);

/**
* Getting the All Employees information
* @return
*/

public List<Employee> getAllEmployees();
}

com/ranga/dao/EmployeeDAOImpl.java
package com.ranga.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import com.ranga.entity.Employee;
import com.ranga.util.MyCassandraTemplate;

/**
* DAOImpl class for Employee to perform CRUD operation.
* @author Ranga Reddy
* @version 1.0
*/

public class EmployeeDAOImpl implements EmployeeDAO {

@Autowired
private MyCassandraTemplate myCassandraTemplate;

@Override
public Employee createEmployee(Employee employee) {
return myCassandraTemplate.create(employee, Employee.class);
}

@Override
public Employee getEmployee(int id) {
return myCassandraTemplate.findById(id, Employee.class);
}

@Override
public Employee updateEmployee(Employee employee) {
return myCassandraTemplate.update(employee, Employee.class);
}

@Override
public void deleteEmployee(int id) {
myCassandraTemplate.deleteById(id, Employee.class);
}

@Override
public List<Employee> getAllEmployees() {
return myCassandraTemplate.findAll(Employee.class);
}
}
Spring Main Configuration file:
com/ranga/configuration/MainAppConfiguration.java
package com.ranga.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import com.ranga.dao.EmployeeDAO;
import com.ranga.dao.EmployeeDAOImpl;
import com.ranga.service.EmployeeService;
import com.ranga.service.EmployeeServiceImpl;
import com.ranga.util.CassandraUtil;
import com.ranga.util.MyCassandraTemplate;

/**
* This is the main configuration file to create the Beans.
* @author Ranga Reddy
* @version 1.0
*/


@Configuration
@Import(CassandraUtil.class)
public class MainAppConfiguration {

/**
* Creating the EmployeeService bean.
* @return {@link EmployeeService}
*/

@Bean
public EmployeeService getEmployeeService() {
return new EmployeeServiceImpl();
}

/**
* Creating the EmployeeDAO bean.
* @return {@link EmployeeDAO}
*/

@Bean
public EmployeeDAO getEmployeeDAO() {
return new EmployeeDAOImpl();
}

/**
* Creating the MyCassandraTemplate bean.
* @return {@link MyCassandraTemplate}
*/

@Bean
public MyCassandraTemplate getMyCassandraTemplate() {
return new MyCassandraTemplate();
}
}
Client Application
com/ranga/client/Application.java
package com.ranga.client;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.ranga.configuration.MainAppConfiguration;
import com.ranga.entity.Employee;
import com.ranga.service.EmployeeService;

/**
* Client Application to perform CRUD operations.
* @author Ranga Reddy
* @version 1.0
*/


public class Application {

@SuppressWarnings("resource")
public static void main(String[] args) {

// Getting the ApplicationContext
ApplicationContext applicationContext =
new AnnotationConfigApplicationContext(MainAppConfiguration.class);

//Getting the EmployeeService object.
EmployeeService employeeService = applicationContext.getBean(EmployeeService.class);

Employee employee = new Employee(1, "Ranga", 20000);

// Create the Employee information
employee = employeeService.createEmployee(employee);
System.out.println("After Creattion Employee Info: "+employee);

System.out.println("Displaying all Employee Info ");
// Getting All Employees information and printing
List<Employee> employees = employeeService.getAllEmployees();
employees.forEach(emp -> { System.out.println(emp);});

System.out.println("Updating the Employee Info: ");
// Updating the Employee information
employee.setName("Ranga Reddy");
employee.setSalary(40000);
employeeService.updateEmployee(employee);

// Getting the Employee information based on Id
employee = employeeService.getEmployee(employee.getId());
System.out.println("After Updation Employee Info: "+employee);

System.out.println("Deleting Employee Info ");
// Deleting the Employee Information
employeeService.deleteEmployee(employee.getId());
employee = employeeService.getEmployee(employee.getId());
System.out.println("After Deletion Employee Info: "+employee);
}
}

Output:
20:48:44.253 [main] DEBUG o.s.cassandra.core.CqlTemplate - executing [INSERT INTO employee(id,name,salary) VALUES (1,'Ranga',20000.0);]
After Creattion Employee Info: Employee [id=1, name=Ranga, salary=20000.0]
Displaying all Employee Info
Employee [id=1, name=Ranga, salary=20000.0]
Updating the Employee Info:
20:48:44.376 [main] DEBUG o.s.cassandra.core.CqlTemplate - executing [INSERT INTO employee(id,name,salary) VALUES (1,'Ranga Reddy',40000.0);]
20:48:44.382 [main] DEBUG o.s.cassandra.core.CqlTemplate - executing [SELECT * FROM employee WHERE id=1;]
After Updation Employee Info: Employee [id=1, name=Ranga Reddy, salary=40000.0]
Deleting Employee Info
20:48:44.391 [main] DEBUG o.s.cassandra.core.CqlTemplate - executing [DELETE FROM employee WHERE id=1;]
20:48:44.395 [main] DEBUG o.s.cassandra.core.CqlTemplate - executing [SELECT * FROM employee WHERE id=1;]
After Deletion Employee Info: null