Author: arminw Date: Thu Nov 8 07:29:20 2007 New Revision: 593197 URL: http://svn.apache.org/viewvc?rev=593197&view=rev Log: add example for use of OJB's xdoclet-module
Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Author.java db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/AuthorDetail.java db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/BasicObject.java db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Book.java db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/CD.java db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/DVD.java db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Medium.java db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/ProductGroup.java db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Publisher.java db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/PublisherImpl.java db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Review.java db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/SampleTest.java Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Author.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Author.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Author.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Author.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,153 @@ +package org.apache.ojb.sample; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; + +/** + * The Author class + * + * FK's only used in a 1:1 reference can use an "anonymous field" (no FK field in java class). + * @ojb.class + * @ojb.field name="fkAuthorDetail" jdbc-type="INTEGER" + */ +public class Author extends BasicObject +{ + /** + * @ojb.field + */ + private String name; + // This field is used by a 1:1 and target of an 1:n reference in class PublisherImpl + // so it's not recommended to use an "anonymous field". But we can declare it as + // private field without getter/setter with a specific PersistentField implementation + // class called 'direct' (the OJB shortcut name) + /** + * @ojb.field field-class="direct" + */ + private Integer fkPublisher; + /** + * @ojb.reference foreignkey="fkPublisher" auto-retrieve="true" + * auto-update="create" auto-delete="none" proxy="true" + */ + private Publisher publisher; + /** + * @ojb.reference foreignkey="fkAuthorDetail" auto-retrieve="true" + * auto-update="create" auto-delete="none" proxy="true" + */ + private AuthorDetail authorDetail; + /** + * @ojb.collection element-class-ref="org.apache.ojb.sample.Medium" + * indirection-table="MEDIUM_AUTHOR" + * foreignkey="authorId" + * auto-retrieve="true" + * auto-update="create" + * auto-delete="none" + * proxy="true" + */ + private List media; + + public Author() + { + } + + public Author(String name, List books) + { + this.name = name; + this.media = books; + } + + public void addMedia(Medium medium) + { + if (media == null) + { + media = new ArrayList(); + } + if (!media.contains(medium)) + { + media.add(medium); + medium.addAuthor(this); + } + } + + public boolean removeMedia(Medium medium) + { + boolean result = false; + if (media != null) + { + result = media.remove(medium); + if (result) medium.removeAuthor(this); + } + return result; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public List getMedia() + { + return media; + } + + public Publisher getPublisher() + { + return publisher; + } + + public void setPublisher(Publisher publisher) + { + if(this.publisher != publisher) + { + Publisher old = this.publisher; + this.publisher = publisher; + if(publisher != null) + { + publisher.addAuthor(this); + } + if(old != null) + { + old.removeAuthor(this); + } + } + } + + public AuthorDetail getAuthorDetail() + { + return authorDetail; + } + + public void setAuthorDetail(AuthorDetail authorDetail) + { + if(this.authorDetail != authorDetail) + { + AuthorDetail old = this.authorDetail; + this.authorDetail = authorDetail; + if(authorDetail != null) authorDetail.setAuthor(this); + if(old != null) old.setAuthor(null); + } + } +} Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/AuthorDetail.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/AuthorDetail.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/AuthorDetail.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/AuthorDetail.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,85 @@ +package org.apache.ojb.sample; + +/* + * 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. + */ + +/** + * Details class of Author class + * + * @ojb.class + * @version $Id$ + */ +public class AuthorDetail extends BasicObject +{ + /** + * @ojb.field + */ + private String bio; + // use PersistentFieldDirectImpl, no getter/setter required + /** + * @ojb.field field-class="direct" + */ + private Integer fkAuthor; + /** + * @ojb.reference foreignkey="fkAuthor" auto-retrieve="true" + * auto-update="create" auto-delete="none" proxy="true" + */ + private Author author; + + public AuthorDetail() + { + } + + public AuthorDetail(String bio) + { + this.bio = bio; + } + + public String getBio() + { + return bio; + } + + public void setBio(String bio) + { + this.bio = bio; + } + + public Author getAuthor() + { + return author; + } + + public void setAuthor(Author author) + { + if(this.author != author) + { + Author old = this.author; + this.author = author; + if(author != null) + { + author.setAuthorDetail(this); + } + if(old != null) + { + old.setAuthorDetail(null); + } + } + } +} Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/BasicObject.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/BasicObject.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/BasicObject.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/BasicObject.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,77 @@ +package org.apache.ojb.sample; + +import java.io.Serializable; + +/* + * 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. + */ + +/** + * A base class. + * + * IMPORTANT: Don't declare a 'ojb.class' tag, because this is only a base class + * and we only need the base fields in the sub-classes (xdoclet shouldn't generate + * the table- or mapping-info for this class). + * + * @version $Id$ + */ +class BasicObject implements Serializable +{ + /** + * @ojb.field autoincrement="ojb" primarykey="true" field-class="direct" + */ + Integer id; + + /** + * @ojb.field locking="true" field-class="direct" + */ + Integer version; + + public Integer getId() + { + return id; + } + + public Integer getVersion() + { + return version; + } + + public boolean equals(Object obj) + { + if (obj != null && obj.getClass().equals(this.getClass())) + { + BasicObject tmp = (BasicObject) obj; + if (tmp.getId() != null) + { + return tmp.getId().equals(this.getId()); + } + else + { + return tmp == this; + } + } + return false; + } + + public int hashCode() + { + // this could cause problems, but I don't know a better way + return id != null ? getId().hashCode() : 0; + } +} Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Book.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Book.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Book.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Book.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,40 @@ +package org.apache.ojb.sample; + +/* + * 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. + */ + +import java.util.Date; + +/** + * The Book class + * + * @ojb.class + * @version $Id$ + */ +public class Book extends Medium +{ + public Book() + { + } + + public Book(String title, Date publicationDate, byte[] cover) + { + super(title, publicationDate, cover); + } +} Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/CD.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/CD.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/CD.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/CD.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,40 @@ +package org.apache.ojb.sample; + +/* + * 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. + */ + +import java.util.Date; + +/** + * The CD class + * + * @ojb.class + * @version $Id$ + */ +public class CD extends Medium +{ + public CD() + { + } + + public CD(String title, Date publicationDate, byte[] cover) + { + super(title, publicationDate, cover); + } +} Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/DVD.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/DVD.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/DVD.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/DVD.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,40 @@ +package org.apache.ojb.sample; + +/* + * 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. + */ + +import java.util.Date; + +/** + * The DVD class + * + * @ojb.class + * @version $Id$ + */ +public class DVD extends Medium +{ + public DVD() + { + } + + public DVD(String title, Date publicationDate, byte[] cover) + { + super(title, publicationDate, cover); + } +} Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Medium.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Medium.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Medium.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Medium.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,234 @@ +package org.apache.ojb.sample; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +/** + * A "medium" base class + * + * FK's only used in a 1:1 reference can use an "anonymous field" (no FK field in java class). + * @ojb.class generate-table-info="false" + * @ojb.field name="fkPublisher" jdbc-type="INTEGER" + * @version $Id$ + */ +public abstract class Medium extends BasicObject +{ + /** + * @ojb.field + */ + private String title; + /** + * @ojb.field jdbc-type="TIMESTAMP" conversion="JavaData2SqlTimestamp" + */ + private Date publicationDate; + /** + * @ojb.field jdbc-type="LONGVARBINARY" + */ + private byte[] cover; + // This field is used by a 1:1 and target of an 1:n reference in class ProductGroup + // so it's not recommended to use an "anonymous field". But we can declare it as + // private field without getter/setter with a specific PersistentField implementation + // class called 'direct' (the OJB shortcut name) + /** + * @ojb.field field-class="direct" + */ + private Integer fkProductGroup; + + /** + * @ojb.reference foreignkey="fkProductGroup" auto-retrieve="true" + * auto-update="create" auto-delete="none" proxy="true" + */ + private ProductGroup productGroup; + /** + * @ojb.reference foreignkey="fkPublisher" auto-retrieve="true" + * auto-update="create" auto-delete="none" proxy="true" + */ + private Publisher publisher; + + + /** + * @ojb.collection element-class-ref="org.apache.ojb.sample.Author" + * indirection-table="MEDIUM_AUTHOR" + * foreignkey="mediumId" + * auto-retrieve="true" + * auto-update="create" + * auto-delete="none" + * proxy="true" + */ + private List authors; + /** + * @ojb.collection element-class-ref="org.apache.ojb.sample.Review" + * foreignkey="fkMedium" + * auto-retrieve="true" + * auto-update="create" + * auto-delete="none" + * proxy="true" + */ + private List reviews; + + public Medium() + { + } + + public Medium(String title, Date publicationDate, byte[] cover) + { + this.title = title; + this.publicationDate = publicationDate; + this.cover = cover; + } + + public String toString() + { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", id).append("title", title).append( + "publicationDate", publicationDate).append("version", + version).append( + "cover", cover).append("authors.size", + authors != null ? authors.size() : 0).append( + "reviews.size", reviews != null ? reviews.size() : 0) + .append("publisher", publisher).toString(); + } + + public void addAuthor(Author author) + { + if (authors == null) + { + authors = new ArrayList(); + } + if (!authors.contains(author)) + { + authors.add(author); + author.addMedia(this); + } + } + + public boolean removeAuthor(Author author) + { + boolean result = false; + if (authors != null) + { + result = authors.remove(author); + if (result) author.removeMedia(this); + } + return result; + } + + public void addReview(Review review) + { + if (reviews == null) + { + reviews = new ArrayList(); + } + if(!reviews.contains(review)) + { + reviews.add(review); + review.setMedium(this); + } + } + + public boolean removeReview(Review review) + { + boolean result = false; + if (reviews != null) result = reviews.remove(review); + if(result) + { + review.setMedium(null); + } + return result; + } + + public String getTitle() + { + return title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public Date getPublicationDate() + { + return publicationDate; + } + + public void setPublicationDate(Date publicationDate) + { + this.publicationDate = publicationDate; + } + + public byte[] getCover() + { + return cover; + } + + public void setCover(byte[] cover) + { + this.cover = cover; + } + + public List getAuthors() + { + return authors; + } + + public List getReviews() + { + return reviews; + } + + public Publisher getPublisher() + { + return publisher; + } + + public void setPublisher(Publisher publisher) + { + this.publisher = publisher; + } + + public ProductGroup getProductGroup() + { + return productGroup; + } + + public void setProductGroup(ProductGroup productGroup) + { + if(this.productGroup != productGroup) + { + ProductGroup old = this.productGroup; + this.productGroup = productGroup; + if(productGroup != null) + { + productGroup.addMedium(this); + } + if(old != null) + { + old.removeMedium(this); + } + } + } +} \ No newline at end of file Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/ProductGroup.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/ProductGroup.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/ProductGroup.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/ProductGroup.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,91 @@ +package org.apache.ojb.sample; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; + +/** + * The ProductGroup class + * + * @ojb.class + * @version $Id$ + */ +public class ProductGroup extends BasicObject +{ + /** + * @ojb.field + */ + private String name; + /** + * @ojb.collection element-class-ref="org.apache.ojb.sample.Medium" + * foreignkey="fkProductGroup" + * auto-retrieve="true" + * auto-update="create" + * auto-delete="none" + * proxy="true" + */ + private List media; + + public ProductGroup() + { + } + + public ProductGroup(String name) + { + this.name = name; + } + + public List getMedia() + { + return media; + } + + public void addMedium(Medium medium) + { + if (media == null) media = new ArrayList(); + if (!media.contains(medium)) + { + media.add(medium); + medium.setProductGroup(this); + } + } + + public boolean removeMedium(Medium medium) + { + boolean result = false; + if (media != null) result = media.remove(medium); + if(result) + { + medium.setProductGroup(null); + } + return result; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } +} \ No newline at end of file Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Publisher.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Publisher.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Publisher.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Publisher.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,44 @@ +package org.apache.ojb.sample; + +/* + * 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. + */ + +import java.io.Serializable; +import java.util.List; + +/** + * The Publisher interface + * + * @ojb.class generate-table-info="false" + * @version $Id$ + */ +public interface Publisher extends Serializable +{ + public Integer getId(); + + public String getName(); + + public void setName(String name); + + public List getAuthors(); + + public boolean removeAuthor(Author author); + + public void addAuthor(Author author); +} Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/PublisherImpl.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/PublisherImpl.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/PublisherImpl.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/PublisherImpl.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,101 @@ +package org.apache.ojb.sample; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; + +/** + * The Publisher implementation class + * + * @ojb.class + * @version $Id$ + */ +public class PublisherImpl extends BasicObject implements Publisher +{ + /** + * @ojb.field + */ + private String name; + + /** + * @ojb.collection element-class-ref="org.apache.ojb.sample.Author" + * foreignkey="fkPublisher" + * auto-retrieve="true" + * auto-update="create" + * auto-delete="none" + * proxy="true" + */ + private List authors; + + public PublisherImpl() + { + } + + public PublisherImpl(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public List getAuthors() + { + return authors; + } + + public void setAuthors(List authors) + { + this.authors = authors; + } + + public void addAuthor(Author author) + { + if (authors == null) + { + authors = new ArrayList(); + } + if (!authors.contains(author)) + { + authors.add(author); + author.setPublisher(this); + } + } + + + public boolean removeAuthor(Author author) + { + boolean result = false; + if (authors != null) result = authors.remove(author); + if(result) + { + author.setPublisher(null); + } + return result; + } +} Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Review.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Review.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Review.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/Review.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,147 @@ +package org.apache.ojb.sample; + +/* + * 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. + */ + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +/** + * The Review class + * + * @ojb.class + * @ojb.field name="fkAuthor" jdbc-type="INTEGER" + * @version $Id$ + */ +public class Review extends BasicObject +{ + /** + * @ojb.field + */ + private Integer vote; + /** + * @ojb.field + */ + private String summary; + // This field is used by a 1:1 and target of an 1:n reference in class Medium + // so it's not recommended to use an "anonymous field". But we can declare it as + // private field without getter/setter with a specific PersistentField implementation + // class called 'direct' (the OJB shortcut name) + /** + * @ojb.field field-class="direct" + */ + private Integer fkMedium; + + /** + * @ojb.reference foreignkey="fkAuthor" auto-retrieve="true" + * auto-update="create" auto-delete="none" proxy="true" + */ + private Author author; + /** + * @ojb.reference foreignkey="fkMedium" auto-retrieve="true" + * auto-update="create" auto-delete="none" proxy="true" + */ + private Medium medium; + + public Review() + { + } + + public Review(String summary, Integer vote, Medium medium) + { + this.summary = summary; + this.vote = vote; + setMedium(medium); + } + + public Review(String summary, Integer vote) + { + this.summary = summary; + this.vote = vote; + } + + public Review(String summary) + { + this.summary = summary; + } + + public Integer getVote() + { + return vote; + } + + public void setVote(Integer vote) + { + this.vote = vote; + } + + public Integer getFkMedium() + { + return fkMedium; + } + + public String getSummary() + { + return summary; + } + + public void setSummary(String summary) + { + this.summary = summary; + } + + public Author getAuthor() + { + return author; + } + + public void setAuthor(Author author) + { + this.author = author; + } + + public Medium getMedium() + { + return medium; + } + + public void setMedium(Medium medium) + { + if(this.medium != medium) + { + Medium old = this.medium; + this.medium = medium; + if(medium != null) + { + medium.addReview(this); + } + if(old != null) + { + old.removeReview(this); + } + } + } + + public String toString() + { + return ToStringBuilder.reflectionToString(this, + ToStringStyle.MULTI_LINE_STYLE, false); + } +} Added: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/SampleTest.java URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/SampleTest.java?rev=593197&view=auto ============================================================================== --- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/SampleTest.java (added) +++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/sample/java/org/apache/ojb/sample/SampleTest.java Thu Nov 8 07:29:20 2007 @@ -0,0 +1,99 @@ +package org.apache.ojb.sample; + +/* + * 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. + */ + +import java.lang.Object; +import java.util.Date; + +import junit.framework.TestCase; +import org.apache.ojb.broker.PersistenceBroker; +import org.apache.ojb.broker.PersistenceBrokerFactory; +import org.apache.ojb.broker.platforms.Platform; + +/** + * This class + * + * @version $Id$ + */ +public class SampleTest extends TestCase +{ + public PersistenceBroker broker; + byte[] cover = new byte[]{10,11,12,13,14,15,16,17,18,19,20}; + + public void test_A() + { + String name = ojbTestMethodIdentifier(); + + ProductGroup pg = new ProductGroup(name); + Book book = new Book(name, new Date(), cover); + CD cd = new CD(name, new Date(), cover); + DVD dvd = new DVD(name, new Date(), cover); + pg.addMedium(book); + pg.addMedium(cd); + pg.addMedium(dvd); + Review review_book_1 = new Review(name, new Integer(5), book); + Review review_book_2 = new Review(name, new Integer(6), book); + Review review_book_3 = new Review(name, new Integer(6), book); + Review review_dvd_1 = new Review(name, new Integer(6), dvd); + + } + + public void setUp() throws Exception + { + super.setUp(); + assertNotNull(broker = PersistenceBrokerFactory.defaultPersistenceBroker()); + // enable batch mode for all used PB instances + broker.serviceConnectionManager().setBatchMode(true); + } + + public void tearDown() throws Exception + { + if(broker != null) + { + try + { + if(broker.isInTransaction()) broker.abortTransaction(); + broker.close(); + } + catch(Exception ignore) + { + } + } + super.tearDown(); + } + + /** + * Returns a string based identifier for the current test compounded by + * test method name and current system time: + * <br/> + * _testMethodName_123349886_ + * + * @return A string based test method identifier. + */ + String ojbTestMethodIdentifier() + { + return "_" + getName() + "_" + System.currentTimeMillis() + "_"; + } + + public static void main(String[] args) + { + junit.textui.TestRunner.main(new String[]{SampleTest.class.getName()}); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]