sudo apt-get install python-software-properties
sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
sudo apt-get install postgresql-9.2

hopefully will move from mysql to postgresql

I will try to publish some performance comparision !!!

cheers


Hi everybody, this was my surprise project , achivy.com my first startup, my first ruby on rails project :)

you can check the about page but it is simply a gamification platform for lots of social sites and more, it now supports foursquare, gowalla, stackoverflow etc….

Achivy adds some fun and gamification to your social life. Add Twitter,Tumblr, Foursquare Gowalla , Flickr, Stackoverflow, Klout and many other applications to your profile to see how many achievements, badges,scores you have and follow your progress. You can keep up with your friends, and see the other people’s achievements and activities — achivies.

more to come soon…


[caption id=”” align=”alignright” width=”240" caption=”Image by alancleaver_2000 via Flickr”]

checklist
checklist

[/caption]

it has been a long time since I posted :( so it would be really good to put some targets and build a list of them. otherwise I will be lying on my coach all the time.

  • yagdao : finalize and release 1.0
  • startupweekend amsterdam notes ! anybody for utrecht ?
  • ???, surprise

hope to implement all those and do something interesting here

see you soon


Append Method handler
Another dynamic query builder. But this one , use simple StringBuilder instead of trying to parse the argument. So more fast and adjustable dynamic query builder

For more see test cases and example dao

@YMethod(type = YMethodType.APPEND,select = "pbyte,count(id)",groupBy = "pbyte")
List<SimpleBean> append2(@YParameter("pint>=?") int i);
@YMethod(type = YMethodType.APPEND,select = "pbyte,count(id)",groupBy = "pbyte",having = "count(id)>10")
List<SimpleBean> append3(@YParameter("pint>=?") int i);
group and having support with aggregation supportAppend and JPA criteria methods now support Projections

Execute Method handler

bulk method support@YMethod(type = YMethodType.EXECUTE,query = "update SimpleBean set pint=:newInt where id=:id ")
int execute1(@YParameter(value = "newInt") int newInt,@YParameter(value = "id") long id);

experimental criteria query parser for JPA

Criteria method is now support more sophisticated queries . please see test cases and example dao@YMethod(type = YMethodType.CRITERIA)
SearchResultList<SimpleBean> criteria2(@YParameter("pint >=") Integer arg1,@YParameter("pint <=") Integer arg2);
@YMethod(type = YMethodType.CRITERIA)
SearchResultList<SimpleBean> criteria3(@YParameter("pstring is null") boolean apply);
@YMethod(type = YMethodType.CRITERIA)
SearchResultList<Object> criteria2CheckApplied(@YParameter("pint>=20000") boolean apply1,@YParameter( "pint<=50000") boolean apply2);

yagdao (Yet Another Generic DAO) finally.

this version is a little bit experimental but stable.

yagdao is an generic dao framework that would be enabled by annotations.

simple step to go through for setup read more

  • extend GenericDAO

moreover you can implement custom method read more


for hibernate

public String getIdProperty(Class entityClass) {
String idProperty=sessionAccessor.getSessionFactory()
.getClassMetadata(entityClass)
.getIdentifierPropertyName();
return idProperty;
}

for JPA 2.0 metamodel API this method or to get value of id field see comment below

public String getIdProperty(Class entityClass) {
String idProperty;
Metamodel metamodel = getEntityManager().getMetamodel();
EntityType entity = metamodel.entity(entityClass);
Set<SingularAttribute> singularAttributes = entity.getSingularAttributes();
for (SingularAttribute singularAttribute : singularAttributes) {
if (singularAttribute.isId()){
idProperty=singularAttribute.getName();
break;
}
}
if(idProperty==null)
throw new RuntimeException("id field not found");
return idProperty;
}

to


JPA Criteria API by samples — Part-I

some more examples with JPA criteria API
Simple Join query

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

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”); …

Although examples are pretty much simple it will help you with finalized version of JPA 2.0 API.

For Part II please read JPA Criteria API by samples — Part-II

and in this examples in my opinion building query by programming is not so easy and maintainable but still possible.

PS: I tested it with hibernate 3.5.1

Simple Query

Query query = entityManager.createQuery("from SimpleBean s");
List<SimpleBean> list = query.getResultList();
CriteriaBuilder criteriaBuilder =entityManager.getCriteriaBuilder();
CriteriaQuery<Object> criteriaQuery = criteriaBuilder.createQuery();
Root<SimpleBean> from = criteriaQuery.from(SimpleBean.class);
CriteriaQuery<Object> select = criteriaQuery.select(from);
TypedQuery<Object> typedQuery = entityManager.createQuery(select);
List<Object> resultList = typedQuery.getResultList();
assertEqualsList(list, resultList);

Simple Query with Order

List<SimpleBean> expected= entityManager.createQuery("from …


Although this is an important, it is a hidden bug unless you trace you generated SQL for hibernate.

simply the two lines of code below should generate same SQL

Criteria rootCriteria = session.createCriteria(OrderItem.class);
Criteria criteria = rootCriteria.createCriteria("order").createCriteria("customer");
List<OrderItem> list1 = criteria.add(Restrictions.eq("city", "city-1")).list();
List<OrderItem> list2 = session.createQuery("select s from OrderItem s where s.order.customer.city=?").setString(0,"city-1").list();
assertEquals(list1, list2);
but when you trace the generated SQL you can see the huge difference. it simply changes fetchmode defaults and ignore any manual fetchmode settingSQL from criteria APIselect this_.id as id1_2_, this_.name as name1_2_, this_.order_id as order5_1_2_, this_.product_id as product6_1_2_, this_.quantity as quantity1_2_, this_.totalPrice as totalPrice1_2_, order1_.id as id0_0_, order1_.customer_id as customer7_0_0_, order1_.deliveryDate as delivery2_0_0_, order1_.name as name0_0_, order1_.orderDate as orderDate0_0_, order1_.priority as priority0_0_, order1_.totalValue as totalValue0_0_, customer2_.id as id3_1_, customer2_.city as city3_1_, customer2_.name as name3_1_ from erp_orderitem this_ inner join erp_order order1_ on this_.order_id=order1_.id …

Here you can see how to traverse the runtime information to get this information. You Can simply traverse the inheritance tree ofr the class and get the metadata of the generic definition. Somthing like

public static Type[] getGenericDefinitons(Class classFrom, Class class1) ;
Type[] types=getGenericDefinitons(MockClass1.class,GenericInterface.class);//[String.class,Long.class,Integer.class] expected
First The Sample Cases :public interface GenericInterface <T,K,L>{}public interface MockClass1 extends GenericInterface<String,Long,Integer>{}
public interface MockClass11<T,K,L> extends GenericInterface<T,K,L>{}
public interface MockClass12 extends MockClass11<String,Long,Integer>{}
public interface MockClass2 extends MockClass1{}
public class MockClass3 implements GenericInterface<String,Long,Integer>{}
public class MockClass4 extends MockClass3{}
public class GenericClass <T,K,L>{}
public class AMockClass2 extends AMockClass1{}
public class AMockClass1 extends…

About

altuure

#expat #amsterdam #cycling

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store