package business;
import data.DBDriver;
import data.SchemaBuilder;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.sql.SQLException;
public class LexiconEntry extends DBObject implements Serializable {
private String key;
private String topic;
private String language;
private String value;
public LexiconEntry() { }
/**
* Initialize the object. This must be called prior to any database-related methods.
* @param driver The database driver instance.
*/
@Override
public void init( DBDriver driver ) {
super.init( driver );
String className = this.getClass().getName();
Field[] fields = this.getClass().getDeclaredFields();
SchemaBuilder builder = new SchemaBuilder( driver );
schema = builder.getSchema( className, fields);
}
/**
* Populates the object with the ResultSet cursor content.
* @param row The ResultSet cursor to populate the object with.
* @return True on success, false otherwise.
* @throws SQLException
*/
@Override
public boolean populate( ResultSet row ) throws SQLException {
return super.populate( row );
}
/**
* Saves the object to the database.
* @return True if the object has been saved successfully, false otherwise.
*/
@Override
public boolean save() {
return super.save();
}
/**
* Removes the database record matching this object's primary key content fields.
* @return True if the record has been removed successfully, false otherwise.
*/
public boolean remove() {
return driver.delete( schema.getTableName(), formatPKWhere( schema.getPrimaryKeys() ) ) > 0;
}
/**
* Inserts a record into the database containing the content of this object.
* @return True if the record has been inserted successfully, false otherwise.
*/
protected boolean insert() {
int affectedRows;
if( ( affectedRows = driver.insert( schema.getTableName(), getDatabaseFields() ) ) > 0 ) {
newObject = false;
}
return affectedRows > 0;
}
/**
* Updates the database record matching this object's primary key content fields.
* @return True if the record has been updated successfully, false otherwise.
*/
protected boolean update() {
int affectedRows;
if( ( affectedRows = driver.update( schema.getTableName(), getDatabaseFields(), formatPKWhere( schema.getPrimaryKeys() ) ) ) > 0 ) {
dirty = false;
}
return affectedRows > 0;
}
/**
* @return the key
*/
public String getKey() {
return key;
}
/**
* @param key the key to set
*/
public void setKey(String key) {
this.key = key;
}
/**
* @return the topic
*/
public String getTopic() {
return topic;
}
/**
* @param topic the topic to set
*/
public void setTopic(String topic) {
this.topic = topic;
}
/**
* @return the language
*/
public String getLanguage() {
return language;
}
/**
* @param language the language to set
*/
public void setLanguage(String language) {
this.language = language;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
}