Hello Again Friends and welcome to my blog. Today i will let u guys have a sneak preview of the Google Application Engine however you may find proprietary google articles but still needs a little bit more explanation so lets start
Google Application Engine lets a user publish websites or web applications to be precise on the google engine or google servers its currently open source and looking on the number of the developers who have contributed to this it's going to be open source for untill a long duration of time.
Currently gooogle Application engine supports only two platforms i.e Python and Java here we will be talking about Java implementation of the application engine i will be using Eclipse Plugin of the Application engine which is available for the lates releases of eclipse Ganymede and Galileo[Latest] the URL of the download site is
For Galileo Package of eclipse
and
For Ganymede Package of eclipse
after installing and downloading the plugins your Eclipse IDE will be ready to develop and deploy the Applications and you would be able to see the Google App Engine ICON now start a new eclipse project
Now Enter the Appropriate Settings such as do you want to use the GWT or not after that you could start building on the JSP pages and classes for your Scripts the technologies which are completeley supported by Google App Engine are
- JSP
- JSPXHTML
- JSTL
- Java Beans
- JDO[Data Nucleus]
- JPA[Data Nucleus]
The J2EE technologies which are not currently completely Supported or with Partial Support which are typically Web Frameworks are
- JSF
- RichFaces
- JPA {Dependency Injection and All}
- Struts
- Seam
The technologies mentioned above are supported only with use some of the tweaks or some other workarounds which i shall explain for each of them And finally Un-supported Technologies
- EJB
- JMX
- Container Managed Persistence[CMP]
and
many more of the J2EE standard ............
We will begin with a simple servlet that would insert value into the Data Store by using a Persistence Enabled Class Lets dive into the code and find out how
//CODE BEGIN Employee.java Entity
package com.equinox;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
/**
*
* @author root
*/
@Entity
@Table(name = "Users")
@NamedQueries({@NamedQuery(name = "Users.findByUserID", query = "SELECT u FROM Users u WHERE u.userID = :userID"), @NamedQuery(name = "Users.findByUsername", query = "SELECT u FROM Users u WHERE u.username = :username"), @NamedQuery(name = "Users.findByPassword", query = "SELECT u FROM Users u WHERE u.password = :password"), @NamedQuery(name = "Users.findByCollegeName", query = "SELECT u FROM Users u WHERE u.collegeName = :collegeName"), @NamedQuery(name = "Users.findByColRegNo", query = "SELECT u FROM Users u WHERE u.colRegNo = :colRegNo"), @NamedQuery(name = "Users.findBySecurityQuestion", query = "SELECT u FROM Users u WHERE u.securityQuestion = :securityQuestion"), @NamedQuery(name = "Users.findBySecurityAnswer", query = "SELECT u FROM Users u WHERE u.securityAnswer = :securityAnswer"), @NamedQuery(name = "Users.findByUserStatus", query = "SELECT u FROM Users u WHERE u.userStatus = :userStatus")})
public class Users implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "UserID", nullable = false)
private Long userID;
@Column(name = "Username")
private String username;
@Column(name = "Password")
private String password;
@Column(name = "SecurityQuestion")
private String securityQuestion;
@Column(name = "SecurityAnswer")
private String securityAnswer;
@Column(name = "UserStatus")
private Boolean userStatus;
@JoinColumn(name="role_id",referencedColumnName="roleID")
private Role role_id;
public Users() {
}
public Role getRole_id() {
return role_id;
}
public void setRole_id(Role role_id) {
this.role_id = role_id;
}
public Users(Long userID) {
this.userID = userID;
}
public Long getUserID() {
return userID;
}
public void setUserID(Long userID) {
this.userID = userID;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSecurityQuestion() {
return securityQuestion;
}
public void setSecurityQuestion(String securityQuestion) {
this.securityQuestion = securityQuestion;
}
public String getSecurityAnswer() {
return securityAnswer;
}
public void setSecurityAnswer(String securityAnswer) {
this.securityAnswer = securityAnswer;
}
public Boolean getUserStatus() {
return userStatus;
}
public void setUserStatus(Boolean userStatus) {
this.userStatus = userStatus;
}
@Override
public int hashCode() {
int hash = 0;
hash += (userID != null ? userID.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Users)) {
return false;
}
Users other = (Users) object;
if ((this.userID == null && other.userID != null) || (this.userID != null && !this.userID.equals(other.userID))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.equinox.Users[userID=" + userID + "]";
}
}
//CODE END
the above given is the Entity Class for the Employee now lets have a look at the controller
//CODE BEGIN EmployeeController.java
package com.equinox.controllers;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import com.equinox.EMF;
import com.equinox.Users;
public class UserController {
public static Users getUser(Integer uid)
{
try{
EntityManager em= EMF.get().createEntityManager();
Users u=em.find(Users.class, uid);
em.close();
return u;
}catch(Exception e)
{
return null;
}
}
public static boolean createNewUser(String username,String password,String secQues,String secAns)
{
Users u = new Users();
u.setUsername(username);
u.setPassword(password);
u.setSecurityQuestion(secQues);
u.setSecurityAnswer(secAns);
try
{
EntityManager em= EMF.get().createEntityManager();
Query q1= em.createQuery("Select r from Role r where r.rolename =:roleName");
q1.setParameter("roleName", "USER");
em.persist(u);
em.clear();
return true;
}catch(Exception e){
return false;
}
}
}
//CODE END
And finally the Servlet which handles the response and creates a dummy user
//CODE Begin
package com.equinox;
import java.io.IOException;
import java.util.Iterator;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class NewtestServlet extends HttpServlet {
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
EntityManager em= EMF.get().createEntityManager();
Users usr= new Users();
usr.setUsername("Techounds");
usr.setPassword("techounds12345");
usr.setSecurityAnswer("jacky");
usr.setSecurityQuestion("what is ur pets name");
usr.setUserStatus(true);
em.persist(usr);
Query q1=em.createQuery("Select u from Users u");
java.util.List l1=(java.util.List)q1.getResultList();
Iterator itr=l1.iterator();
while(itr.hasNext())
{
Users temp= (Users)itr.next();
resp.getWriter().write(temp.getUsername());
}
em.close();
}
}
//CODE END
the above example uses the JPA {DATA NUCLEUS} platform and Entity class along with a custom controller