论坛首页 Java企业应用论坛

jdo直接操作sql

浏览 3058 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-07-13   最后修改:2009-07-13

google推出支持java的gae也有好一段时间了,我准备做一个博客练练手。但是发现gae里操作数据库用的是jdo,jdo虽然是将rdbms转换成了orm但是总感觉有那么点不爽,像这样转换后使得我们只能对数据库做一些简单的操作,本来只需要对数据库进行一次的操作,往往被分割成了多次,消耗了性能不说还增加了页面的相应时间。所以我一直在想:如何能直接用sql语句对数据库进行操作呢?我查了一些jdo的api发现了一个可行方法:

PersistenceManager pm = pmf.getPersistenceManager();
Query q = pm.newQuery("javax.jdo.query.SQL", "EXECUTE sp_who");

 

Query q = pm.newQuery("javax.jdo.query.SQL", "UPDATE MY_TABLE SET MY_COLUMN = ? WHERE MY_ID = ?");

 

Query q = pm.newQuery("javax.jdo.query.SQL","SELECT col1, col2 FROM MYTABLE WHERE col3 = ? AND col4 = ? and col5 = ?");
List results = (List) q.execute(val1, val2, val3);

 

Query query = pm.newQuery("javax.jdo.query.SQL", "SELECT count(*) FROM MYTABLE");
List results = (List) query.execute();
Integer tableSize = (Integer) result.iterator().next();

详细内容查看: http://www.datanucleus.org/products/accessplatform_1_1/jdo/sql.html

不知道这些能不能直接在gae里用呢,但是gae里的bigtable都是根据pojo对象自动创建是的,那自动创建的表的名称有又叫什么呢?有没有哪位大牛实验过?

   发表时间:2009-09-20   最后修改:2009-09-20
呵呵.我测试一下.
  • 大小: 3.9 KB
0 请登录后投票
   发表时间:2009-09-20  
原生sql 好像是不支持.


INFO: Property datanucleus.query.cached unknown - will be ignored
javax.jdo.JDOUserException: Query language "SQL" is not supported by the datastore.
at org.datanucleus.jdo.JDOPersistenceManager.newQuery(JDOPersistenceManager.java:1270)
at com.test.demo.server.LoginUserActionImpl.findLoginUserSize(LoginUserActionImpl.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:527)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:166)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:86)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:124)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:313)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:313)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:844)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)



报了这样的错误.
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics