1 23 24 package org.hammurapi.results.persistent.jdbc; 25 26 import java.sql.PreparedStatement ; 27 import java.sql.ResultSet ; 28 import java.sql.SQLException ; 29 30 import org.hammurapi.WaiverSet; 31 32 import com.pavelvlasov.sql.Parameterizer; 33 import com.pavelvlasov.sql.RowProcessor; 34 35 40 public class NamedResults extends AggregatedResults implements Comparable , org.hammurapi.results.NamedResults { 41 42 47 public NamedResults(int id, ResultsFactory factory) throws SQLException { 48 super(id, factory); 49 factory.getSQLProcessor().processSelect( 50 "SELECT NAME FROM RESULT WHERE ID=?", 51 idParameterizer, 52 new RowProcessor() { 53 public boolean process(ResultSet rs) throws SQLException { 54 name=rs.getString("NAME"); 55 return false; 56 } 57 }); 58 } 59 60 NamedResults(final String name, WaiverSet waiverSet, ResultsFactory factory) throws SQLException { 61 super(waiverSet, factory); 62 this.name=name; 63 factory.getSQLProcessor().processUpdate( 64 "UPDATE RESULT SET NAME=? WHERE ID=?", 65 new Parameterizer() { 66 public void parameterize(PreparedStatement preparedStatement) throws SQLException { 67 preparedStatement.setString(1, name); 68 preparedStatement.setInt(2, getId()); 69 } 70 }); 71 } 72 73 private String name; 74 75 public String getName() { 76 return name; 77 } 78 79 public int compareTo(Object obj) { 80 if (obj instanceof NamedResults) { 81 String otherName=((NamedResults) obj).getName(); 82 if (name==null && otherName==null) { 83 return 0; 84 } else if (name!=null) { 85 return name.compareTo(otherName); 86 } else { 87 return 1; 88 } 89 } 90 91 return 2; 92 } 93 } 94 | Popular Tags |