cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r419076 - in /incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client: ./ src/ src/cayenne/ src/cayenne/tutorial/ src/cayenne/tutorial/client/ src/cayenne/tutorial/client/auto/
Date Tue, 04 Jul 2006 19:31:26 GMT
Author: aadamchik
Date: Tue Jul  4 12:31:25 2006
New Revision: 419076

URL: http://svn.apache.org/viewvc?rev=419076&view=rev
Log:
ROP tutorials

Added:
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/.classpath
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/.project
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Artist.java
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Gallery.java
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Main.java
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Painting.java
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Artist.java
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Gallery.java
    incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Painting.java

Added: incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/.classpath
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/.classpath?rev=419076&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/.classpath
(added)
+++ incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/.classpath
Tue Jul  4 12:31:25 2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="lib" path="/Users/andrus/Desktop/cayenne-1.2RC2/lib/cayenne-client-nodeps.jar"/>
+	<classpathentry kind="lib" path="/Users/andrus/opt/commons-logging-1.0.4/commons-logging.jar"/>
+	<classpathentry kind="lib" path="/Users/andrus/opt/commons-collections-3.1/commons-collections-3.1.jar"/>
+	<classpathentry kind="lib" path="/Users/andrus/opt/commons-lang-2.1/commons-lang-2.1.jar"/>
+	<classpathentry kind="lib" path="/Users/andrus/opt/hessian-3.0.13/hessian-3.0.13.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/.project
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/.project?rev=419076&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/.project
(added)
+++ incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/.project
Tue Jul  4 12:31:25 2006
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>cayenne-tutorial-client</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Artist.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Artist.java?rev=419076&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Artist.java
(added)
+++ incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Artist.java
Tue Jul  4 12:31:25 2006
@@ -0,0 +1,38 @@
+package cayenne.tutorial.client;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import cayenne.tutorial.client.auto._Artist;
+
+/**
+ * A persistent class mapped as "Artist" Cayenne entity.
+ */
+public class Artist extends _Artist {
+    static final String DEFAULT_DATE_FORMAT = "yyyyMMdd";
+
+    /**
+     * Sets date of birth using a string in format yyyyMMdd.
+     */
+    public void setDateOfBirthString(String yearMonthDay) {
+        if (yearMonthDay == null) {
+            setDateOfBirth(null);
+        }
+        else {
+
+            Date date;
+            try {
+                date = new SimpleDateFormat(DEFAULT_DATE_FORMAT).parse(yearMonthDay);
+            }
+            catch (ParseException e) {
+                throw new IllegalArgumentException("A date argument must be in format '"
+                        + DEFAULT_DATE_FORMAT
+                        + "': "
+                        + yearMonthDay);
+            }
+
+            setDateOfBirth(date);
+        }
+    }
+}
\ No newline at end of file

Added: incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Gallery.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Gallery.java?rev=419076&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Gallery.java
(added)
+++ incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Gallery.java
Tue Jul  4 12:31:25 2006
@@ -0,0 +1,10 @@
+package cayenne.tutorial.client;
+
+import cayenne.tutorial.client.auto._Gallery;
+
+/**
+ * A persistent class mapped as "Gallery" Cayenne entity.
+ */
+public class Gallery extends _Gallery {
+
+}
\ No newline at end of file

