1 package org.paneris.bibliomania; 2 3 import java.util.Enumeration; 4 5 import org.melati.poem.Database; 6 import org.melati.poem.DefinitionSource; 7 import org.melati.poem.PoemException; 8 import org.paneris.bibliomania.generated.BookTableBase; 9 10 public class BookTable<T extends Book> extends BookTableBase<Book> { 11 12 public BookTable( 13 Database database, 14 String name, 15 DefinitionSource definitionSource) 16 throws PoemException { 17 super(database, name, definitionSource); 18 } 19 20 public Enumeration selectionFor(Section section, Author author) { 21 StringBuffer whereClause = new StringBuffer(); 22 if (section != null) { 23 whereClause.append("section = "); 24 whereClause.append(section.troid()); 25 } 26 27 if (author != null) { 28 if (whereClause.length() != 0) 29 whereClause.append(" AND "); 30 whereClause.append("author = "); 31 whereClause.append(author.troid()); 32 } 33 34 return selection(whereClause.toString()); 35 } 36 public Book ensure(String title, Author author, Section section) { 37 Book p = (Book)getTitleColumn().firstWhereEq(title); 38 if (p == null) { 39 p = (Book)newPersistent(); 40 p.setTitle(title); 41 p.setAuthor(author); 42 p.setPaginated(Boolean.TRUE); 43 p.setSection(section); 44 p.setPath(author.getPath() + "/" + BibliomaniaDatabase.toCamelCase(title, false)); 45 p.setDeleted(false); 46 p.setHasnofrontpage(false); 47 p.setNonstandard(false); 48 p.setNonstandard(false); 49 } 50 return (Book)getTitleColumn().ensure(p); 51 52 } 53 }