*/
@SuppressWarnings("unchecked")
public ValueList getValueList(String name, ValueListInfo info) {
int numberPerPage = 0;
Object tplReturn = null;
Session tplSession = null;
List list = null;
ValueList returnValueList = null;
Vector<String> params = null;
String tmpStr = null;
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("ToplinkAdapter.getValueList : '" + name
+ "' start...");
}
/* Check factory object validity */
if (this.sessionFactory == null) {
throw new IllegalArgumentException(
"Toplink session factory can't be null !");
}
/* Configure ValueListInfo object */
// Sorting
if (info.getSortingColumn() == null) {
info.setPrimarySortColumn(getDefaultSortColumn());
info.setPrimarySortDirection(getDefaultSortDirectionInteger());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("The default sort column '"
+ getDefaultSortColumn() + "' with direction '"
+ getDefaultSortDirectionInteger() + "' was set.");
}
}
// Paging
numberPerPage = info.getPagingNumberPer();
if (numberPerPage == Integer.MAX_VALUE) {
numberPerPage = getDefaultNumberPerPage();
info.setPagingNumberPer(numberPerPage);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("The paging number per page '" + numberPerPage
+ "' was set.");
}
}
/* Extract data from database */
// Check type of extraction : DatabaseQuery or NamedQuery
if ((this.databaseQuery == null)
&& (this.namedQuery == null || "".equals(this.namedQuery))) {
throw new IllegalArgumentException(
"One type of database operation must be setted : 'databaseQuery' and 'namedQuery' can't both be null !");
}
// Check parameter validty
if (this.domainClass == null || "".equals(this.domainClass)) {
throw new IllegalArgumentException(
"'domainClass' can't be null !");
}
// Acquire Toplink session
tplSession = this.sessionFactory.createSession();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Toplink session '" + tplSession.getName()
+ "' acquired !");
}
// Data extraction using DatabaseQuery
if (this.databaseQuery != null) {
tplReturn = tplSession.executeQuery(this.databaseQuery);
}
// Data extraction using NamedQuery
else if (this.namedQuery != null && !"".equals(this.namedQuery)) {
// We check if NamedQuery use parameter
if (!this.namedQueryUseParameters) {
tplReturn = tplSession.executeQuery(this.namedQuery);
} else {
// We check to see if NamedQuery parameters are passed by
// HTTP request instead of XML configuration
// HTTP request parameter have higher priority on XML
// configuration. Parameters defined in XML configuration as
// cons�dered as default parameter if no parameter is find
// in HTTP request
if ((info.getFilters().get("namedQueryParameters") != null)
&& !"".equals(info.getFilters().get(
"namedQueryParameters"))) {
tmpStr = (String) info.getFilters().get(
"namedQueryParameters");
} else {
tmpStr = (this.namedQueryParameters == null) ? ""
: this.namedQueryParameters;
}
// Build parameters array
params = new Vector<String>();
if (tmpStr.indexOf("|") != -1) {
for (String str : tmpStr.split("\\|")) {
params.add(str);
}
} else {
params.add(tmpStr);
}
tplReturn = tplSession.executeQuery(this.namedQuery, Class
.forName(this.domainClass.trim()), params);
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Database request executed !");
}
// Process output object
// The database request have extracted a collection of object
if (tplReturn instanceof Vector) {
list = (Vector) tplReturn;
} else {
// The database request have extracted a single object or nothing
list = new Vector();
if (tplReturn != null) {
list.add(tplReturn);
}
}
info.setTotalNumberOfEntries(list.size());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Output object processed !");
}
// Prepare returned object
returnValueList = new DefaultListBackedValueList(list, info);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Retrieved list was wrapped in valuelist, info = "
+ info);
}
} catch (Exception e) {
// Log exception
e.printStackTrace();
LOGGER.error(e);
} finally {
// Release session
if (tplSession != null) {
tplSession.release();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Toplink session '" + tplSession.getName()
+ "' released !");
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("ToplinkAdapter.getValueList : '" + name