int intEndParam = intEnd.intValue();
int beginindex = Math.max(intStartParam - 100, 1);
int endindex = intEndParam + 100;
CustomFieldList cfList = new CustomFieldList();
cfList.setPrimaryMember("Name");
cfList.setSortMember(strSortMem);
CVDal cvdl = new CVDal(dataSource);
Collection colList = null;
try {
if ((strSearch != null) && strSearch.startsWith("ADVANCE:")) {
strSearch = strSearch.substring(8);
String str = "create TEMPORARY TABLE customfieldlistSearch " + strSearch;
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery(str);
cvdl.executeUpdate();
cvdl.clearParameters();
String sortType = "ASC";
if (charSort == 'A') {
sortType = "ASC";
} else {
sortType = "DESC";
}
String strQuery = "select c.customfieldid as customfieldid,c.name as name,c.fieldtype as type,m.name as module,r.name as record from customfield c,module m,cvtable r,customfieldlistSearch cfsearch where r.moduleid=m.moduleid and c.recordtype=r.tableid and cfsearch.customfieldid=c.customfieldid order by "
+ strSortMem + " " + sortType;
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery(strQuery);
colList = cvdl.executeQuery();
cvdl.clearParameters();
cvdl.setSqlQueryToNull();
cvdl.setSqlQuery("DROP TABLE customfieldlistSearch");
cvdl.executeUpdate();
} else {
String sortType = "ASC";
if (charSort == 'A') {
sortType = "ASC";
} else {
sortType = "DESC";
}
String strQuery = "select a.CustomFieldID as customfieldid, a.Name as name,a.FieldType as type,d.name as module,b.name as record from customfield a,cvtable b, module c, module d where a.RecordType = b.tableid and b.moduleid = c.moduleid and c.parentid = d.moduleid and d.name = ? union select a.CustomFieldID as customfieldid, a.Name as name,a.FieldType as type,b.name as module,b.name as record from customfield a,cvtable b, module c, module d where a.RecordType = b.tableid and b.moduleid = c.moduleid and ISNULL(c.parentid) and c.name =? order by "
+ strSortMem + " " + sortType;
cvdl.setSqlQuery(strQuery);
cvdl.setString(1, moduleName);
cvdl.setString(2, moduleName);
colList = cvdl.executeQuery();
}
if (colList.size() > 0) {
Iterator it = colList.iterator();
int i = 0;
while (it.hasNext()) {
i++;
HashMap hm = (HashMap) it.next();
int custfieldID = ((Long) hm.get("customfieldid")).intValue();
try {
IntMember intCustFieldID = new IntMember("CustomFieldID", custfieldID, 10, "", 'T', false, 10);
StringMember strName = null;
if ((hm.get("name") != null)) {
strName = new StringMember("Name", (String) hm.get("name"), 10, "", 'T', true);
} else {
strName = new StringMember("Name", null, 10, "", 'T', true);
}
String typeValue = (hm.get("type") == null) ? "SCALAR" : (String) hm.get("type");
if (typeValue.equals("SCALAR")) {
typeValue = "Single";
} else {
typeValue = "Multiple";
}
StringMember strType = new StringMember("Type", typeValue, 10, "", 'T', false);
StringMember strModule = null;
if ((hm.get("module") != null)) {
strModule = new StringMember("Module", (String) hm.get("module"), 10, "", 'T', false);
} else {
strModule = new StringMember("Module", "", 10, "", 'T', false);
}
StringMember strRecord = null;
if ((hm.get("record") != null)) {
strRecord = new StringMember("Record", (String) hm.get("record"), 10, "", 'T', false);
} else {
strRecord = new StringMember("Record", "", 10, "", 'T', false);
}
CustomFieldListElement cflistelement = new CustomFieldListElement(custfieldID);
cflistelement.put("CustomFieldID", intCustFieldID);
cflistelement.put("Name", strName);
cflistelement.put("Type", strType);
cflistelement.put("Module", strModule);
cflistelement.put("Record", strRecord);
StringBuffer stringbuffer = new StringBuffer("00000000000");
stringbuffer.setLength(11);
String s3 = (new Integer(i)).toString();
stringbuffer.replace(stringbuffer.length() - s3.length(), stringbuffer.length(), s3);
String s4 = stringbuffer.toString();
cfList.put(s4, cflistelement);
} catch (Exception e) {
logger.error("[getCustomFieldList]: Exception", e);
}
}
}
cfList.setTotalNoOfRecords(cfList.size());
cfList.setListType("CustomFields");
cfList.setBeginIndex(beginindex);
cfList.setEndIndex(endindex);
} finally {
cvdl.destroy();
}
return cfList;
}