Salut;
Je tente de faire une appli en utilisant appengine.
Pour l'instant, il y a du struts 2, tiles 2. Je voudrais utiliser le datastore avec du jpa; mais je n'ai pas d'enregistrements.
Voici mes fichiers:
le persistence.xml
le jdoconfig.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?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.store.appengine.jpa.DatastorePersistenceProvider</provider> <properties> <property name="datanucleus.NontransactionalRead" value="true" /> <property name="datanucleus.NontransactionalWrite" value="true" /> <property name="datanucleus.ConnectionURL" value="appengine" /> </properties> </persistence-unit> </persistence>
le dao
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?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.store.appengine.jpa.DatastorePersistenceProvider</provider> <properties> <property name="datanucleus.NontransactionalRead" value="true" /> <property name="datanucleus.NontransactionalWrite" value="true" /> <property name="datanucleus.ConnectionURL" value="appengine" /> </properties> </persistence-unit> </persistence>
la classe emfservice
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 import java.util.ArrayList; import java.util.Date; import javax.persistence.EntityManager; import javax.persistence.Query; import com.ejavasourcing.entity.Comment; import com.ejavasourcing.service.EMFService; public class CommentDaoImpl implements CommentDao { @Override public void addComment(String pseudo, String email, String comment, String ip, Date dateOfComment) { synchronized (this) { EntityManager em = EMFService.get().createEntityManager(); Comment myComment = new Comment(); myComment.setPseudo(pseudo); myComment.setEmail(email); myComment.setComment(comment); myComment.setIp(ip); myComment.setDateOfComment(dateOfComment); try { em.persist(myComment); } finally { em.close(); } } } public ArrayList <Comment> getAllComment(){ EntityManager em = EMFService.get().createEntityManager(); Query q = em.createQuery("select c from Comment c"); ArrayList <Comment> listOfComments = new ArrayList <Comment>(q.getResultList()); em.close(); return listOfComments; } }
l'entity
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 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; } }
l'action
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 mport java.io.Serializable; import java.util.Date; import javax.jdo.annotations.Persistent; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity (name = "Comment") public class Comment implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int idComment; private String pseudo; private String email; private String comment; private String ip; private Date dateOfComment = new Date(); public Comment() { } public int getIdComment() { return idComment; } public void setIdComment(int idComment) { this.idComment = idComment; } public String getPseudo() { return pseudo; } public void setPseudo(String pseudo) { this.pseudo = pseudo; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getComment() { return comment; } public void setComment(String comment) { this.comment = comment; } public String getIp() { return ip; } public void setIp(String ip) { this.ip = ip; } public Date getDateOfComment() { return dateOfComment; } public void setDateOfComment(Date dateOfComment) { this.dateOfComment = dateOfComment; } }
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 import java.util.ArrayList; import java.util.Date; import javax.servlet.http.HttpServletResponse; import com.ejavasourcing.dao.CommentDao; import com.ejavasourcing.dao.CommentDaoImpl; import com.ejavasourcing.entity.Comment; import com.opensymphony.xwork2.ActionSupport; public class CommentAction extends ActionSupport{ /** * */ private static final long serialVersionUID = 999028149323880000L; private ArrayList <Comment> listOfComments = new ArrayList<Comment>(); private String msg = "test"; public String execute() throws Exception { System.out.println(" in "); CommentDao commentIDao = new CommentDaoImpl(); Date dateOfComment = new Date(); commentIDao.addComment("pseudo", "email", "comment", "ip", dateOfComment); listOfComments = commentIDao.getAllComment(); msg ="row inserted"; return SUCCESS; } public ArrayList<Comment> getListOfComments() { return listOfComments; } public void setListOfComments(ArrayList<Comment> listOfComments) { this.listOfComments = listOfComments; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } }
Je peux pas le tester en local en plus. Les tiles renvoient une excecption. C'est la loose![]()
Partager