Skip to content

Instantly share code, notes, and snippets.

View aziz781's full-sized avatar

Abdul Aziz (A575072) aziz781

View GitHub Profile
@aziz781
aziz781 / gist:1336488
Created November 3, 2011 13:34
Java sample persistence.xml with JNDI JTA Data source and Hibernate configuration
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="MyAppUnit" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/myAppDS</jta-data-source>
<!-- Package: uk.co.example.domain -->
@aziz781
aziz781 / gist:1336493
Created November 3, 2011 13:37
Spring framework sample applicationContext.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:amq="http://activemq.apache.org/schema/core"
@aziz781
aziz781 / gist:1336502
Created November 3, 2011 13:40
Spring quartz sample configuration applicationContext-quartz.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:amq="http://activemq.apache.org/schema/core"
@aziz781
aziz781 / gist:1336506
Created November 3, 2011 13:43
Spring JMS sample configuration applicationContext-jms.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:amq="http://activemq.apache.org/schema/core"
@aziz781
aziz781 / gist:1336511
Created November 3, 2011 13:44
Spring Batch sample configuration applicationContext-batch.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:amq="http://activemq.apache.org/schema/core"
@aziz781
aziz781 / gist:1336519
Created November 3, 2011 13:47
Java: is Future Date
public static boolean isFutureDate(Date givenDate)
{
// current date
Calendar currentCal = Calendar.getInstance();
currentCal.setTime(getCurrentDate());
// given date
Calendar givenCal = Calendar.getInstance();
givenCal.setTime(givenDate);
if(currentCal.equals(givenCal) || currentCal.after(givenCal))
return false;
@aziz781
aziz781 / gist:1336521
Created November 3, 2011 13:47
Java: is Current date
public static boolean isCurrentDate(Date givenDate)
{
// current date
Calendar currentCal = Calendar.getInstance();
currentCal.setTime(getCurrentDate());
// given date
Calendar givenCal = Calendar.getInstance();
givenCal.setTime(givenDate);
if(currentCal.equals(givenCal))
return true;
@aziz781
aziz781 / gist:1336525
Created November 3, 2011 13:48
java get current date
public static Date getCurrentDate()
{
Calendar calendar = Calendar.getInstance();
Date currentDate = calendar.getTime();
String dateStr= new SimpleDateFormat("dd/MM/yyyy").format(currentDate);
return getDate(dateStr);
}
@aziz781
aziz781 / gist:1336542
Created November 3, 2011 13:56
Spring JDBC: simple way to excute a query
// first get 'dataSource'
// @Autowired
// private DataSource dataSource;
private Object[] geStatus() {
try {
JdbcTemplate template = new JdbcTemplate(dataSource);
Object[] result = (Object[]) template.queryForObject(SQL, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Object[]{rs.getString(1), sdf.format(rs.getDate(2))};
}
@aziz781
aziz781 / gist:1336551
Created November 3, 2011 14:02
Java Spring Controller
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class StatusController {
@RequestMapping(value = "/", method = RequestMethod.GET)