click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r769101 - in /incubator/click/trunk/click/examples: src/ src/org/apache/click/examples/domain/ src/org/apache/click/examples/domain/auto/ src/org/apache/click/examples/page/cayenne/ src/org/apache/click/examples/service/ src/org/apache/clic...
Date Mon, 27 Apr 2009 18:43:35 GMT
Author: sabob
Date: Mon Apr 27 18:43:34 2009
New Revision: 769101

URL: http://svn.apache.org/viewvc?rev=769101&view=rev
Log:
added two new Cayenne demos (one-to-many and many-to-many)

Added:
    incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Course.java
    incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Student.java
    incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/StudentHouse.java
    incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Course.java
    incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Student.java
    incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_StudentHouse.java
    incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/AccommodationDemo.java
    incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/EnrollmentDemo.java
    incubator/click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java
    incubator/click/trunk/click/examples/src/org/apache/click/examples/util/courses.txt
    incubator/click/trunk/click/examples/src/org/apache/click/examples/util/student-houses.txt
    incubator/click/trunk/click/examples/webapp/cayenne/accommodation-demo.htm
    incubator/click/trunk/click/examples/webapp/cayenne/enrollment-demo.htm
Modified:
    incubator/click/trunk/click/examples/src/cayenneMap.map.xml
    incubator/click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitFilter.java
    incubator/click/trunk/click/examples/webapp/WEB-INF/menu.xml

Modified: incubator/click/trunk/click/examples/src/cayenneMap.map.xml
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/cayenneMap.map.xml?rev=769101&r1=769100&r2=769101&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/cayenneMap.map.xml (original)
+++ incubator/click/trunk/click/examples/src/cayenneMap.map.xml Mon Apr 27 18:43:34 2009
@@ -20,6 +20,10 @@
 		<db-attribute name="last_name" type="VARCHAR" isMandatory="true" length="64"/>
 		<db-attribute name="title" type="VARCHAR" length="8"/>
 	</db-entity>
+	<db-entity name="COURSE">
+		<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="name" type="VARCHAR" length="50"/>
+	</db-entity>
 	<db-entity name="COURSE_BOOKING">
 		<db-attribute name="bookingDate" type="DATE" isMandatory="true"/>
 		<db-attribute name="bookingNotes" type="LONGVARCHAR" isMandatory="true" length="1024"/>
@@ -38,12 +42,25 @@
 		<db-attribute name="investments" type="VARCHAR" length="32"/>
 		<db-attribute name="name" type="VARCHAR" isMandatory="true" length="32"/>
 	</db-entity>
+	<db-entity name="ENROLLMENT">
+		<db-attribute name="courseId" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="studentId" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+	</db-entity>
 	<db-entity name="POST_CODE">
 		<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
 		<db-attribute name="locality" type="VARCHAR" isMandatory="true" length="50"/>
 		<db-attribute name="postCode" type="VARCHAR" isMandatory="true" length="5"/>
 		<db-attribute name="state" type="VARCHAR" isMandatory="true" length="5"/>
 	</db-entity>
+	<db-entity name="STUDENT">
+		<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="name" type="VARCHAR" length="50"/>
+		<db-attribute name="studentHouseId" type="INTEGER"/>
+	</db-entity>
+	<db-entity name="STUDENT_HOUSE">
+		<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="name" type="VARCHAR" length="50"/>
+	</db-entity>
 	<db-entity name="SYSTEM_CODE">
 		<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
 		<db-attribute name="label" type="VARCHAR" isMandatory="true" length="32"/>
@@ -73,6 +90,9 @@
 		<obj-attribute name="lastName" type="java.lang.String" db-attribute-path="last_name"/>
 		<obj-attribute name="title" type="java.lang.String" db-attribute-path="title"/>
 	</obj-entity>
+	<obj-entity name="Course" className="org.apache.click.examples.domain.Course" dbEntityName="COURSE"
superClassName="org.apache.click.examples.domain.BaseEntity">
+		<obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/>
+	</obj-entity>
 	<obj-entity name="CourseBooking" className="org.apache.click.examples.domain.CourseBooking"
