package com;
import java.sql.Timestamp;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import com.google.gson.Gson;
public class os
{
public static void main(String s[])
{
System.out.println("logic");
SessionFactory s1=new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
Session session=s1.openSession();
//processor p=new processor();
Criteria criteria=session.createCriteria(osvo.class);
ProjectionList p=Projections.projectionList();
//p.add(Projections.property("osname"));
p.add(Projections.groupProperty("osname"));
p.add(Projections.rowCount());
criteria.setProjection(p);
List l1 = criteria.list();
Gson gson = new Gson();
String record = gson.toJson(l1);
System.out.println("record in json = " + record);
System.out.println("ok" + l1.size());
for(int i=0; i<l1.size(); i++)
{
Object[] o=(Object[]) l1.get(i);
String os=o[0].toString();
if(os.contains("windows xp"))
System.out.println("windows xp" + o[1]);
else if(os.contains("windows vista"))
System.out.println("windows vista" + o[1]);
else if(os.contains("windows server 2003"))
System.out.println("windows server 2003" + o[1]);
else if(os.contains("windows server 2008"))
System.out.println("windows server 2008" + o[1]);
else if(os.contains("windows 7"))
System.out.println("windows 7" + o[1]);
else
System.out.println("other" + o[1]);
}
// Iterator i =l1.iterator();
// while(i.hasNext())
// {
// // System.out.println("ok");
// Object p11=(Object) i.next();
// osvo p2=(osvo)p11;
// //System.out.println("ok");
// System.out.println(p2.);
// System.out.println(String.valueOf(p2.getCpuusage()));
// }
// //.out.println("save");
session.close();
s1.close();
}
}
//
//System.out.println("logic");
//SessionFactory s1=new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
//Session session=s1.openSession();
//processor p=new processor();
//login l=new login();
///* l.setusername("vipul");
//l.setpassword("tejal");
//l.setemail("vipulpatel@gmail.com");
//l.setphonenumber("9601969261");
//Transaction t=session.beginTransaction();
//session.save(l);
//t.commit();
//*/
//Criteria c1=session.createCriteria(processor.class);
//// c1.add(Restrictions.and(Restrictions.eq("id", new Integer(0)),Restrictions.like("username","vipul")));
//// c1.addOrder(Order.desc("id"));
//// c1.setProjection(Projections.property("username"));
//// c1.setProjection(Projections.property("address"));
//ProjectionList p1=Projections.projectionList();
//p1.add(Projections.property(""));
//p1.add(Projections.property("address"));
//
//
//c1.setProjection(p1);
//
//List l1 = (List) c1.list();
//Iterator i =l1.iterator();
//while(i.hasNext())
//{
// Object o[]=(Object [])i.next();
// System.out.println(o[0] + "==" + o[1]);
//
//
//// String str=(String) i.next();
//// System.out.println(str);
///*
// Object o=i.next();
// login l11=(login)o;
// System.out.println(l11.getid());
// System.out.println(l11.getaddress());
// System.out.println(l11.getemail());
// System.out.println(l11.getpassword());
// System.out.println(l11.getphonenumber());
// System.out.println(l11.getusername());
//*/
//}
//System.out.println("save");
//
//session.close();
//s1.close();