Archive for January, 2013

java splipt with “|”


String cronExpression="0 0 12 * * ? | 0 15 10 ? * * | 0 0/5 14,18 * * ?";

String[] tokens=cronExpression.split("\\|");
for (int i = 0; i < tokens.length; i++){
System.out.println(tokens[i].trim());
}

Advertisements

Leave a comment

JPQL

Delete statement


@Transactional
public void delete(String date) {
logger.info("calling delete metod...");
StringBuffer queryBuffer = new StringBuffer(" delete from ListChangeNotification p where p.incomingSequenceTimestamp<= to_date ( ?1, 'dd/MM/yyyy hh24:mi:ss' ) ");
Query query = em.createQuery(queryBuffer.toString());
query.setParameter(1, date);
int deletedRows = query.executeUpdate();
logger.info(deletedRows + " deleteted from ListChangeNotification table ");

}
</

Select Statement-Dynamic
public List getScheduledJob(String startTime, String currentTime, String endTime,
boolean isEndTimeGreaterThanCurrentTime) {
// TODO Auto-generated method stub
TypedQuery query = null;
StringBuffer queryBuffer = new StringBuffer(” select p from ScheduledJob p “);
if (startTime != null && endTime != null) {

if (isEndTimeGreaterThanCurrentTime) {
queryBuffer.append(” where p.startTime>= to_date ( ?1, ‘dd/MM/yyyy hh24:mi’ )”);
queryBuffer.append(” and p.startTime<= to_date ( ?2, 'dd/MM/yyyy hh24:mi' )");
//create query
query = (TypedQuery) em.createQuery(queryBuffer.toString());
//set parameter
query.setParameter(1, startTime);
query.setParameter(2, currentTime);

} else {
queryBuffer.append(” where p.startTime>= to_date ( ?1, ‘dd/MM/yyyy hh24:mi’ )”);
queryBuffer.append(” and p.startTime<= to_date ( ?2, 'dd/MM/yyyy hh24:mi' )");
//create query
query = (TypedQuery) em.createQuery(queryBuffer.toString());
//set parameter
query.setParameter(1, startTime);
query.setParameter(2, endTime);

}

}

List list = query.getResultList();
return list;
}

, , , , ,

Leave a comment

Dowload Excel Report

Business code.Assuse your worbook list is ready.

//download excell file
try {
dowloadExcelReport(wb,fileName);
} catch (IOException e) {

e.printStackTrace();
}

……..

Generic code

@Override
public void dowloadExcelReport(Workbook workbook,String filename) throws IOException {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.setResponseContentType("application/vnd.ms-excel");
externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
// Write Excel report to response body.
workbook.write(externalContext.getResponseOutputStream());
// Inform JSF that response is completed and it thus doesn't have to navigate.
facesContext.responseComplete();
}

Leave a comment