/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package uk.org.aspellclark.fillerup.model;
import java.util.ArrayList;
import java.util.HashMap;
import uk.org.aspellclark.common.model.AbstractDataObj;
/**
* @author andy
*/
public class MetaDataKey extends AbstractDataObj {
private static String FIELD_NAME_METADATA_DESC_NAME = "field_name";
private static String FIELD_NAME_METADATA_DESC_DESC = "field_description";
private static String FIELD_NAME_METADATA_DESC_LINK_TBL = "linked_object_table";
private String fieldName = null;
private String fieldDesc = null;
private String linkedObjectTbl = null;
public MetaDataKey() {
}
/**
* Copy constructor.
*
* @param rhs
*/
public MetaDataKey(MetaDataKey rhs) {
this.fieldName = rhs.fieldName;
fieldDesc = rhs.fieldDesc;
linkedObjectTbl = rhs.linkedObjectTbl;
}
public MetaDataKey(HashMap<String, String> aRow) {
fieldName = (aRow.get(FIELD_NAME_METADATA_DESC_NAME));
fieldDesc = (aRow.get(FIELD_NAME_METADATA_DESC_DESC));
linkedObjectTbl = (aRow.get(FIELD_NAME_METADATA_DESC_LINK_TBL));
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !(obj instanceof MetaDataKey)) {
return false;
}
MetaDataKey vObj = (MetaDataKey) obj;
if (!this.fieldName.equals(vObj.fieldName)) {
return false;
}
if (!this.fieldDesc.equals(vObj.fieldDesc)) {
return false;
}
if (!this.linkedObjectTbl.equals(vObj.linkedObjectTbl)) {
return false;
}
return true;
}
@Override
public HashMap<Integer, ArrayList<String>> getFields() {
HashMap<Integer, ArrayList<String>> fields = new HashMap<Integer, ArrayList<String>>();
int x = 1;
fields.put(x++, this.getArrayList(FIELD_NAME_UNIQUE_IDENTIFIER, "INTEGER PRIMARY KEY"));
fields.put(x++, this.getArrayList(FIELD_NAME_METADATA_DESC_NAME, "VARCHAR(20) not null"));
fields.put(x++, this.getArrayList(FIELD_NAME_METADATA_DESC_DESC, "VARCHAR(255) not null"));
fields.put(x++, this.getArrayList(FIELD_NAME_METADATA_DESC_LINK_TBL,
"VARCHAR(255) not null"));
return fields;
}
public String getSelectAllSql(String linkTblName) {
return String.format("select * from %s where %s=%s", this.getTableName(),
FIELD_NAME_METADATA_DESC_LINK_TBL, linkTblName);
}
@Override
public String getSqlInsert() {
StringBuilder sqlStmt = new StringBuilder(super.getSqlInsert());
sqlStmt.append("\"").append(fieldName).append("\",");
sqlStmt.append("\"").append(fieldDesc).append("\",");
sqlStmt.append("\"").append(linkedObjectTbl).append("\",");
sqlStmt.append(");");
return sqlStmt.toString();
}
@Override
public String getSqlUpdate() {
StringBuilder sqlStmt = new StringBuilder(super.getSqlUpdate());
throw new RuntimeException("Not Implemented Yet!");
}
@Override
public String getTableName() {
return "metadatakey";
}
}// class()
|