Ingredients:
2 cups plain flour
1.5 or 2 cups milk
2 eggs
2 tablespoon sugar
3 teaspoon baking soda
60g melted and cooled butter or ghee
some more butter or ghee for cooking
Serves: about 8 pancakes
Procedure:
Mix the four and sugar together in a vessel
In a bowl, mix the milk, eggs, baking soda and melted butter or ghee
Make a well in the flour. Gradually add the milk mixture to the well in flour and keep mixing to form a smooth batter
Keep aside the batter for about 10 mins
In a pan, add some butter or ghee and spread it nicely
Keep the flame in low heat
Pour the batter to the pan in small circles.
When bubbles start to appear on top, toss the pancake and cook the other side
Pancakes ready!
Serve hot. Can also be served with golden syrup or coconul milk + sugar
Thursday, October 9, 2008
Tuesday, September 2, 2008
What Kevin says...
6 yrs
kevin: can you put the lumpic channel on tv
translated as: can you put the Olympic channel on tv
kevin: don't change the channel, its just the abatisan
translated as: don't change the channel, its just the advertisement
kevin: they are singing the national anshum on tv
translated as: they are singing the national anthem on tv
kevin: i accidentally delicate the picture
translated as: i accidentally delete the picture
kevin: can you put the lumpic channel on tv
translated as: can you put the Olympic channel on tv
kevin: don't change the channel, its just the abatisan
translated as: don't change the channel, its just the advertisement
kevin: they are singing the national anshum on tv
translated as: they are singing the national anthem on tv
kevin: i accidentally delicate the picture
translated as: i accidentally delete the picture
Wednesday, August 13, 2008
Querying a date column in database
To query a date column, use
select * from person_table where date_of_birth >= to_date('01/01/2000', 'dd/MM/yyyy')
select * from person_table where date_of_birth >= to_date('01/01/2000', 'dd/MM/yyyy')
Thursday, July 24, 2008
Querying date with java and sql
Two ways to query a date:
1. by formatting and querying as a string
2. by to_date sql function
public List getPersonList(Timestamp startDate, Timestamp endDate)
{
String startDateStr = new SimpleDateFormat("yyyy-MM-dd hh24:mm:ss").format(startDate);
String endDateStr = new SimpleDateFormat("yyyy-MM-dd hh24:mm:ss").format(startDate);
List toReturn = new ArrayList();
StringBuffer personQuery = new StringBuffer();
personQuery.append("select user from User as user ");
if(startDate != null && endDate != null)
{
registrationGrowthQuery.append(" where activationSentTime >= '" + startDateStr + "' and activationSentTime <= '" + endDateStr + "'");
registrationGrowthQuery.append(" where activationSentTime >= to_date("+startDate+", 'yyyy-MM-dd hh24:mm:ss') and activationSentTime <= to_date("+endDate+", 'yyyy-MM-dd hh24:mm:ss')");
}
1. by formatting and querying as a string
2. by to_date sql function
public List getPersonList(Timestamp startDate, Timestamp endDate)
{
String startDateStr = new SimpleDateFormat("yyyy-MM-dd hh24:mm:ss").format(startDate);
String endDateStr = new SimpleDateFormat("yyyy-MM-dd hh24:mm:ss").format(startDate);
List toReturn = new ArrayList();
StringBuffer personQuery = new StringBuffer();
personQuery.append("select user from User as user ");
if(startDate != null && endDate != null)
{
registrationGrowthQuery.append(" where activationSentTime >= '" + startDateStr + "' and activationSentTime <= '" + endDateStr + "'");
registrationGrowthQuery.append(" where activationSentTime >= to_date("+startDate+", 'yyyy-MM-dd hh24:mm:ss') and activationSentTime <= to_date("+endDate+", 'yyyy-MM-dd hh24:mm:ss')");
}
Thursday, June 19, 2008
Google Map Example
Create a div with id = googleMap
<tr>
<td colspan=2 >
<table border=1>
<tr>
<td>
<div id="googleMap" style="width: 550px; height: 450px"></div>
</td>
</tr>
</table>
<td colspan=1 class="sidebar">
</td>
</tr>
Send the AJAX call to the server to retrieve map data
var request = GXmlHttp.create();
request.open("GET", "http://myserver:8080/MapServlet?method=getGoogleMap", true);
// the getGoogleMap method should be implemented on the server side to retrieve the lat and lng from database and populate the result as an XML and return back to front end
request.onreadystatechange = function()
{
if (request.readyState == 4)
{
if (request.status == 200)
{
var response = request.responseText;
if (response == '<%= MapServlet.ERROR_NO_DATA %>')
{
alert('<bean:message key="errors.map.notInDatabase"/>');
}
else
{
var xmlDoc = GXml.parse(response);
// obtain the array of markers and loop through it
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++)
{
var lat = parseFloat(GXml.value(markers[i].getElementsByTagName("lat")[0]));
var lng = parseFloat(GXml.value(markers[i].getElementsByTagName("lng")[0]));
var point = new GLatLng(lat, lng);
var html = GXml.value(markers[i].getElementsByTagName("stnName")[0]);
createMarker(point, html);
}
}
}
function createMarker(point, html)
{
var map = new GMap2(document.getElementById("map"));
map.setCenter(point, 3);
var marker = createInfoMarker(gLatLng, html);
map.addOverlay(marker);
GEvent.addListener(marker, "click", function()
{
marker.openInfoWindowHtml(html);
});
}
Sample XSD for creating the above map xml
<xs:element name="MapObject">
<xs:complexType>
<xs:sequence>
<xs:element name="marker" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="lat" type="xs:string" />
<xs:element name="lng" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<tr>
<td colspan=2 >
<table border=1>
<tr>
<td>
<div id="googleMap" style="width: 550px; height: 450px"></div>
</td>
</tr>
</table>
<td colspan=1 class="sidebar">
</td>
</tr>
Send the AJAX call to the server to retrieve map data
var request = GXmlHttp.create();
request.open("GET", "http://myserver:8080/MapServlet?method=getGoogleMap", true);
// the getGoogleMap method should be implemented on the server side to retrieve the lat and lng from database and populate the result as an XML and return back to front end
request.onreadystatechange = function()
{
if (request.readyState == 4)
{
if (request.status == 200)
{
var response = request.responseText;
if (response == '<%= MapServlet.ERROR_NO_DATA %>')
{
alert('<bean:message key="errors.map.notInDatabase"/>');
}
else
{
var xmlDoc = GXml.parse(response);
// obtain the array of markers and loop through it
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++)
{
var lat = parseFloat(GXml.value(markers[i].getElementsByTagName("lat")[0]));
var lng = parseFloat(GXml.value(markers[i].getElementsByTagName("lng")[0]));
var point = new GLatLng(lat, lng);
var html = GXml.value(markers[i].getElementsByTagName("stnName")[0]);
createMarker(point, html);
}
}
}
function createMarker(point, html)
{
var map = new GMap2(document.getElementById("map"));
map.setCenter(point, 3);
var marker = createInfoMarker(gLatLng, html);
map.addOverlay(marker);
GEvent.addListener(marker, "click", function()
{
marker.openInfoWindowHtml(html);
});
}
Sample XSD for creating the above map xml
<xs:element name="MapObject">
<xs:complexType>
<xs:sequence>
<xs:element name="marker" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="lat" type="xs:string" />
<xs:element name="lng" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Create own domian names for pc
To add our own domain name to our pc, we may do the following:
On a Windows XP machine you can find your HOSTS file in the “C:\Windows\System32\drivers\etc” directory.
Windows 2000, it’s ” c:\winnt\system32\drivers\etc\hosts”. And on Linux, it’s just “/etc/hosts”.
Open it up in a text editor, and add the following lines:
127.0.0.1 mydomain.com.localhost
and Reboot
Now you can access the url http://mydomain.com.localhost/
On a Windows XP machine you can find your HOSTS file in the “C:\Windows\System32\drivers\etc” directory.
Windows 2000, it’s ” c:\winnt\system32\drivers\etc\hosts”. And on Linux, it’s just “/etc/hosts”.
Open it up in a text editor, and add the following lines:
127.0.0.1 mydomain.com.localhost
and Reboot
Now you can access the url http://mydomain.com.localhost/
Hibernate basic examples
Example shows basic hibernate usage:
person.hbm.xml
<hibernate-mapping>
<class name="com.test.model.Person" table="person" >
<id name="personId" type="int">
<column name="person_id" />
<generator class="sequence">
<param name="sequence">NEXT_PERSON_ID</param>
<param name="parameters">INCREMENT BY 1 START WITH 1</param>
</generator>
</id>
<property name="personAge" type="java.lang.Integer">
<column name="person_age" />
</property>
<property name="personName" type="string">
<column name="person_name" length="3" not-null="true" />
</property>
<property name="personDateOfBirth" type="date">
<column name="person_dob" length="4" />
</property>
<property name="updateTime" type="timestamp">
<column name="update_time" length="3594" />
</property>
We ca also properties to fetch another table data lazily as:
<property name="personRoles" lazy="false" type="string" >
<formula>
(select pr.person_role from PersonRole pr where pr.person_id=person_id)
</formula>
</property>
One to Many mapping returning a List
<list name="personRoles" lazy="true" fetch="select" inverse="true">
<key>
<column name="person_id" />
<column name="person_role" />
</key>
<list-index column="role_seq" base="1"/>
<one-to-many class="com.test.model.PersonRole" />
</list>
One to Many mapping returning a Set
<set name="personRoles" order-by="role_seq" lazy="true" fetch="select" inverse="true">
<key>
<column name="person_id" />
<column name="person_role" />
</key>
Model class to represent this would be as follows:
public class Person implements java.io.Serializable
{
private int personId;
private Integer personAge;
private String personName;
private Date personDateOfBirth;
private Date updateTime;
// setters and getters
}
DAO to access the persistence layer
class PersonDAOHibernateImpl extends PersonDAO
{
public List<Person> getPersonList()
{
try
{
beginTransaction();
Session session = getSession();
List<Person> instList = session.createCriteria(Person.class)
.addOrder(Order.desc("personId"))
.list();
commitTransaction();
return instList;
}
catch(Exception e)
{
rollbackTransaction();
return Collections.emptyList();
}
}
Some other kind of queries we can use are:
To get a specific name list
List<Person> instList = session.createCriteria(Person.class)
.add(Restrictions.eq("personName", Integer.valueOf(personName)))
.addOrder(Order.desc("personId"))
.list();
can also use this clause in above query where we have a composite id
.add(Restrictions.eq("id.name", Integer.valueOf(personName)))
or
Query q = getSession().createQuery("select personName from Person");
List<Person> personList = q.list();
or if we need to make a join on another table say for example called PersonRoles
Criteria c = session.createCriteria(Person.class)
.add(Restrictions.eq("id.name", Integer.valueOf(personId)))
.setFetchMode("roles", FetchMode.JOIN)
.createAlias("roles", "personRoles", CriteriaSpecification.LEFT_JOIN)
.addOrder(Order.asc("id.personId"))
.addOrder(Order.asc("personRoles.id.roleName"))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
or we can create a plain sql statement and query
String updatePerson =
" update person " +
" SET person_name = 'ABC' " +
" WHERE person_id = ? ";
Session session = getSession();
beginTransaction();
Connection conn = session.connection();
PreparedStatement pstmt = conn.prepareStatement(updatePerson);
pstmt.setInt(1, personId);
pstmt.execute();
pstmt.close();
Couple of helpful Ant tasks
<target name="hibernatetool" description="Run Hibernate Tool" unless="hibernate.skip" depends="">
<mkdir dir="${src.resources.hibernate.generated}" />
<echo message="ANT HEAP SIZE = ${env.ANT_OPTS}" />
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="hibernatetools.path" />
<hibernatetool destdir="${src.resources.hibernate.generated}" templatepath="${src.resources.hibernate}">
<jdbcconfiguration
revengfile="${src.resources.hibernate}/hibernate.reveng.xml"
configurationfile="${src.resources.hibernate}/hibernate.cfg.xml"
packagename="${package.name}" />
<hbm2hbmxml/> <!-- This regenerates the hbm mapping files -->
<!-- <hbm2cfgxml/> This cretaes a hibernate.cfg.xml file -->
</hibernatetool>
</target>
<target name="hbm2java" description="Run Hibernate Tool" unless="hibernate.skip" depends="">
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="hibernatetools.path"
/>
<hibernatetool destdir="${src.resources.hibernate.generated}">
<configuration>
<fileset dir="${src.resources.hibernate.generated}">
<include name="**/Person*.hbm.xml" />
</fileset>
</configuration>
<hbm2java jdk5="false" ejb3="false" />
</hibernatetool>
</target>
hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<!-- Bind the getCurrentSession() method to the thread, session-per-conversation -->
<property name="current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
<property name="hibernate.connection.url">jdbc:informix-sqli:myhostname:myportnumber/mydatabasename:INFORMIXSERVER=myservername</property>
<property name="hibernate.connection.username">myusername</property>
<property name="hibernate.connection.password">mypassword</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.connection.driver_class">com.informix.jdbc.IfxDriver</property>
<property name="dialect">org.hibernate.dialect.InformixDialect</property>
<property name="show_sql">true</property>
<!-- Connection Pool -->
<property name="hibernate.connection.pool_size">3</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">5</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">100</property>
<!-- Use EHCache as secondary cache-->
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<mapping resource="com/mytest/persistence/orm/hibernate/model/Person.hbm.xml" />
</session-factory>
</hibernate-configuration>
hibernate.reveng.xml
<hibernate-reverse-engineering>
<type-mapping>
<sql-type jdbc-type="5" hibernate-type="integer"/>
</type-mapping>
<table-filter match-catalog="mydatabasename" match-schema="informix" match-name="person" exclude="false" />
</hibernate-reverse-engineering>
person.hbm.xml
<hibernate-mapping>
<class name="com.test.model.Person" table="person" >
<id name="personId" type="int">
<column name="person_id" />
<generator class="sequence">
<param name="sequence">NEXT_PERSON_ID</param>
<param name="parameters">INCREMENT BY 1 START WITH 1</param>
</generator>
</id>
<property name="personAge" type="java.lang.Integer">
<column name="person_age" />
</property>
<property name="personName" type="string">
<column name="person_name" length="3" not-null="true" />
</property>
<property name="personDateOfBirth" type="date">
<column name="person_dob" length="4" />
</property>
<property name="updateTime" type="timestamp">
<column name="update_time" length="3594" />
</property>
We ca also properties to fetch another table data lazily as:
<property name="personRoles" lazy="false" type="string" >
<formula>
(select pr.person_role from PersonRole pr where pr.person_id=person_id)
</formula>
</property>
One to Many mapping returning a List
<list name="personRoles" lazy="true" fetch="select" inverse="true">
<key>
<column name="person_id" />
<column name="person_role" />
</key>
<list-index column="role_seq" base="1"/>
<one-to-many class="com.test.model.PersonRole" />
</list>
One to Many mapping returning a Set
<set name="personRoles" order-by="role_seq" lazy="true" fetch="select" inverse="true">
<key>
<column name="person_id" />
<column name="person_role" />
</key>
Model class to represent this would be as follows:
public class Person implements java.io.Serializable
{
private int personId;
private Integer personAge;
private String personName;
private Date personDateOfBirth;
private Date updateTime;
// setters and getters
}
DAO to access the persistence layer
class PersonDAOHibernateImpl extends PersonDAO
{
public List<Person> getPersonList()
{
try
{
beginTransaction();
Session session = getSession();
List<Person> instList = session.createCriteria(Person.class)
.addOrder(Order.desc("personId"))
.list();
commitTransaction();
return instList;
}
catch(Exception e)
{
rollbackTransaction();
return Collections.emptyList();
}
}
Some other kind of queries we can use are:
To get a specific name list
List<Person> instList = session.createCriteria(Person.class)
.add(Restrictions.eq("personName", Integer.valueOf(personName)))
.addOrder(Order.desc("personId"))
.list();
can also use this clause in above query where we have a composite id
.add(Restrictions.eq("id.name", Integer.valueOf(personName)))
or
Query q = getSession().createQuery("select personName from Person");
List<Person> personList = q.list();
or if we need to make a join on another table say for example called PersonRoles
Criteria c = session.createCriteria(Person.class)
.add(Restrictions.eq("id.name", Integer.valueOf(personId)))
.setFetchMode("roles", FetchMode.JOIN)
.createAlias("roles", "personRoles", CriteriaSpecification.LEFT_JOIN)
.addOrder(Order.asc("id.personId"))
.addOrder(Order.asc("personRoles.id.roleName"))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
or we can create a plain sql statement and query
String updatePerson =
" update person " +
" SET person_name = 'ABC' " +
" WHERE person_id = ? ";
Session session = getSession();
beginTransaction();
Connection conn = session.connection();
PreparedStatement pstmt = conn.prepareStatement(updatePerson);
pstmt.setInt(1, personId);
pstmt.execute();
pstmt.close();
Couple of helpful Ant tasks
<target name="hibernatetool" description="Run Hibernate Tool" unless="hibernate.skip" depends="">
<mkdir dir="${src.resources.hibernate.generated}" />
<echo message="ANT HEAP SIZE = ${env.ANT_OPTS}" />
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="hibernatetools.path" />
<hibernatetool destdir="${src.resources.hibernate.generated}" templatepath="${src.resources.hibernate}">
<jdbcconfiguration
revengfile="${src.resources.hibernate}/hibernate.reveng.xml"
configurationfile="${src.resources.hibernate}/hibernate.cfg.xml"
packagename="${package.name}" />
<hbm2hbmxml/> <!-- This regenerates the hbm mapping files -->
<!-- <hbm2cfgxml/> This cretaes a hibernate.cfg.xml file -->
</hibernatetool>
</target>
<target name="hbm2java" description="Run Hibernate Tool" unless="hibernate.skip" depends="">
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="hibernatetools.path"
/>
<hibernatetool destdir="${src.resources.hibernate.generated}">
<configuration>
<fileset dir="${src.resources.hibernate.generated}">
<include name="**/Person*.hbm.xml" />
</fileset>
</configuration>
<hbm2java jdk5="false" ejb3="false" />
</hibernatetool>
</target>
hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<!-- Bind the getCurrentSession() method to the thread, session-per-conversation -->
<property name="current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
<property name="hibernate.connection.url">jdbc:informix-sqli:myhostname:myportnumber/mydatabasename:INFORMIXSERVER=myservername</property>
<property name="hibernate.connection.username">myusername</property>
<property name="hibernate.connection.password">mypassword</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.connection.driver_class">com.informix.jdbc.IfxDriver</property>
<property name="dialect">org.hibernate.dialect.InformixDialect</property>
<property name="show_sql">true</property>
<!-- Connection Pool -->
<property name="hibernate.connection.pool_size">3</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">5</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">100</property>
<!-- Use EHCache as secondary cache-->
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<mapping resource="com/mytest/persistence/orm/hibernate/model/Person.hbm.xml" />
</session-factory>
</hibernate-configuration>
hibernate.reveng.xml
<hibernate-reverse-engineering>
<type-mapping>
<sql-type jdbc-type="5" hibernate-type="integer"/>
</type-mapping>
<table-filter match-catalog="mydatabasename" match-schema="informix" match-name="person" exclude="false" />
</hibernate-reverse-engineering>
Subscribe to:
Posts (Atom)