Saturday, April 14, 2012

successful in understanding google app engine .finished learning a full project,awesome concepts

the whole project can be downloaded form http://www.mediafire.com/?2cwxmg5i2cnl3f6
Understanding datastore??
references:-https://developers.google.com/appengine/docs/java/gettingstarted/usingdatastore

 DatastoreService datastore =  DatastoreServiceFactory.getDatastoreService();     datastore.put(greeting);

Because querying in the High Replication datastore is only strongly consistent within entity groups, we assign all Greetings to the same entity group by setting the same parent for each Greeting. This means a user will always see a Greeting immediately after it was written. However, the rate at which you can write to the same entity group is limited to 1 write to the entity group per second.
The low-level Java API provides a Query class for constructing queries and a PreparedQuery class for fetching and returning the entities that match the query from the datastore. The code that fetches the data is here:



Query query = new Query("Greeting", guestbookKey).addSort("date",Query.SortDirection.DESCENDING);
   List<Entity> greetings = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(10));
follow this link:
https://appengine.google.com/->newapps6974(my app name)->datastore indexes
in the datastore indexes you will see the entity name and indexes.refer to the datastore-indexes,xml file now and see the matching.
see the datastore viewer.you will see the mesages in the descending order(datewise)).awesome.

working for the first time with google appengine

today i learnt to run a web project under google app engine from my eclipse ide with the help of google appengine plugins
the encircled area denotes the google plugins.
now to create a new project u click the bluish g icon..and do the needful.
the project is deployed by the deploy app engine project
 after deploying u run it as a run-as web application
my url-http://newapps6974.appspot.com/

references:-http://www.mkyong.com/google-app-engine/google-app-engine-hello-world-example-using-eclipse/

Wednesday, April 11, 2012

The day i started using frameworks

it took some time while getting acquainted with hibernate.but no matter what it was easy learning.
why hibernate?
The developers get rid of writing complex SQLs and no more need of JDBC APIs for resultset handling.
x.cfg.xml file provides  the connection with database.
Y.hbm.xml provides mapping between database column and POJO variable.
A simple web app test to know the basics.

remember to create a database connection on the back end and then select that when you open a new project to execute
the code can be downloaded from 
http://www.mediafire.com/?lw5pvhxpfwx5xr9

hibernate.cfg.xml file


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernatetutorial</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.connection.pool_size">10</property>
        <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <mapping resource="entities/Subscriber.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

Subscriber.hbm.xml


<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping>
    <class name="entities.Subscriber" table="test">
        <id name="uname" type="java.lang.String">
            <column name="username" />
            <generator class="assigned"/>
        </id>
        <property name="pwd" type="java.lang.String">
            <column name="password"/>
        </property>
    </class>
  


</hibernate-mapping>


create a jsp page .pass the login and password say through a form into a servlet.create a getter setter class with the instance variables that are to be used to insert data in a database..these are mapped to column names in the Y.hbm.xml file

the servlet file

 protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter out = response.getWriter();
        String uname = request.getParameter("uname");
        String pwd = request.getParameter("pwd");
        System.out.println("inside the servlet");
        try {
            SessionFactory sf = new Configuration().configure().buildSessionFactory();
            Session s = sf.openSession();
            Subscriber sub = new Subscriber();
            sub.setUname(uname);
            sub.setPwd(pwd);
            s.beginTransaction();
            s.save(sub);
            s.getTransaction().commit();
            s.close();
            sf.close();
            out.println(
                    "<h3 >[" + uname + "  ] has been registered successfully!</h3 >");
        } catch (Exception ex) {
            out.println(
                    "<h3 >[" + uname + "] could NOT be registered!</h3 >");
            System.out.println(ex.getMessage());
        }
    }