1 40 package org.dspace.content; 41 42 import java.io.IOException ; 43 import java.sql.SQLException ; 44 import java.util.ArrayList ; 45 46 import org.apache.log4j.Logger; 47 import org.dspace.authorize.AuthorizeException; 48 import org.dspace.core.Context; 49 import org.dspace.core.LogManager; 50 import org.dspace.storage.rdbms.DatabaseManager; 51 import org.dspace.storage.rdbms.TableRow; 52 import org.dspace.storage.rdbms.TableRowIterator; 53 54 64 public class MetadataValue 65 { 66 67 private int fieldId = 0; 68 69 70 private int valueId = 0; 71 72 73 private int itemId; 74 75 76 public String value; 77 78 79 public String language; 80 81 82 public int place = 1; 83 84 85 private static Logger log = Logger.getLogger(MetadataValue.class); 86 87 88 private TableRow row; 89 90 95 public MetadataValue(TableRow row) 96 { 97 if (row != null) 98 { 99 fieldId = row.getIntColumn("metadata_field_id"); 100 valueId = row.getIntColumn("metadata_value_id"); 101 itemId = row.getIntColumn("item_id"); 102 value = row.getStringColumn("text_value"); 103 language = row.getStringColumn("text_lang"); 104 place = row.getIntColumn("place"); 105 this.row = row; 106 } 107 } 108 109 112 public MetadataValue() 113 { 114 } 115 116 121 public MetadataValue(MetadataField field) 122 { 123 this.fieldId = field.getFieldID(); 124 } 125 126 131 public int getFieldId() 132 { 133 return fieldId; 134 } 135 136 141 public void setFieldId(int fieldId) 142 { 143 this.fieldId = fieldId; 144 } 145 146 151 public int getItemId() 152 { 153 return itemId; 154 } 155 156 161 public void setItemId(int itemId) 162 { 163 this.itemId = itemId; 164 } 165 166 171 public String getLanguage() 172 { 173 return language; 174 } 175 176 181 public void setLanguage(String language) 182 { 183 this.language = language; 184 } 185 186 191 public int getPlace() 192 { 193 return place; 194 } 195 196 201 public void setPlace(int place) 202 { 203 this.place = place; 204 } 205 206 211 public int getValueId() 212 { 213 return valueId; 214 } 215 216 221 public String getValue() 222 { 223 return value; 224 } 225 226 231 public void setValue(String value) 232 { 233 this.value = value; 234 } 235 236 244 public void create(Context context) throws SQLException , AuthorizeException 245 { 246 row = DatabaseManager.row("MetadataValue"); 248 row.setColumn("item_id", itemId); 249 row.setColumn("metadata_field_id", fieldId); 250 row.setColumn("text_value", value); 251 row.setColumn("text_lang", language); 252 row.setColumn("place", place); 253 DatabaseManager.insert(context, row); 254 255 this.valueId = row.getIntColumn("metadata_value_id"); 257 258 } 261 262 272 public static MetadataValue find(Context context, int valueId) 273 throws IOException , SQLException , AuthorizeException 274 { 275 TableRowIterator tri = DatabaseManager.queryTable(context, "MetadataValue", 277 "SELECT * FROM MetadataValue where metadata_value_id= ? ", 278 valueId); 279 280 TableRow row = null; 281 if (tri.hasNext()) 282 { 283 row = tri.next(); 284 } 285 286 tri.close(); 288 289 if (row == null) 290 { 291 return null; 292 } 293 else 294 { 295 return new MetadataValue(row); 296 } 297 } 298 299 309 public static java.util.Collection findByField(Context context, int fieldId) 310 throws IOException , SQLException , AuthorizeException 311 { 312 TableRowIterator tri = DatabaseManager.queryTable(context, "MetadataValue", 314 "SELECT * FROM MetadataValue WHERE metadata_field_id= ? ", 315 fieldId); 316 317 TableRow row = null; 318 java.util.Collection ret = new ArrayList (); 319 while (tri.hasNext()) 320 { 321 row = tri.next(); 322 ret.add(new MetadataValue(row)); 323 } 324 325 tri.close(); 327 328 return ret; 329 } 330 331 338 public void update(Context context) throws SQLException , AuthorizeException 339 { 340 row.setColumn("item_id", itemId); 341 row.setColumn("metadata_field_id", fieldId); 342 row.setColumn("text_value", value); 343 row.setColumn("text_lang", language); 344 row.setColumn("place", place); 345 DatabaseManager.update(context, row); 346 347 log.info(LogManager.getHeader(context, "update_metadatavalue", 348 "metadata_value_id=" + getValueId())); 349 } 350 351 358 public void delete(Context context) throws SQLException , AuthorizeException 359 { 360 log.info(LogManager.getHeader(context, "delete_metadata_value", 361 " metadata_value_id=" + getValueId())); 362 DatabaseManager.delete(context, row); 363 } 364 } 365 | Popular Tags |