1 package org.paneris.jammyjoes.model; 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.melati.util.StringUtils; 9 import org.paneris.jammyjoes.controller.ParameterProvider; 10 import org.paneris.jammyjoes.controller.SearchAge; 11 import org.paneris.jammyjoes.model.generated.AgeTableBase; 12 13 public class AgeTable extends AgeTableBase { 14 15 public AgeTable( 16 Database database, String name, 17 DefinitionSource definitionSource) throws PoemException { 18 super(database, name, definitionSource); 19 } 20 21 public SearchAge fromParameter(ParameterProvider provider) { 22 String ageString = provider.getParam("field_age", 2); 23 if (ageString != null) { 24 int hyphen = ageString.indexOf('_'); 25 if (hyphen > 0) { 26 String[] ages = StringUtils.split(ageString, '_'); 27 Integer minAge = new Integer(ages[0]); 28 Integer maxAge = new Integer(ages[1]); 29 String where = minAge + " = " + q("minage") + " AND " + maxAge + " = " + q("maxage"); 30 Enumeration en = selection(where); 31 if (en.hasMoreElements()) { 32 return new SearchAge((Age)en.nextElement()); 33 } 34 return new SearchAge(minAge, maxAge); 35 } else { 36 Enumeration en = getNameColumn().selectionWhereEq(ageString); 37 if (en.hasMoreElements()) { 38 return new SearchAge((Age) en.nextElement()); 39 } 40 en = getPluralNameColumn().selectionWhereEq(ageString); 41 if (en.hasMoreElements()) { 42 return new SearchAge((Age) en.nextElement()); 43 } 44 } 45 } 46 return new SearchAge(); 47 } 48 49 public String q(String name) { 50 StringBuffer b = new StringBuffer(); 51 StringUtils.appendQuoted(b, name, '"'); 52 return b.toString(); 53 } 54 55 }