1.1 --- a/pom.xml Tue Aug 16 09:09:18 2011 +0300
1.2 +++ b/pom.xml Tue Aug 16 15:54:50 2011 +0300
1.3 @@ -9,7 +9,7 @@
1.4 <vaadin.version>6.5.0</vaadin.version>
1.5 <gwt.version>2.1.1</gwt.version>
1.6 <oracle.jdbc.version>10.1.0.5.0</oracle.jdbc.version>
1.7 - <openjpa.version>2.0.1</openjpa.version>
1.8 + <openjpa.version>2.1.1</openjpa.version>
1.9 </properties>
1.10 <repositories>
1.11 <repository>
1.12 @@ -106,6 +106,27 @@
1.13 </dependency>
1.14 </dependencies>
1.15 </plugin>
1.16 + <plugin>
1.17 + <groupId>org.codehaus.mojo</groupId>
1.18 + <artifactId>exec-maven-plugin</artifactId>
1.19 + <version>1.2</version>
1.20 + <executions>
1.21 + <execution>
1.22 + <goals>
1.23 + <goal>exec</goal>
1.24 + </goals>
1.25 + </execution>
1.26 + </executions>
1.27 + <configuration>
1.28 + <executable>java</executable>
1.29 + <arguments>
1.30 + <argument>-classpath</argument>
1.31 + <classpath/>
1.32 + <argument>-javaagent:${settings.localRepository}/org/apache/openjpa/openjpa/${openjpa.version}/openjpa-${openjpa.version}.jar</argument>
1.33 + <argument>ru.indvdum.mywork.MyWork</argument>
1.34 + </arguments>
1.35 + </configuration>
1.36 + </plugin>
1.37 </plugins>
1.38 </build>
1.39 <dependencies>
1.40 @@ -128,6 +149,12 @@
1.41 <groupId>com.vaadin.addon</groupId>
1.42 <artifactId>jpacontainer-addon-agpl-3.0</artifactId>
1.43 <version>1.2.0</version>
1.44 + <exclusions>
1.45 + <exclusion>
1.46 + <groupId>javax.persistence</groupId>
1.47 + <artifactId>persistence-api</artifactId>
1.48 + </exclusion>
1.49 + </exclusions>
1.50 </dependency>
1.51 <dependency>
1.52 <groupId>com.google.gwt</groupId>
2.1 --- a/src/main/java/ru/indvdum/mywork/openjpa/model/Task.java Tue Aug 16 09:09:18 2011 +0300
2.2 +++ b/src/main/java/ru/indvdum/mywork/openjpa/model/Task.java Tue Aug 16 15:54:50 2011 +0300
2.3 @@ -32,6 +32,18 @@
2.4 public Task(){
2.5
2.6 }
2.7 +
2.8 + @Override
2.9 + public boolean equals(Object obj) {
2.10 + if (this == obj)
2.11 + return true;
2.12 + if (obj == null)
2.13 + return false;
2.14 + if (!(obj instanceof Task))
2.15 + return false;
2.16 + final Task other = (Task) obj;
2.17 + return (this.id == other.id || (this.id != null && this.id.equals(other.id)));
2.18 + }
2.19
2.20 public Integer getId() {
2.21 return id;
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/src/main/java/ru/indvdum/mywork/openjpa/model/Work.java Tue Aug 16 15:54:50 2011 +0300
3.3 @@ -0,0 +1,114 @@
3.4 +package ru.indvdum.mywork.openjpa.model;
3.5 +
3.6 +import javax.persistence.CascadeType;
3.7 +import javax.persistence.Column;
3.8 +import javax.persistence.Entity;
3.9 +import javax.persistence.FetchType;
3.10 +import javax.persistence.Id;
3.11 +import javax.persistence.IdClass;
3.12 +import javax.persistence.ManyToOne;
3.13 +import javax.persistence.MapsId;
3.14 +import javax.persistence.Table;
3.15 +
3.16 +/**
3.17 + * @author indvdum
3.18 + * 16.08.2011 13:55:51
3.19 + *
3.20 + */
3.21 +@Entity
3.22 +@IdClass(WorkId.class)
3.23 +@Table(name = "WORK")
3.24 +public class Work implements IDatabaseObject {
3.25 +
3.26 + private static final long serialVersionUID = 7138260708537798813L;
3.27 +
3.28 +// @Id
3.29 +// @PrimaryKeyJoinColumn
3.30 +// @Column(name = "DAYID", nullable = false)
3.31 +// private Integer dayId = null;
3.32 +//
3.33 +// @Id
3.34 +// @PrimaryKeyJoinColumn
3.35 +// @Column(name = "TASKID", nullable = false)
3.36 +// private Integer taskId = null;
3.37 +
3.38 + @Column(name = "HOURS")
3.39 + private Float hours = null;
3.40 +
3.41 + @Column(name = "RESULT")
3.42 + private String result = null;
3.43 +
3.44 + @Id
3.45 + @ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST})
3.46 + Day day = null;
3.47 +
3.48 + @Id
3.49 + @ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST})
3.50 + Task task = null;
3.51 +
3.52 + public Work(){
3.53 +
3.54 + }
3.55 +
3.56 + @Override
3.57 + public boolean equals(Object obj) {
3.58 + if (this == obj)
3.59 + return true;
3.60 + if (obj == null)
3.61 + return false;
3.62 + if (!(obj instanceof Work))
3.63 + return false;
3.64 + final Work other = (Work) obj;
3.65 + return (
3.66 + this.day == other.day
3.67 + && this.task == other.task
3.68 + || (
3.69 + this.day != null
3.70 + && this.day.equals(other.day)
3.71 + && this.task != null
3.72 + && this.task.equals(other.task)
3.73 + )
3.74 + );
3.75 + }
3.76 +
3.77 +// public Integer getDayId() {
3.78 +// return dayId;
3.79 +// }
3.80 +//
3.81 +// public void setDayId(Integer dayId) {
3.82 +// this.dayId = dayId;
3.83 +// }
3.84 +//
3.85 +// public Integer getTaskId() {
3.86 +// return taskId;
3.87 +// }
3.88 +//
3.89 +// public void setTaskId(Integer taskId) {
3.90 +// this.taskId = taskId;
3.91 +// }
3.92 +
3.93 + public Float getHours() {
3.94 + return hours;
3.95 + }
3.96 +
3.97 + public void setHours(Float hours) {
3.98 + this.hours = hours;
3.99 + }
3.100 +
3.101 + public String getResult() {
3.102 + return result;
3.103 + }
3.104 +
3.105 + public void setResult(String result) {
3.106 + this.result = result;
3.107 + }
3.108 +
3.109 + public Day getDay() {
3.110 + return day;
3.111 + }
3.112 +
3.113 + public void setDay(Day day) {
3.114 + this.day = day;
3.115 + }
3.116 +
3.117 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/src/main/java/ru/indvdum/mywork/openjpa/model/WorkId.java Tue Aug 16 15:54:50 2011 +0300
4.3 @@ -0,0 +1,34 @@
4.4 +package ru.indvdum.mywork.openjpa.model;
4.5 +
4.6 +public class WorkId{
4.7 +
4.8 + public Integer day;
4.9 + public Integer task;
4.10 +
4.11 + @Override
4.12 + public boolean equals(Object obj) {
4.13 + if (this == obj)
4.14 + return true;
4.15 + if (obj == null)
4.16 + return false;
4.17 + if (!(obj instanceof WorkId))
4.18 + return false;
4.19 + final WorkId other = (WorkId) obj;
4.20 + return (
4.21 + this.day == other.day
4.22 + && this.task == other.task
4.23 + || (
4.24 + this.day != null
4.25 + && this.day.equals(other.day)
4.26 + && this.task != null
4.27 + && this.task.equals(other.task)
4.28 + )
4.29 + );
4.30 + }
4.31 +
4.32 + @Override
4.33 + public int hashCode() {
4.34 + return day ^ task;
4.35 + }
4.36 +
4.37 +}
5.1 --- a/src/main/java/ru/indvdum/mywork/vaadin/MyWorkApplication.java Tue Aug 16 09:09:18 2011 +0300
5.2 +++ b/src/main/java/ru/indvdum/mywork/vaadin/MyWorkApplication.java Tue Aug 16 15:54:50 2011 +0300
5.3 @@ -7,13 +7,21 @@
5.4 import javax.persistence.Query;
5.5
5.6 import ru.indvdum.mywork.openjpa.model.Day;
5.7 +import ru.indvdum.mywork.openjpa.model.Task;
5.8 +import ru.indvdum.mywork.openjpa.model.Work;
5.9
5.10 import com.vaadin.Application;
5.11 import com.vaadin.addon.jpacontainer.JPAContainer;
5.12 import com.vaadin.addon.jpacontainer.provider.LocalEntityProvider;
5.13 +import com.vaadin.ui.Alignment;
5.14 +import com.vaadin.ui.Button;
5.15 +import com.vaadin.ui.HorizontalLayout;
5.16 +import com.vaadin.ui.TabSheet;
5.17 import com.vaadin.ui.Table;
5.18 import com.vaadin.ui.VerticalLayout;
5.19 import com.vaadin.ui.Window;
5.20 +import com.vaadin.ui.Button.ClickEvent;
5.21 +import com.vaadin.ui.Button.ClickListener;
5.22
5.23 /**
5.24 * @author indvdum
5.25 @@ -27,21 +35,45 @@
5.26 Window window = new Window();
5.27 setMainWindow(window);
5.28
5.29 - VerticalLayout vl = new VerticalLayout();
5.30 - window.setContent(vl);
5.31 -
5.32 - Query query = EM.createQuery("select x from " + Day.class.getName() + " x");
5.33 + Query query = EM.createQuery("select x from " + Work.class.getName() + " x");
5.34 List list = query.getResultList();
5.35 list.size();
5.36
5.37 -// LocalEntityProvider entityProvider = new LocalEntityProvider(Day.class);
5.38 -// entityProvider.setEntityManager(EM);
5.39 -// JPAContainer<Day> dayContainer = new JPAContainer(Day.class);
5.40 -// dayContainer.setEntityProvider(entityProvider);
5.41 -//
5.42 -// Table dayTable = new Table();
5.43 -// dayTable.setSizeFull();
5.44 -// dayTable.setContainerDataSource(dayContainer);
5.45 -// vl.addComponent(dayTable);
5.46 + TabSheet tabSheet = new TabSheet();
5.47 + tabSheet.setSizeFull();
5.48 + window.setContent(tabSheet);
5.49 +
5.50 + VerticalLayout vlMain = new VerticalLayout();
5.51 + vlMain.setMargin(true);
5.52 + vlMain.setSpacing(true);
5.53 + tabSheet.addTab(vlMain, "Main page", null);
5.54 +
5.55 + LocalEntityProvider dayProvider = new LocalEntityProvider(Day.class);
5.56 + dayProvider.setEntityManager(EM);
5.57 + JPAContainer<Day> dayContainer = new JPAContainer(Day.class);
5.58 + dayContainer.setEntityProvider(dayProvider);
5.59 +
5.60 + final Table dayTable = new Table();
5.61 + dayTable.setSelectable(true);
5.62 + dayTable.setEditable(false);
5.63 + dayTable.setImmediate(true);
5.64 + dayTable.setSizeFull();
5.65 + dayTable.setContainerDataSource(dayContainer);
5.66 + vlMain.addComponent(dayTable);
5.67 + vlMain.setExpandRatio(dayTable, 1f);
5.68 +
5.69 + LocalEntityProvider taskProvider = new LocalEntityProvider(Task.class);
5.70 + taskProvider.setEntityManager(EM);
5.71 + JPAContainer<Task> taskContainer = new JPAContainer(Task.class);
5.72 + taskContainer.setEntityProvider(taskProvider);
5.73 +
5.74 + Table taskTable = new Table();
5.75 + taskTable.setSelectable(true);
5.76 + taskTable.setEditable(false);
5.77 + taskTable.setImmediate(true);
5.78 + taskTable.setSizeFull();
5.79 + taskTable.setContainerDataSource(taskContainer);
5.80 + vlMain.addComponent(taskTable);
5.81 + vlMain.setExpandRatio(taskTable, 1f);
5.82 }
5.83 }
6.1 --- a/src/main/resources/META-INF/persistence.xml Tue Aug 16 09:09:18 2011 +0300
6.2 +++ b/src/main/resources/META-INF/persistence.xml Tue Aug 16 15:54:50 2011 +0300
6.3 @@ -1,10 +1,14 @@
6.4 <?xml version="1.0" encoding="UTF-8"?>
6.5 -<persistence xmlns="http://java.sun.com/xml/ns/persistence"
6.6 - version="1.0">
6.7 +<persistence
6.8 + version="1.0"
6.9 + xmlns="http://java.sun.com/xml/ns/persistence"
6.10 + >
6.11 <persistence-unit name="mywork">
6.12 <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
6.13
6.14 <class>ru.indvdum.mywork.openjpa.model.Day</class>
6.15 + <class>ru.indvdum.mywork.openjpa.model.Task</class>
6.16 + <class>ru.indvdum.mywork.openjpa.model.Work</class>
6.17
6.18 <properties>
6.19 <property name="openjpa.ConnectionPassword" value="1"/>