Added: incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Main.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Main.java?rev=419076&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Main.java
(added)
+++ incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Main.java
Tue Jul  4 12:31:25 2006
@@ -0,0 +1,122 @@
+package cayenne.tutorial.client;
+
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import org.objectstyle.cayenne.CayenneContext;
+import org.objectstyle.cayenne.DataChannel;
+import org.objectstyle.cayenne.DataObjectUtils;
+import org.objectstyle.cayenne.ObjectContext;
+import org.objectstyle.cayenne.exp.Expression;
+import org.objectstyle.cayenne.exp.ExpressionFactory;
+import org.objectstyle.cayenne.query.NamedQuery;
+import org.objectstyle.cayenne.query.QueryChain;
+import org.objectstyle.cayenne.query.SelectQuery;
+import org.objectstyle.cayenne.remote.ClientChannel;
+import org.objectstyle.cayenne.remote.ClientConnection;
+import org.objectstyle.cayenne.remote.hessian.HessianConnection;
+
+public class Main {
+
+	public static void main(String[] args) {
+
+		ClientConnection connection = new HessianConnection(
+				"http://localhost:8080/cayenne-service", "cayenne-user",
+				"secret", null);
+
+		DataChannel channel = new ClientChannel(connection);
+
+		ObjectContext context = new CayenneContext(channel);
+
+		// cleans up all data, so that we start with empty database on each
+		// tutorial run
+		mappingQueriesChapter(context);
+
+		// persists an artist, a gallery and a few paintings
+		dataObjectsChapter(context);
+
+		// selects previously saved data
+		selectQueryChapter(context);
+
+		// deletes objects
+		deleteChapter(context);
+	}
+
+	static void dataObjectsChapter(ObjectContext context) {
+		Artist picasso = (Artist) context.newObject(Artist.class);
+		picasso.setName("Pablo Picasso");
+		picasso.setDateOfBirthString("18811025");
+
+		Gallery metropolitan = (Gallery) context.newObject(Gallery.class);
+		metropolitan.setName("Metropolitan Museum of Art");
+
+		Painting girl = (Painting) context.newObject(Painting.class);
+		girl.setName("Girl Reading at a Table");
+
+		Painting stein = (Painting) context.newObject(Painting.class);
+		stein.setName("Gertrude Stein");
+
+		picasso.addToPaintings(girl);
+		picasso.addToPaintings(stein);
+
+		girl.setGallery(metropolitan);
+		stein.setGallery(metropolitan);
+
+		context.commitChanges();
+	}
+
+	static void mappingQueriesChapter(ObjectContext context) {
+
+		QueryChain chain = new QueryChain();
+		chain.addQuery(new NamedQuery("DeleteAll", Collections.singletonMap(
+				"table", "PAINTING")));
+		chain.addQuery(new NamedQuery("DeleteAll", Collections.singletonMap(
+				"table", "ARTIST")));
+		chain.addQuery(new NamedQuery("DeleteAll", Collections.singletonMap(
+				"table", "GALLERY")));
+
+		context.performGenericQuery(chain);
+
+	}
+
+	static void selectQueryChapter(ObjectContext context) {
+
+		// select all paintings
+		SelectQuery select1 = new SelectQuery(Painting.class);
+		List paintings1 = context.performQuery(select1);
+
+		// select paintings that start with "Gi*"
+		Expression qualifier2 = ExpressionFactory.likeIgnoreCaseExp(
+				Painting.NAME_PROPERTY, "gi%");
+		SelectQuery select2 = new SelectQuery(Painting.class, qualifier2);
+		List paintings2 = context.performQuery(select2);
+
+		// select all paintings done by artists who were born more than a 100
+		// years ago
+		Calendar c = new GregorianCalendar();
+		c.set(c.get(Calendar.YEAR) - 100, 0, 1, 0, 0, 0);
+
+		Expression qualifier3 = Expression
+				.fromString("artist.dateOfBirth < $date");
+		qualifier3 = qualifier3.expWithParameters(Collections.singletonMap(
+				"date", c.getTime()));
+		SelectQuery select3 = new SelectQuery(Painting.class, qualifier3);
+		List paintings3 = context.performQuery(select3);
+	}
+
+	static void deleteChapter(ObjectContext context) {
+		Expression qualifier = ExpressionFactory.matchExp(Artist.NAME_PROPERTY,
+				"Pablo Picasso");
+		SelectQuery select = new SelectQuery(Artist.class, qualifier);
+
+		Artist picasso = (Artist) DataObjectUtils.objectForQuery(context,
+				select);
+		if (picasso != null) {
+
+			context.deleteObject(picasso);
+			context.commitChanges();
+		}
+	}
+}
\ No newline at end of file

Added: incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Painting.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Painting.java?rev=419076&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Painting.java
(added)
+++ incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/Painting.java
Tue Jul  4 12:31:25 2006
@@ -0,0 +1,10 @@
+package cayenne.tutorial.client;
+
+import cayenne.tutorial.client.auto._Painting;
+
+/**
+ * A persistent class mapped as "Painting" Cayenne entity.
+ */
+public class Painting extends _Painting {
+
+}
\ No newline at end of file

Added: incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Artist.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Artist.java?rev=419076&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Artist.java
(added)
+++ incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Artist.java
Tue Jul  4 12:31:25 2006
@@ -0,0 +1,91 @@
+package cayenne.tutorial.client.auto;
+
+import java.util.Date;
+import java.util.List;
+
+import org.objectstyle.cayenne.PersistentObject;
+
+import cayenne.tutorial.client.Painting;
+
+/**
+ * A generated persistent class mapped as "Artist" Cayenne entity. It is a good idea to
+ * avoid changing this class manually, since it will be overwritten next time code is
+ * regenerated. If you need to make any customizations, put them in a subclass.
+ */
+public class _Artist extends PersistentObject {
+
+    public static final String DATE_OF_BIRTH_PROPERTY = "dateOfBirth";
+    public static final String NAME_PROPERTY = "name";
+    public static final String PAINTINGS_PROPERTY = "paintings";
+
+    protected Date dateOfBirth;
+    protected String name;
+    protected List paintings;
+
+    public Date getDateOfBirth() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "dateOfBirth");
+        }
+        
+        return dateOfBirth;
+    }
+    public void setDateOfBirth(Date dateOfBirth) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "dateOfBirth");
+        }
+        
+        Object oldValue = this.dateOfBirth;
+        this.dateOfBirth = dateOfBirth;
+        
+        // notify objectContext about simple property change
+        if(objectContext != null) {
+            objectContext.propertyChanged(this, "dateOfBirth", oldValue, dateOfBirth);
+        }
+    }
+    
+    
+    public String getName() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "name");
+        }
+        
+        return name;
+    }
+    public void setName(String name) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "name");
+        }
+        
+        Object oldValue = this.name;
+        this.name = name;
+        
+        // notify objectContext about simple property change
+        if(objectContext != null) {
+            objectContext.propertyChanged(this, "name", oldValue, name);
+        }
+    }
+    
+    
+    public List getPaintings() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "paintings");
+        }
+        
+        return paintings;
+    }
+    public void addToPaintings(Painting object) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "paintings");
+        }
+        
+        this.paintings.add(object);
+    }
+    public void removeFromPaintings(Painting object) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "paintings");
+        }
+        
+        this.paintings.remove(object);
+    }
+    
+}
\ No newline at end of file

