基于flex4技术从零开发flex博客系统 : 5 数据存储之管理Greeting
2009-05-05 12:06:18 来源:WEB开发网@SuppressWarnings用于告诉Eclipse不要再提示unchecked警告,不然总会有一个黄色的小灯泡在哪里挂着。
sban:储如2030、2032等等这类与IO、文件等相关的IOError,在flex客户端接口调试中是最常见,也是爆错信息最简单的一类Error。这类Error多是server端代码引起的。
二,删除与更新
在sban.flexblog.HelloWorld这个类中,添加有关删除一个Greeting,删除所有Greeting,编辑单个Greeting,以及获取单个Greeting的接口方法,该类最终代码如下:
package sban.flexblog;
import java.util.Date;
import java.util.List;
import javax.jdo.PersistenceManager;
import sban.flexblog.managers.PMFactory;
/**
* @author sban.li
*
*/
public class HelloWorld {
public String greet(String name) {
return "Hi " + name + ", this message comes from remoting. Now:"
+ new Date().toString();
}
private PersistenceManager pm = PMFactory.getInstance()
.getPersistenceManager();
public Boolean greet2(String user, String content) {
Boolean result = true;
Greeting greeting = new Greeting(user, content, new Date());
try {
pm.makePersistent(greeting);
} catch (Exception e) {
result = false;
} finally {
pm.close();
}
return result;
}
public Greeting getGreetingById(Long id)
{
return (Greeting) pm.getObjectById(Greeting.class, id);
}
public Boolean editGreeting(Long id, String content)
{
Boolean result = true;
try {
Greeting greeting = getGreetingById(id);
greeting.setGreetingContent(content);
} catch (Exception e) {
result = false;
} finally {
pm.close();
}
return result;
}
public Boolean deleteById(Long id) {
Boolean result = true;
try {
Greeting greeting = getGreetingById(id);
pm.deletePersistent(greeting);
} catch (Exception e) {
result = false;
} finally {
pm.close();
}
return result;
}
@SuppressWarnings(value="unchecked")
public Boolean deleteAllGreetings() {
Boolean result = true;
try {
List<Greeting> greetings = (List<Greeting>) pm.newQuery(
Greeting.class).execute();
pm.deletePersistentAll(greetings);
} catch (Exception e) {
result = false;
} finally {
pm.close();
}
return result;
}
@SuppressWarnings(value="unchecked")
public List<Greeting> getAllGreetings() {
List<Greeting> result;
try {
result = (List<Greeting>) pm.newQuery(Greeting.class).execute();
while (result.get(result.size() - 1) == null) {
result.remove(result.size() - 1);
}
} finally {
pm.close();
}
return result;
}
}
更多精彩
赞助商链接