1 15 package org.apache.tapestry.vlib.ejb; 16 17 import java.io.Serializable ; 18 import java.sql.Timestamp ; 19 20 32 33 public class Book implements Serializable 34 { 35 private static final long serialVersionUID = -3423550323411938995L; 36 37 41 42 public static final int ID_COLUMN = 0; 43 44 48 49 public static final int TITLE_COLUMN = 1; 50 51 public static final int DESCRIPTION_COLUMN = 2; 52 public static final int ISBN_COLUMN = 3; 53 public static final int OWNER_ID_COLUMN = 4; 54 55 61 62 public static final int OWNER_NAME_COLUMN = 5; 63 64 public static final int HOLDER_ID_COLUMN = 6; 65 public static final int HOLDER_NAME_COLUMN = 7; 66 public static final int PUBLISHER_ID_COLUMN = 8; 67 public static final int PUBLISHER_NAME_COLUMN = 9; 68 public static final int AUTHOR_COLUMN = 10; 69 70 public static final int HIDDEN_COLUMN = 11; 71 public static final int LENDABLE_COLUMN = 12; 72 public static final int DATE_ADDED_COLUMN = 13; 73 74 78 79 public static final int N_COLUMNS = 14; 80 81 private Object [] columns; 82 83 87 88 public Book(Object [] columns) 89 { 90 if (columns == null) 91 throw new IllegalArgumentException ("Must provide a non-null columns."); 92 93 if (columns.length != N_COLUMNS) 94 throw new IllegalArgumentException ("Wrong number of columns for a Book."); 95 96 this.columns = new Object [N_COLUMNS]; 97 System.arraycopy(columns, 0, this.columns, 0, N_COLUMNS); 98 } 99 100 private Object get(int index) 101 { 102 return columns[index]; 103 } 104 105 public Integer getId() 106 { 107 return (Integer ) get(ID_COLUMN); 108 } 109 110 public String getTitle() 111 { 112 return (String ) get(TITLE_COLUMN); 113 } 114 115 public String getDescription() 116 { 117 return (String ) get(DESCRIPTION_COLUMN); 118 } 119 120 public String getISBN() 121 { 122 return (String ) get(ISBN_COLUMN); 123 } 124 125 public Integer getOwnerId() 126 { 127 return (Integer ) get(OWNER_ID_COLUMN); 128 } 129 130 public String getOwnerName() 131 { 132 return (String ) get(OWNER_NAME_COLUMN); 133 } 134 135 public Integer getHolderId() 136 { 137 return (Integer ) get(HOLDER_ID_COLUMN); 138 } 139 140 public String getHolderName() 141 { 142 return (String ) get(HOLDER_NAME_COLUMN); 143 } 144 145 public Integer getPublisherId() 146 { 147 return (Integer ) get(PUBLISHER_ID_COLUMN); 148 } 149 150 public String getPublisherName() 151 { 152 return (String ) get(PUBLISHER_NAME_COLUMN); 153 } 154 155 public String getAuthor() 156 { 157 return (String ) get(AUTHOR_COLUMN); 158 } 159 160 public Timestamp getDateAdded() 161 { 162 return (Timestamp ) get(DATE_ADDED_COLUMN); 163 } 164 165 public String toString() 166 { 167 StringBuffer buffer; 168 169 buffer = new StringBuffer ("Book["); 170 buffer.append(get(ID_COLUMN)); 171 buffer.append(' '); 172 buffer.append(get(TITLE_COLUMN)); 173 buffer.append(']'); 174 175 return buffer.toString(); 176 } 177 178 183 184 public boolean isBorrowed() 185 { 186 return !get(HOLDER_ID_COLUMN).equals(get(OWNER_ID_COLUMN)); 187 } 188 189 public boolean isHidden() 190 { 191 return getBit(HIDDEN_COLUMN); 192 } 193 194 public boolean isLendable() 195 { 196 return getBit(LENDABLE_COLUMN); 197 } 198 199 private boolean getBit(int column) 200 { 201 Boolean b = (Boolean ) get(column); 202 203 return b.booleanValue(); 204 } 205 } | Popular Tags |