package org.sfm.querydsl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.sfm.beans.DbObject;
import org.sfm.jdbc.DbHelper;
import org.sfm.jdbc.querydsl.QueryDslMappingProjection;
import org.springframework.dao.DataAccessException;

import com.mysema.query.Tuple;
import com.mysema.query.sql.HSQLDBTemplates;
import com.mysema.query.sql.SQLQuery;
import com.mysema.query.sql.SQLQueryImpl;
import com.mysema.query.types.MappingProjection;

public class TesQueryDSL {
	QTestDbObject qTestDbObject = new QTestDbObject("o");
	
	public List<DbObject> getProductListByCategory()
	        throws DataAccessException, SQLException {
		
		
		Connection conn = DbHelper.objectDb();
		
		SQLQuery sqlquery = new SQLQueryImpl(conn, new HSQLDBTemplates());
		try {
			return sqlquery.from(qTestDbObject).where(qTestDbObject.id.eq(1l)).list(new QueryDslMappingProjection<DbObject>(DbObject.class, qTestDbObject.id,
					qTestDbObject.name, qTestDbObject.email, qTestDbObject.creationTime, qTestDbObject.typeName, qTestDbObject.typeOrdinal ));
		} finally {
			conn.close();
		}
	}

	public static void main(String[] args) throws DataAccessException, SQLException {
		System.out.println(new TesQueryDSL().getProductListByCategory());
	}
}

@@ -20,16 +20,51 @@
 rydsl;%0A%0A
+import static org.junit.Assert.*;%0A%0A
 import j
@@ -109,24 +109,57 @@
 LException;%0A
+import java.text.ParseException;%0A
 import java.
@@ -170,16 +170,39 @@
 .List;%0A%0A
+import org.junit.Test;%0A
 import o
@@ -367,39 +367,8 @@
 n;%0A%0A
-import com.mysema.query.Tuple;%0A
 impo
@@ -491,57 +491,8 @@
 mpl;
-%0Aimport com.mysema.query.types.MappingProjection;
 %0A%0Apu
@@ -578,54 +578,48 @@
 %0A%09%0A%09
-public List%3CDbObject%3E getProductListByCategory
+@Test%0A%09public void testMappingProjection
 ()%0A%09
@@ -662,24 +662,40 @@
 SQLException
+, ParseException
  %7B%0A%09%09%0A%09%09%0A%09%09C
@@ -819,14 +819,30 @@
 %0A%09%09%09
-return
+ List%3CDbObject%3E list =
  sql
@@ -1111,197 +1111,131 @@
 ;%0A%09%09
-%7D finally %7B%0A%09%09%09conn.clos
+%09 %0A%09%09%09 assertEquals(1, list.siz
 e()
+)
 ;%0A%09%09
-%7D%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) throws DataAccessException, SQLException %7B%0A%09%09System.out.println(new TesQueryDSL().getProductListByCategory
+%09 DbHelper.assertDbObjectMapping(list.get(0));%0A%09%09%7D finally %7B%0A%09%09%09conn.close
 ()
-)
 ;%0A%09
-%7D
+%09%7D%0A%09%7D%0A
 %0A%7D%0A

change class to test