Added: incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Gallery.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Gallery.java?rev=419076&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Gallery.java
(added)
+++ incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Gallery.java
Tue Jul  4 12:31:25 2006
@@ -0,0 +1,66 @@
+package cayenne.tutorial.client.auto;
+
+import java.util.List;
+
+import org.objectstyle.cayenne.PersistentObject;
+
+import cayenne.tutorial.client.Painting;
+
+/**
+ * A generated persistent class mapped as "Gallery" Cayenne entity. It is a good idea to
+ * avoid changing this class manually, since it will be overwritten next time code is
+ * regenerated. If you need to make any customizations, put them in a subclass.
+ */
+public class _Gallery extends PersistentObject {
+
+    public static final String NAME_PROPERTY = "name";
+    public static final String PAINTINGS_PROPERTY = "paintings";
+
+    protected String name;
+    protected List paintings;
+
+    public String getName() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "name");
+        }
+        
+        return name;
+    }
+    public void setName(String name) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "name");
+        }
+        
+        Object oldValue = this.name;
+        this.name = name;
+        
+        // notify objectContext about simple property change
+        if(objectContext != null) {
+            objectContext.propertyChanged(this, "name", oldValue, name);
+        }
+    }
+    
+    
+    public List getPaintings() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "paintings");
+        }
+        
+        return paintings;
+    }
+    public void addToPaintings(Painting object) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "paintings");
+        }
+        
+        this.paintings.add(object);
+    }
+    public void removeFromPaintings(Painting object) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "paintings");
+        }
+        
+        this.paintings.remove(object);
+    }
+    
+}
\ No newline at end of file

Added: incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Painting.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Painting.java?rev=419076&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Painting.java
(added)
+++ incubator/cayenne/main/trunk/cayenne/tutorials/quick-start-rop/cayenne-tutorial-client/src/cayenne/tutorial/client/auto/_Painting.java
Tue Jul  4 12:31:25 2006
@@ -0,0 +1,76 @@
+package cayenne.tutorial.client.auto;
+
+import org.objectstyle.cayenne.PersistentObject;
+import org.objectstyle.cayenne.ValueHolder;
+
+import cayenne.tutorial.client.Artist;
+import cayenne.tutorial.client.Gallery;
+
+/**
+ * A generated persistent class mapped as "Painting" Cayenne entity. It is a good idea to
+ * avoid changing this class manually, since it will be overwritten next time code is
+ * regenerated. If you need to make any customizations, put them in a subclass.
+ */
+public class _Painting extends PersistentObject {
+
+    public static final String NAME_PROPERTY = "name";
+    public static final String ARTIST_PROPERTY = "artist";
+    public static final String GALLERY_PROPERTY = "gallery";
+
+    protected String name;
+    protected ValueHolder artist;
+    protected ValueHolder gallery;
+
+    public String getName() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "name");
+        }
+        
+        return name;
+    }
+    public void setName(String name) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "name");
+        }
+        
+        Object oldValue = this.name;
+        this.name = name;
+        
+        // notify objectContext about simple property change
+        if(objectContext != null) {
+            objectContext.propertyChanged(this, "name", oldValue, name);
+        }
+    }
+    
+    
+    public Artist getArtist() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "artist");
+        }
+        
+        return (Artist) artist.getValue();
+    }
+    public void setArtist(Artist artist) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "artist");
+        }
+        
+        this.artist.setValue(artist);
+    }
+    
+    public Gallery getGallery() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "gallery");
+        }
+        
+        return (Gallery) gallery.getValue();
+    }
+    public void setGallery(Gallery gallery) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "gallery");
+        }
+        
+        this.gallery.setValue(gallery);
+    }
+    
+}
\ No newline at end of file



Mime
View raw message