dbEntityName="COURSE_BOOKING" superClassName="org.apache.click.examples.domain.BaseEntity">
 		<obj-attribute name="bookingDate" type="java.util.Date" db-attribute-path="bookingDate"/>
 		<obj-attribute name="bookingNotes" type="java.lang.String" db-attribute-path="bookingNotes"/>
@@ -94,6 +114,12 @@
 		<obj-attribute name="postCode" type="java.lang.String" db-attribute-path="postCode"/>
 		<obj-attribute name="state" type="java.lang.String" db-attribute-path="state"/>
 	</obj-entity>
+	<obj-entity name="Student" className="org.apache.click.examples.domain.Student" dbEntityName="STUDENT"
superClassName="org.apache.click.examples.domain.BaseEntity">
+		<obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/>
+	</obj-entity>
+	<obj-entity name="StudentHouse" className="org.apache.click.examples.domain.StudentHouse"
dbEntityName="STUDENT_HOUSE" superClassName="org.apache.click.examples.domain.BaseEntity">
+		<obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/>
+	</obj-entity>
 	<obj-entity name="SystemCode" className="org.apache.click.examples.domain.SystemCode"
dbEntityName="SYSTEM_CODE" superClassName="org.apache.click.examples.domain.BaseEntity">
 		<obj-attribute name="label" type="java.lang.String" db-attribute-path="label"/>
 		<obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/>
@@ -112,8 +138,30 @@
 	<db-relationship name="address" source="CLIENT" target="ADDRESS" toMany="false">
 		<db-attribute-pair source="address_id" target="id"/>
 	</db-relationship>
+	<db-relationship name="ENROLLMENT" source="COURSE" target="ENROLLMENT" toMany="true">
+		<db-attribute-pair source="id" target="courseId"/>
+	</db-relationship>
+	<db-relationship name="COURSE" source="ENROLLMENT" target="COURSE" toMany="false">
+		<db-attribute-pair source="courseId" target="id"/>
+	</db-relationship>
+	<db-relationship name="STUDENT" source="ENROLLMENT" target="STUDENT" toDependentPK="true"
toMany="false">
+		<db-attribute-pair source="studentId" target="id"/>
+	</db-relationship>
+	<db-relationship name="ENROLLMENT" source="STUDENT" target="ENROLLMENT" toMany="true">
+		<db-attribute-pair source="id" target="studentId"/>
+	</db-relationship>
+	<db-relationship name="STUDENT_HOUSE" source="STUDENT" target="STUDENT_HOUSE" toMany="false">
+		<db-attribute-pair source="studentHouseId" target="id"/>
+	</db-relationship>
+	<db-relationship name="STUDENT" source="STUDENT_HOUSE" target="STUDENT" toMany="true">
+		<db-attribute-pair source="id" target="studentHouseId"/>
+	</db-relationship>
 	<obj-relationship name="client" source="Address" target="Client" db-relationship-path="client"/>
 	<obj-relationship name="address" source="Client" target="Address" db-relationship-path="address"/>
+	<obj-relationship name="students" source="Course" target="Student" db-relationship-path="ENROLLMENT.STUDENT"/>
+	<obj-relationship name="courses" source="Student" target="Course" db-relationship-path="ENROLLMENT.COURSE"/>
+	<obj-relationship name="studentHouse" source="Student" target="StudentHouse" db-relationship-path="STUDENT_HOUSE"/>
+	<obj-relationship name="student" source="StudentHouse" target="Student" db-relationship-path="STUDENT"/>
 	<query name="states" factory="org.apache.cayenne.map.SelectQueryBuilder" root="obj-entity"
