Posts

Showing posts from September, 2018

Framework Vs Design Patterns

Design Patterns: A set of guidelines which talk about how we can architect the application. Frameworks: Follow a particular pattern (or set of many patterns) when building an application. Provides foundation classes and libraries. Advantage of Frameworks 1. Help to get started quickly 2. Leverages industry best practices

RPM Linux command

1. How to Check an RPM Signature Package Always check the PGP signature of packages before installing them on your Linux systems and make sure its integrity and origin is OK . Use the following command with –checksig ( check signature ) option to check the signature of a package called pidgin . [root@tecmint]# rpm --checksig pidgin-2.7.9-5.el6.2.i686.rpm pidgin-2.7.9-5.el6.2.i686.rpm: rsa sha1 (md5) pgp md5 OK 2. How to Install an RPM Package For installing an rpm software package, use the following command with -i option. For example, to install an rpm package called pidgin-2.7.9-5.el6.2.i686.rpm . [root@tecmint]# rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm Preparing... ########################################### [100%] 1:pidgin ########################################### [100%] RPM command and options -i : install a package -v : verbose for a nicer display -h : print hash marks as the package archive is unpacked. 3. How to check depen...

One to Many Table Mapping

1. Uni-Directional Category.java public class Category { private long id; private String name; private Set<Product> products; public Category() { } public Category(String name) { this.name = name; }        //setters...getters... } Product.java public class Product { private long id; private String name; private String description; public Product() { } public Product(String name, String description) { this.name = name; this.description = description; }        // setters...getter... } 1.1 XML Mapping category.hbm.xml <hibernate-mapping package="com.practice.one2many.mapping.unidirectional.xml.approach" auto-import="false"> <class name="Category" table="CATEGORY3"> <id name="id" column="CAT_ID"> <generator class="sequence"/> </id> <property name="name" /> <set name="products" casca...

One to One Table Mapping

HibernateRepository.java public class HibernateUtil { private static SessionFactory sessionFactory; private HibernateUtil(){} static { StandardServiceRegistry standardRegistry =        new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build(); Metadata metaData =         new MetadataSources(standardRegistry).getMetadataBuilder().build(); sessionFactory = metaData.getSessionFactoryBuilder().build(); } public static Session getSession() { return sessionFactory.openSession(); } } hibernate.cfg.xml DB setting <hibernate-configuration> <session-factory> <property name=" hibernate.dialect "> org.hibernate.dialect.Oracle8iDialect </property> <property name=" hibernate.connection.driver_class "> oracle.jdbc.driver.OracleDriver </property> <property name=" hibernate.connection.username ">user</property> <property name=" hibern...

Static Block, Instance, Block, Constructor Chainning

If I have static block, instance block and constructor chaining from super class to sub class then below will be the order of execution: super class static block --> sub class static block --> super class instance block --> super class constructor --> sub class instance block --> sub class constructor class A { public A() { System.out.println("A1 constructor code"); } { System.out.println("A2 instance block"); } static { System.out.println("A3 static block"); } } class B extends A { public B() { System.out.println("B1 A1 constructor code"); } { System.out.println("B2 instance block"); } static { System.out.println("B3 static block"); } } class C extends B { int id; public C() { System.out.println("C1 A1 constructor code"); } { System.out.println("C2 instance block"); } stat...

Collection Data Types

XML Based Mapping public class Student { private int id; private String name; private int[] mobileNumbers; private String[] projects; private Collection<String> skills; private List<Integer> marks; private Set<String> jobs; private Map<String, String> educations; //sertters......getters } HibernateUtil.java public class HibernateUtil { private static SessionFactory sessionFactory; private HibernateUtil(){} static { StandardServiceRegistry standardRegistry =        new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build(); Metadata metaData =         new MetadataSources(standardRegistry).getMetadataBuilder().build(); sessionFactory = metaData.getSessionFactoryBuilder().build(); } public static Session getSession() { return sessionFactory.openSession(); } } student.hbm.xml <hibernate-mapping package="com.practic...

Read XML file from Java

1. Get XML file ready like below person.xml <?xml version = "1.0" encoding = "utf-8"?> <persons> <person id="15"> <firstName>Piyush</firstName> <lastName>Trivedi</lastName> <age>15</age> <email>piyush@gmail.com</email> </person> <person id="16"> <firstName>Vibha</firstName> <lastName>Singh</lastName> <age>10</age> <email>vibha@gmail.com</email> </person> </persons> 2. Create a Person class public class Person { private int id; private String firstName; private String lastName; private int age; private String email;         //setters.......getters...... } 3. Create Handler class by extending DefaultHandler public class PersonHandler extends DefaultHandler { private List<Person> persons = new ArrayList<>(); private Person person; private...

Rest Call in Spring Boot

1. Create Employee class. The important thing to note is we should have 2 constructors, default and with parameters.  @Entity @Table(name = "employee007") public class Employee { @Id String employeeId; String name; String address; String emailId;        //default constructor        //constructor with parameters        //setters & getters } 2. Create EmployeeRepository interface public interface EmployeeRepository extends JpaRepository<Employee, String>{} 3. Create EmployeeService interface public interface EmployeeService { public List<Employee> getAllEmployees(); public Optional<Employee> getEmployee(String empId); public Employee getEmployeeFromStoredProcedure(String empId); public Employee getEmployee(Employee employee); public void addEmployee(Employee employee); public void updateEmployee(Employee employee, String empId); public void deleteEmployee(String...

How to call Stored Procedure from Spring Boot

1. This is stored procedure for getting a single employee by passing employee id create or replace PROCEDURE get_employee (    employeeId IN VARCHAR2,    employee OUT SYS_REFCURSOR ) AS BEGIN     OPEN employee FOR     SELECT *     FROM employee007     WHERE employee_id = employeeId; END; 2. Create Employee class. The important thing to note is we should have 2 constructors, default and with parameters.  @Entity @Table(name = "employee007") @NamedStoredProcedureQuery(name = "getEmployeeFromStoredProcedure", procedureName = "get_employee", resultClasses = com.practice.employee.Employee.class) public class Employee { @Id String employeeId; String name; String address; String emailId;        //default constructor        //constructor with parameters        //setters & getters } 3. Create CustomEmployeeRepository interface pub...

SQL: stored procedure

Image
Procedures and Functions are the subprograms which can be created and saved in the database as database objects. They can be called or referred inside the other blocks also. Apart from this, we will cover the major differences between these two subprograms. Also, we are going to discuss the Oracle built-in functions. Terminologies in PL/SQL Subprograms Below are the terminologies that we are going to discuss. Parameter: The parameter is variable or placeholder of any valid PL/SQL datatype through which the PL/SQL subprogram exchange the values with the main code. This parameter allows to give input to the subprograms and to extract from these subprograms. These parameters should be defined along with the subprograms at the time of creation. These parameters are included n the calling statement of these subprograms to interact the values with the subprograms. The datatype of the parameter in the subprogram and the calling statement should be same. The size of the datat...