首页 > 其他分享 >Appengine部署JPA

Appengine部署JPA

时间:2023-05-24 13:03:06浏览次数:37  
标签:persistence JPA 部署 jarspring 3.1 RELEASE import javax Appengine


Google App Engine and JPA[url]http://www.vogella.com/blog/2011/01/10/google-app-engine-jpa/[/url]
在google app engine中使用JPA [url]http://www.1zhang.com/group/viewthread.php?tid=5188[/url]

1.创建的时候,会自动增加jpa的jar.
2.src/META-INF/persistence.xml

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
	version="1.0">
	<persistence-unit name="transactions-optional">
		<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
		<properties>
			<property name="datanucleus.NontransactionalRead" value="true" />
			<property name="datanucleus.NontransactionalWrite" value="true" />
			<property name="datanucleus.ConnectionURL" value="appengine" />
		</properties>
	</persistence-unit>
	<persistence-unit name="eventual-reads-short-deadlines">
		<provider>org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider</provider>
		<properties>
			<property name="datanucleus.NontransactionalRead" value="true" />
			<property name="datanucleus.NontransactionalWrite" value="true" />
			<property name="datanucleus.ConnectionURL" value="appengine" />

			<property name="datanucleus.appengine.datastoreReadConsistency"
				value="EVENTUAL" />
			<property name="javax.persistence.query.timeout" value="5000" />
			<property name="datanucleus.datastoreWriteTimeout" value="10000" />
		</properties>
	</persistence-unit>
</persistence>



3.Pojo


package com.gae.pandy.pojo;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Todo {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long todoId;
	private String summary;

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}
}



4.service


package com.gae.pandy.service;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class EMFService {
    private static final EntityManagerFactory emfInstance = Persistence
            .createEntityManagerFactory("transactions-optional");

    private EMFService() {
    }

    public static EntityManagerFactory get() {
        return emfInstance;
    }
}



5.servlet


package com.gae.pandy.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gae.pandy.pojo.Todo;
import com.gae.pandy.service.EMFService;

@SuppressWarnings("serial")
public class PersistsServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        this.doPost(req, resp);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        Todo todo = new Todo();

        todo.setSummary("This is my todo");

        EntityManager em = EMFService.get().createEntityManager();
        List<Todo> todos = null;
        try {
            em.persist(todo);//增加到数据库
            Query q = em.createQuery("select t from Todo t");
            todos = new ArrayList(q.getResultList());
        } finally {
            em.close();
        }

        resp.setContentType("text/plain");
        if (todos != null) {
            resp.getWriter().println(
                    "Hello, JPA. We have " + todos.size()
                            + " number of entries.");
        } else {
            resp.getWriter().println("Should not happen");
        }
    }
}



6.web.xml


<servlet>
		<servlet-name>PersistsServlet</servlet-name>
		<servlet-class>com.gae.pandy.controller.PersistsServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>PersistsServlet</servlet-name>
		<url-pattern>/PersistsServlet</url-pattern>
	</servlet-mapping>



执行:[url]http://localhost:8888/PersistsServlet[/url]




aopalliance-1.0.jar


appengine-api-1.0-sdk-1.7.4.jar


appengine-api-labs.jar


appengine-endpoints.jar


appengine-jsr107cache-1.7.4.jar


apps-marketplace.jar


asm-4.0.jar


commons-logging-1.1.1.jar


datanucleus-api-jdo-3.1.1.jar


datanucleus-api-jpa-3.1.1.jar


datanucleus-appengine-2.1.1.jar


datanucleus-core-3.1.1.jar


geronimo-jpa_2.0_spec-1.0.jar


jdo-api-3.0.1.jar


jsr107cache-1.1.jar


jstl.jar


jta-1.1.jar


junit-3.8.1.jar


spring-aop-3.1.2.RELEASE.jar


spring-asm-3.1.2.RELEASE.jar


spring-beans-3.1.2.RELEASE.jar


spring-context-3.1.2.RELEASE.jar


spring-context-support-3.1.2.RELEASE.jar


spring-core-3.1.2.RELEASE.jar


spring-expression-3.1.2.RELEASE.jar


spring-web-3.1.2.RELEASE.jar


spring-webmvc-3.1.2.RELEASE.jar


standard.jar


