Friday, May 20, 2016

Java transfer content from one file to another

http://www.programcreek.com/2011/03/java-transfer-content-from-one-file-to-another/


package com.aaa.fileDataTransfer;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class FileDataModTransfer {
public static void main(String[] args) throws IOException {
String source = "F://fileDataInput.txt";
String dest = "F://fileDataOutput.txt";

File fin = new File(source);
FileInputStream fis = new FileInputStream(fin);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));

FileWriter fstream = new FileWriter(dest, true);
BufferedWriter out = new BufferedWriter(fstream);

String aLine = null;
while ((aLine = in.readLine()) != null) {
// Process each line and add output to Dest.txt file
String[] parts = aLine.split(" ");
System.out.println("First Part: " + parts[0]);
System.out.println("Second Part: " + parts[1]);
String generatedLine = "(" + parts[0] + ", '" + parts[1] + "'),";
System.out.println(generatedLine.toString());
out.write(generatedLine);
out.newLine();
}
// do not forget to close the buffer reader
in.close();
// close buffer writer
out.close();
}
}

INPUT: F://fileDataInput.txt
88 baikaName_88
89 baikaName_89
90 baikaName_90

OUTPUT:F://fileDataOutput.txt
(88, 'baikaName_88'),
(89, 'baikaName_89'),
(90, 'baikaName_90'),

Postgresql Backup of single table

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserve

C:\Users\USER>cd C:\Program Files (x86)\PostgreSQL\9.2\bin
C:\Program Files (x86)\PostgreSQL\9.2\bin> pg_dump  --host localhost --port 5432 --username postgres --format plain --ignore-version --verbose --file "F:\tm_baikanol.backup" --table public.tm_baikanol mog001

Best Null Pointer Checking

        List<Mst00202> zaikolist =
            this.mst002Logic.findZaikoByScode(request.scode);
if (zaikolist != null && !zaikolist.isEmpty() && zaikolist.size() > 0) {

Thursday, May 19, 2016

Marx Book Library

My Questions and Answers

2 way SSL


  1. http://www.robinhowlett.com/blog/2016/01/05/everything-you-ever-wanted-to-know-about-ssl-but-were-afraid-to-ask/
  2. http://stackoverflow.com/questions/33808603/implementing-2-way-ssl-using-spring-boot
  3. http://stackoverflow.com/questions/6441523/spring-security-how-to-force-https-with-flag
  4. https://developer.salesforce.com/page/Making_Authenticated_Web_Service_Callouts_Using_Two-Way_SSL
  5. https://github.com/viniciusccarvalho/boot-two-way-ssl-example
  6. https://dzone.com/articles/2-way-ssl-java-keystore
  7. https://edlee.me/2012/09/04/two-way-ssl-restful-service-using-apache-cxf/
  8. https://jeromebulanadi.wordpress.com/2010/02/25/basic-spring-web-service-tutorial-from-contract-to-security/#server_security
  9. http://crunchify.com/step-by-step-guide-to-enable-https-or-ssl-correct-way-on-apache-tomcat-server-port-8443/

Introduction to Security in the Java EE Platform

Criteria API URL

Wednesday, May 18, 2016

JPA Criteria API by samples – Part-II

JPA Criteria API by samples – Part-II

you can read first part from JPA Criteria API by samples – Part-I
some more examples with JPA criteria API

Simple Join query

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
long category=200L;
Query query = entityManager.createQuery("select s from OrderItem s " +
        "where s.product.category=:cat");
query.setParameter("cat", category);
List<OrderItem> list = query.getResultList();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Object> criteriaQuery = criteriaBuilder.createQuery();
Root<OrderItem> from = criteriaQuery.from(OrderItem.class);
Path<Object> path = from.join("product").get("category");
CriteriaQuery<Object> select = criteriaQuery.select(from);
select.where(criteriaBuilder.equal(path, category));
TypedQuery<Object> typedQuery = entityManager.createQuery(select);
List<Object> resultList = typedQuery.getResultList();
assertEqualsList(list, resultList);

simple fetch join query

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
long category=200L;
Query query = entityManager.createQuery("select s from OrderItem s " +
        "join fetch s.product where s.product.category=:cat");
query.setParameter("cat", category);
List<OrderItem> list = query.getResultList();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Object> criteriaQuery = criteriaBuilder.createQuery();
Root<OrderItem> from = criteriaQuery.from(OrderItem.class);
Path<Object> path = from.join("product").get("category");
from.fetch("product"); //FETCH product
CriteriaQuery<Object> select = criteriaQuery.select(from);
select.where(criteriaBuilder.equal(path, category));
TypedQuery<Object> typedQuery = entityManager.createQuery(select);
List<Object> resultList = typedQuery.getResultList();
assertEqualsList(list, resultList);

subselect (subquery) join query

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Query query = entityManager.createQuery(
        "select s from OrderItem s join fetch s.product" +
        " where s.product.category in" +
        " (select sb.pbyte from SimpleBean sb where sb.pint>=30000)");
List<OrderItem> list = query.getResultList();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Object> criteriaQuery = criteriaBuilder.createQuery();
Root<OrderItem> from = criteriaQuery.from(OrderItem.class);
Path<Object> path = from.join("product").get("category");
from.fetch("product");
CriteriaQuery<Object> select = criteriaQuery.select(from);
Subquery<SimpleBean> subquery = criteriaQuery.subquery(SimpleBean.class);
Root fromSimpleBean = subquery.from(SimpleBean.class);
subquery.select(fromSimpleBean.get("pbyte"));
subquery.where(criteriaBuilder.ge(fromSimpleBean.get("pint"),30000));
select.where(criteriaBuilder.in(path).value(subquery));
TypedQuery<Object> typedQuery = entityManager.createQuery(select);
List<Object> resultList = typedQuery.getResultList();
assertEqualsList(list, resultList);