root-name="SystemCode">
 		<property name="cayenne.GenericSelectQuery.refreshingObjects" value="false"/>
 		<property name="cayenne.GenericSelectQuery.cachePolicy" value="sharedcache"/>

Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Course.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Course.java?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Course.java
(added)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Course.java
Mon Apr 27 18:43:34 2009
@@ -0,0 +1,10 @@
+package org.apache.click.examples.domain;
+
+import org.apache.click.examples.domain.auto._Course;
+
+public class Course extends _Course {
+
+}
+
+
+

Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Student.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Student.java?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Student.java
(added)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Student.java
Mon Apr 27 18:43:34 2009
@@ -0,0 +1,10 @@
+package org.apache.click.examples.domain;
+
+import org.apache.click.examples.domain.auto._Student;
+
+public class Student extends _Student {
+
+}
+
+
+

Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/StudentHouse.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/StudentHouse.java?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/StudentHouse.java
(added)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/StudentHouse.java
Mon Apr 27 18:43:34 2009
@@ -0,0 +1,10 @@
+package org.apache.click.examples.domain;
+
+import org.apache.click.examples.domain.auto._StudentHouse;
+
+public class StudentHouse extends _StudentHouse {
+
+}
+
+
+

Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Course.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Course.java?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Course.java
(added)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Course.java
Mon Apr 27 18:43:34 2009
@@ -0,0 +1,36 @@
+package org.apache.click.examples.domain.auto;
+
+import java.util.List;
+
+/** Class _Course was generated by Cayenne.
+  * It is probably a good idea to avoid changing this class manually, 
+  * since it may be overwritten next time code is regenerated. 
+  * If you need to make any customizations, please use subclass. 
+  */
+public class _Course extends org.apache.click.examples.domain.BaseEntity {
+
+    public static final String NAME_PROPERTY = "name";
+    public static final String STUDENTS_PROPERTY = "students";
+
+    public static final String ID_PK_COLUMN = "id";
+
+    public void setName(String name) {
+        writeProperty("name", name);
+    }
+    public String getName() {
+        return (String)readProperty("name");
+    }
+    
+    
+    public void addToStudents(org.apache.click.examples.domain.Student obj) {
+        addToManyTarget("students", obj, true);
+    }
+    public void removeFromStudents(org.apache.click.examples.domain.Student obj) {
+        removeToManyTarget("students", obj, true);
+    }
+    public List getStudents() {
+        return (List)readProperty("students");
+    }
+    
+    
+}

Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Student.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Student.java?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Student.java
(added)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Student.java
Mon Apr 27 18:43:34 2009
@@ -0,0 +1,46 @@
+package org.apache.click.examples.domain.auto;
+
+import java.util.List;
+
+/** Class _Student was generated by Cayenne.
+  * It is probably a good idea to avoid changing this class manually, 
+  * since it may be overwritten next time code is regenerated. 
+  * If you need to make any customizations, please use subclass. 
+  */
+public class _Student extends org.apache.click.examples.domain.BaseEntity {
+
+    public static final String NAME_PROPERTY = "name";
+    public static final String COURSES_PROPERTY = "courses";
+    public static final String STUDENT_HOUSE_PROPERTY = "studentHouse";
+
+    public static final String ID_PK_COLUMN = "id";
+
+    public void setName(String name) {
+        writeProperty("name", name);
+    }
+    public String getName() {
+        return (String)readProperty("name");
+    }
+    
+    
+    public void addToCourses(org.apache.click.examples.domain.Course obj) {
+        addToManyTarget("courses", obj, true);
+    }
+    public void removeFromCourses(org.apache.click.examples.domain.Course obj) {
+        removeToManyTarget("courses", obj, true);
+    }
+    public List getCourses() {
+        return (List)readProperty("courses");
+    }
+    
+    
+    public void setStudentHouse(org.apache.click.examples.domain.StudentHouse studentHouse)
{
+        setToOneTarget("studentHouse", studentHouse, true);
+    }
+
+    public org.apache.click.examples.domain.StudentHouse getStudentHouse() {
+        return (org.apache.click.examples.domain.StudentHouse)readProperty("studentHouse");
+    } 
+    
+    
+}

Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_StudentHouse.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_StudentHouse.java?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_StudentHouse.java
(added)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_StudentHouse.java
Mon Apr 27 18:43:34 2009
@@ -0,0 +1,36 @@
+package org.apache.click.examples.domain.auto;
+
+import java.util.List;
+
+/** Class _StudentHouse was generated by Cayenne.
+  * It is probably a good idea to avoid changing this class manually, 
+  * since it may be overwritten next time code is regenerated. 
+  * If you need to make any customizations, please use subclass. 
+  */
+public class _StudentHouse extends org.apache.click.examples.domain.BaseEntity {
+
+    public static final String NAME_PROPERTY = "name";
+    public static final String STUDENT_PROPERTY = "student";
+
+    public static final String ID_PK_COLUMN = "id";
+
+    public void setName(String name) {
+        writeProperty("name", name);
+    }
+    public String getName() {
+        return (String)readProperty("name");
+    }
+    
+    
+    public void addToStudent(org.apache.click.examples.domain.Student obj) {
+        addToManyTarget("student", obj, true);
+    }
+    public void removeFromStudent(org.apache.click.examples.domain.Student obj) {
+        removeToManyTarget("student", obj, true);
+    }
+    public List getStudent() {
+        return (List)readProperty("student");
+    }
+    
+    
+}

Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/AccommodationDemo.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/AccommodationDemo.java?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/AccommodationDemo.java
(added)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/AccommodationDemo.java
Mon Apr 27 18:43:34 2009
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.cayenne;
+
+import java.util.List;
+import javax.annotation.Resource;
+import org.apache.cayenne.DataObject;
+
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.click.Context;
+import org.apache.click.control.Column;
+import org.apache.click.control.Decorator;
+import org.apache.click.control.TextField;
+import org.apache.click.examples.domain.Student;
+import org.apache.click.examples.domain.StudentHouse;
+import org.apache.click.examples.service.StudentService;
+import org.apache.click.extras.cayenne.PropertySelect;
+import org.springframework.stereotype.Component;
+
+/**
+ * This example demonstrates how to represent a one-to-many relationship
+ * between StudentHouse and Students using Apache Click.
+ *
+ * A Student House can have many Students, and a Student can only live
+ * in one Student House.
+ *
+ * The relationship is managed by a Select control.
+ *
+ * @author Bob Schellink
+ */
+@Component
+public class AccommodationDemo extends FormTablePage {
+
+    @Resource(name="studentService")
+    private StudentService studentService;
+
+    private PropertySelect select;
+
+    /**
+     * @see FormTablePage#onInit()
+     */
+    public void onInit() {
+        form.add(new TextField("name")).setRequired(true);
+
+        select = new PropertySelect("studentHouse");
+
+        // Populate the Select control with Student Houses where "id" is the
+        // option value and "name" is the option label
+        select.setSelectQuery(new SelectQuery(StudentHouse.class));
+        select.setOptionLabel("name");
+        select.setOptional(true);
+        form.add(select);
+
+        // Table
+        table.addColumn(new Column("id"));
+        table.addColumn(new Column("name"));
+        table.addColumn(new Column("studentHouse")).setDecorator(new Decorator() {
+
+            public String render(Object object, Context context) {
+                Student student = (Student) object;
+                if (student.getStudentHouse() != null) {
+                    return student.getStudentHouse().getName();
+                } else {
+                    return "";
+                }
+            }
+        });
+
+        super.onInit();
+    }
+
+    /**
+     * @see FormTablePage#getDataObject(Object)
+     */
+    public DataObject getDataObject(Object id) {
+        return studentService.getStudent(id);
+    }
+
+    /**
+     * @see FormTablePage#getDataObjectClass()
+     */
+    public Class getDataObjectClass() {
+        return Student.class;
+    }
+
+    /**
+     * @see FormTablePage#getRowList()
+     */
+    public List getRowList() {
+        return studentService.getStudentsByHouse();
+    }
+}

Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/EnrollmentDemo.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/EnrollmentDemo.java?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/EnrollmentDemo.java
(added)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/EnrollmentDemo.java
Mon Apr 27 18:43:34 2009
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.cayenne;
+
+import java.util.List;
+import javax.annotation.Resource;
+import org.apache.cayenne.DataObject;
+
+import org.apache.click.control.Column;
+import org.apache.click.control.TextField;
+import org.apache.click.examples.domain.Course;
+import org.apache.click.examples.domain.Student;
+import org.apache.click.examples.service.StudentService;
+import org.apache.click.extras.control.PickList;
+import org.springframework.stereotype.Component;
+
+/**
+ * This example demonstrates how to represent a many-to-many relationship
+ * between Students and Courses using Apache Click.
+ *
+ * A Student can take many Courses, and a Course can be taken by many Students.
+ *
+ * The relationship is managed by a PickList control.
+ *
+ * @author Bob Schellink
+ */
+@Component
+public class EnrollmentDemo extends FormTablePage {
+
+    @Resource(name="studentService")
+    private StudentService studentService;
+
+    private PickList pickList;
+
+    /**
+     * @see FormTablePage#onInit()
+     */
+    public void onInit() {
+        form.add(new TextField("name")).setRequired(true);
+
+        pickList = new PickList("courseList", "Courses");
+        pickList.addAll(studentService.getCourses(), "id", "name");
+        form.add(pickList);
+
+        // Table
+        table.addColumn(new Column("id"));
+        table.addColumn(new Column("name"));
+
+        super.onInit();
+    }
+
+    /**
+     * @see FormTablePage#onSaveClick()
+     */
+    public boolean onSaveClick() {
+        if (form.isValid()) {
+            Student student = (Student) form.getDataObject();
+
+            List courseIds = pickList.getSelectedValues();
+            studentService.setStudentCourses(student, courseIds);
+
+            saveDataObject(student);
+
+            clear();
+        }
+        return true;
+    }
+
+    /**
+     * @see FormTablePage#onEditClick()
+     */
+    public boolean onEditClick() {
+        Student student = getSelectedStudent();
+
+        // If no student is selected, exist early
+        if (student == null) {
+            return true;
+        }
+
+        // Add each student course to the PickList
+        List courses = student.getCourses();
+        for (int i = 0; i < courses.size(); i++) {
+            Course course = (Course) courses.get(i);
+            pickList.addSelectedValue(course.getId().toString());
+        }
+        form.setDataObject(student);
+
+        return true;
+    }
+
+    /**
+     * @see FormTablePage#clear()
+     */
+    public void clear() {
+        pickList.setSelectedValues(null);
+        super.clear();
+    }
+
+    /**
+     * @see FormTablePage#getDataObject(Object)
+     */
+    public DataObject getDataObject(Object id) {
+        return studentService.getStudent(id);
+    }
+
+    /**
+     * @see FormTablePage#getDataObjectClass()
+     */
+    public Class getDataObjectClass() {
+        return Student.class;
+    }
+
+    /**
+     * @see FormTablePage#getRowList()
+     */
+    public List getRowList() {
+        return studentService.getStudents();
+    }
+
+    /**
+     * Return the selected student or null if no student is selected.
+     *
+     * @return the selected student or null if no student is selected
+     */
+    private Student getSelectedStudent() {
+        Student student = null;
+
+        Integer id = editLink.getValueInteger();
+        if (id != null) {
+            student = (Student) getDataObject(id);
+        }
+        return student;
+    }
+}

Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java
(added)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java
Mon Apr 27 18:43:34 2009
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.service;
+
+import java.util.Iterator;
+import java.util.List;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.query.Ordering;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.click.examples.domain.Course;
+import org.apache.click.examples.domain.Student;
+import org.apache.click.examples.domain.StudentHouse;
+import org.apache.click.extras.cayenne.CayenneTemplate;
+import org.springframework.stereotype.Component;
+
+/**
+ * Provides a Student Service.
+ *
+ * @author Bob Schellink
+ */
+@Component
+public class StudentService extends CayenneTemplate {
+
+    // ---------------------------------------------------------- Student logic
+
+    public List getStudents() {
+        SelectQuery query = new SelectQuery(Student.class);
+        query.addPrefetch("studentHouse");
+        query.addOrdering("db:id", true);
+        return performQuery(query);
+    }
+
+    public Student getStudent(Object id) {
+        SelectQuery query = new SelectQuery(Student.class);
+        query.addPrefetch("courses");
+        query.addPrefetch("studentHouse");
+        query.setQualifier(ExpressionFactory.matchDbExp("id", id));
+
+        List students = getDataContext().performQuery(query);
+
+        if (students.size() == 0) {
+            return null;
+        }
+
+        if (students.size() == 1) {
+            return (Student) students.get(0);
+        } else {
+            String msg = "SelectQuery for " + Student.class.getName()
+                    + " where id equals " + id + " returned "
+                    + students.size() + " rows";
+            throw new RuntimeException(msg);
+        }
+    }
+
+    public void saveStudent(Student student) {
+        if (student.getObjectContext() == null) {
+            registerNewObject(student);
+        }
+        commitChanges();
+    }
+
+    // ----------------------------------------------------------- Course logic
+
+    public void setStudentCourses(Student student, List courseIds) {
+        // First remove current courses
+        List removes = student.getCourses();
+        for (int i = removes.size() - 1; i >= 0; i--) {
+            Course course = (Course) removes.get(i);
+            student.removeFromCourses(course);
+        }
+
+        if (courseIds == null || courseIds.isEmpty()) {
+            return;
+        }
+
+        // Next, set the new courses
+        SelectQuery query = new SelectQuery(Course.class);
+        query.setQualifier(ExpressionFactory.inDbExp("id", courseIds));
+        List courses = getDataContext().performQuery(query);
+
+        for (Iterator it = courses.iterator(); it.hasNext(); ) {
+            Course course = (Course) it.next() ;
+            student.addToCourses(course);
+        }
+    }
+
+    public List getCourses() {
+        SelectQuery query = new SelectQuery(Course.class);
+        query.addOrdering("db:id", true);
+        return performQuery(query);
+    }
+
+    public Course getCourse(Object id) {
+        return (Course) getObjectForPK(Course.class, id);
+    }
+
+    public void saveCourse(Course course) {
+        if (course.getObjectContext() == null) {
+            registerNewObject(course);
+        }
+        commitChanges();
+    }
+
+    // ---------------------------------------------------- Student House logic
+
+    public List getStudentsByHouse() {
+        SelectQuery query = new SelectQuery(Student.class);
+        query.addPrefetch("studentHouse");
+
+        // Add in-memory ordering
+        Ordering ordering = new Ordering("studentHouse.name", true);
+        List result = performQuery(query);
+        ordering.orderList(result);
+        return result;
+    }
+
+    public List getStudentHouses() {
+        SelectQuery query = new SelectQuery(StudentHouse.class);
+        query.addOrdering(StudentHouse.NAME_PROPERTY, true);
+        return performQuery(query);
+    }
+
+    public StudentHouse getStudentHouse(Object id) {
+        return (StudentHouse) getObjectForPK(StudentHouse.class, id);
+    }
+
+    public void saveStudentHouse(StudentHouse studentHouse) {
+        if (studentHouse.getObjectContext() == null) {
+            registerNewObject(studentHouse);
+        }
+        commitChanges();
+    }
+}

Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitFilter.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitFilter.java?rev=769101&r1=769100&r2=769101&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitFilter.java
(original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitFilter.java
Mon Apr 27 18:43:34 2009
@@ -51,6 +51,8 @@
 import org.apache.cayenne.conf.ServletUtil;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.query.SelectQuery;
+import org.apache.click.examples.domain.Course;
+import org.apache.click.examples.domain.StudentHouse;
 import org.apache.commons.lang.WordUtils;
 
 /**
@@ -158,6 +160,12 @@
         // Load post codes data file
         loadPostCodes(dataContext);
 
+        // Load course data file
+        loadCourses(dataContext);
+
+        // Load student houses data file
+        loadStudentHouses(dataContext);
+
         dataContext.commitChanges();
     }
 
@@ -275,6 +283,34 @@
         });
     }
 
+    private void loadCourses(final DataContext dataContext) throws IOException {
+        loadFile("courses.txt", dataContext, new LineProcessor() {
+            public void processLine(String line, DataContext context) {
+                StringTokenizer tokenizer = new StringTokenizer(line, ",");
+
+                Course course = new Course();
+
+                course.setName(next(tokenizer));
+
+                context.registerNewObject(course);
+            }
+        });
+    }
+
+    private void loadStudentHouses(final DataContext dataContext) throws IOException {
+        loadFile("student-houses.txt", dataContext, new LineProcessor() {
+            public void processLine(String line, DataContext context) {
+                StringTokenizer tokenizer = new StringTokenizer(line, ",");
+
+                StudentHouse studentHouse = new StudentHouse();
+
+                studentHouse.setName(next(tokenizer));
+
+                context.registerNewObject(studentHouse);
+            }
+        });
+    }
+
     private static interface LineProcessor {
         public void processLine(String line, DataContext dataContext);
     }

Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/util/courses.txt
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/util/courses.txt?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/util/courses.txt (added)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/util/courses.txt Mon
Apr 27 18:43:34 2009
@@ -0,0 +1,27 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#
+# COURSE table data file, format:
+# name
+#
+Applied Mathematics
+Applied Physics
+Bioengineering
+Computer Science
+Electrical Engineering
+Mechanical Engineering
\ No newline at end of file

Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/util/student-houses.txt
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/util/student-houses.txt?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/util/student-houses.txt
(added)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/util/student-houses.txt
Mon Apr 27 18:43:34 2009
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#
+# STUDENT_HOUSE table data file, format:
+# name
+#
+
+House Vernius
+House Ordos
+House Corrino
+House Boro
\ No newline at end of file

Modified: incubator/click/trunk/click/examples/webapp/WEB-INF/menu.xml
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/WEB-INF/menu.xml?rev=769101&r1=769100&r2=769101&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/webapp/WEB-INF/menu.xml (original)
+++ incubator/click/trunk/click/examples/webapp/WEB-INF/menu.xml Mon Apr 27 18:43:34 2009
@@ -139,6 +139,8 @@
     <menu separator="true"/>
     <menu label="Apache Cayenne Form" path="cayenne/cayenne-form-page.htm"/>
     <menu label="Cayenne Tabbed Form" path="cayenne/tabbed-cayenne-form-page.htm"/>
+    <menu label="Accommodation Demo &lt;br&gt; (one-to-many)" path="cayenne/accommodation-demo.htm"/>
+    <menu label="Enrollment Demo &lt;br&gt; (many-to-many)" path="cayenne/enrollment-demo.htm"/>
     <menu separator="true"/>
     <menu label="Apache POI Excel Export" path="general/excel-export.htm"/>
   </menu>

Added: incubator/click/trunk/click/examples/webapp/cayenne/accommodation-demo.htm
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/cayenne/accommodation-demo.htm?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/webapp/cayenne/accommodation-demo.htm (added)
+++ incubator/click/trunk/click/examples/webapp/cayenne/accommodation-demo.htm Mon Apr 27
18:43:34 2009
@@ -0,0 +1,32 @@
+<!--
+#* Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.*#
+-->
+
+This example demonstrates a one-to-many relationship between a student
+and a student house. A student stays in one student house, but a student house
+has many students.
+
+<p/>
+
+#if ($error) <span class="error">$error</span> #end
+
+$form
+
+<p/>
+
+$table
\ No newline at end of file

Added: incubator/click/trunk/click/examples/webapp/cayenne/enrollment-demo.htm
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/cayenne/enrollment-demo.htm?rev=769101&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/webapp/cayenne/enrollment-demo.htm (added)
+++ incubator/click/trunk/click/examples/webapp/cayenne/enrollment-demo.htm Mon Apr 27 18:43:34
2009
@@ -0,0 +1,24 @@
+<!--
+#* Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.*#
+-->
+
+$form
+
+<p/>
+
+$table
\ No newline at end of file



Mime
View raw message