标签:persistence,JPA,部署,jarspring,3.1,RELEASE,import,javax,Appengine
From: https://blog.51cto.com/u_3871599/6338651

相关文章

  • 使用JPA+Struts2+Spring 在 google Appengine开发应用
    本文同时发表在我在googleAppengine上的搭建的博客:[url]http://blogfor11lu.appspot.com/articleaction_view.action?article.id=agtibG9nZm9yMTFsdXIPCxIHQXJ0aWNsZRjBtQMM[/url]之前用JDO和Struts2在googleAppengine上试着写了一个简单的blog程序,但我还是希望使用Spring......
  • Appengine部署springMVC3.1
    参考:[url]http://sikeh.iteye.com/blog/364043[/url]获得springMVC的方法:[url]http://panyongzheng.iteye.com/blog/1759912[/url][b]1.mvnarchetype:create-DgroupId=com.pandy-DartifactId=study[/b][b]2.cdstudy[/b]需要做一些另外的事情,然......
  • windows环境下的vue部署(使用nginx)
    首先需要将vue项目打包成dist,在需要部署的服务器上进行解压然后我们使用nginx进行反向代理设置,具体操作如下打开解压后的nginx,进入目录:nginx-1.23.4->conf,打开编辑nginx.conf*注意:对于后端路径的映射这里一定是^~/前缀/对应于地址的端口/前缀/,这里一定是两个//包裹。以下......
  • wordpress部署
    wordpress部署1,拉取镜像dockerpull192.168.100.10/library/wordpressdockerpull192.168.100.10/library/mysql:5.62,编写compose文件mkdir/root/wordpressvimdocker-compose.yamlversion:'3.3'services:wordprss:image:192.168.100.1......
  • 3d打印机添加AI炒面检测服务 klipper+fluidd ubuntu本地部署TheSpaghttiDetective Ser
    炒面检测(TheSpaghettiDetective)介绍:炒面检测服务可以借助打印机的摄像头,检测打印是否炒面(打印失败)并作出提醒或停止打印的一种服务,该服务由服务器和客户端组成客户端支持两种: ocoprint或klipper服务器也有两种:ocobi官方提供的有限免费服务......
  • 阿里云vpc下面部署自建k8s一些注意事项
    简介这几天接手了一个政府单位项目,所有的资源均为云资源,而且是阿里云vpc机器。在部署k8s的过程中发现我部署的k8s跨主机网段不通。折腾了我好几天最后发现问题是我在vpc里面是用的不是规定的cidr,我是用的是172.235.0.0修改到规定的cidr清空etcd删除网络重装k8s即可。解决阿......
  • mysql、redis、mongo本地docker部署命令备忘
    1mysqldocker环境部署####获取镜像dockerpullredis####启动mysqldockerrun--name=mysql-it-p3306:3306-eMYSQL_ROOT_PASSWORD=123456-dmysql####登录mysql-h127.0.0.1-P3306-uroot-p1234562redisdocker环境部署####官⽅方指引https://hub.docker.c......
  • 用CentOS服务器自己搭建部署个Discuz论坛网站,网站搭建教程
     Linux系统CentOS服务器使用堡塔搭建论坛网站全套教程。服务器大本营,技术文章内容集合站发车啦! 操作系统:Centos 7.6网站程序:Discuz-X3.4前言首先,搭建一个网站需要准备:服务器、域名、网站程序。 服务器是什么?服务器从字面理解就是提供服务的机器,服务器可以提供哪些......
  • MVC4 部署 could not load file or assembly system.web.http.webhost.....出错
    1.确保项目是.net4.0版本 2.如下图标出的部分,确保这个dll引用是项目本地,找到项目下的“引用”,找到对应的引用右键属性,将“复制本地”改为True,这里我们可以在项目下新建一个存入dll的文件夹,将这些dll放在这个文件夹里面,路径引用改为复制本地为True后就自动引用这个文件夹的路......
  • https部署与docker下nginx的转发+文件获取
    进入nginx容器查看是否有etc/nginx/cert目录将https的域名证书放到cert目录下配置80和443server{#listen80;#侦听80端口listen80;#侦听443端口,用于SSLserver_name127.zyfdtsite.com;client_max_body_size1024m;#charsetkoi8-r;#acc......