| 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 | 2 | super(database, name, definitionSource); |
| 18 | 2 | } |
| 19 | |
|
| 20 | |
public Enumeration selectionFor(Section section, Author author) { |
| 21 | 0 | StringBuffer whereClause = new StringBuffer(); |
| 22 | 0 | if (section != null) { |
| 23 | 0 | whereClause.append("section = "); |
| 24 | 0 | whereClause.append(section.troid()); |
| 25 | |
} |
| 26 | |
|
| 27 | 0 | if (author != null) { |
| 28 | 0 | if (whereClause.length() != 0) |
| 29 | 0 | whereClause.append(" AND "); |
| 30 | 0 | whereClause.append("author = "); |
| 31 | 0 | whereClause.append(author.troid()); |
| 32 | |
} |
| 33 | |
|
| 34 | 0 | return selection(whereClause.toString()); |
| 35 | |
} |
| 36 | |
public Book ensure(String title, Author author, Section section) { |
| 37 | 2 | Book p = (Book)getTitleColumn().firstWhereEq(title); |
| 38 | 2 | if (p == null) { |
| 39 | 0 | p = (Book)newPersistent(); |
| 40 | 0 | p.setTitle(title); |
| 41 | 0 | p.setAuthor(author); |
| 42 | 0 | p.setPaginated(Boolean.TRUE); |
| 43 | 0 | p.setSection(section); |
| 44 | 0 | p.setPath(author.getPath() + "/" + BibliomaniaDatabase.toCamelCase(title, false)); |
| 45 | 0 | p.setDeleted(false); |
| 46 | 0 | p.setHasnofrontpage(false); |
| 47 | 0 | p.setNonstandard(false); |
| 48 | 0 | p.setNonstandard(false); |
| 49 | |
} |
| 50 | 2 | return (Book)getTitleColumn().ensure(p); |
| 51 | |
|
| 52 | |
} |
| 53 | |
} |