Author: tv
Date: Thu Nov 28 09:33:37 2019
New Revision: 1870544
URL: http://svn.apache.org/viewvc?rev=1870544&view=rev
Log:
Better localization support for progress text
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java?rev=1870544&r1=1870543&r2=1870544&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java Thu Nov 28 09:33:37 2019
@@ -22,14 +22,15 @@ package org.apache.torque.util;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import org.apache.torque.criteria.Criteria;
@@ -175,18 +176,29 @@ public class LargeSelect<T> implements R
*/
private BasePeerImpl<T> peer = null;
+ /** default MessageFormat pattern for the page progress text */
+ public static final String DEFAULT_PAGE_PROGRESS_TEXT_PATTERN = "{0} of {1,choice,0#> |1#}{2}";
+
/**
- * The default value (">") used to indicate that the total number of
- * records or pages is unknown.
+ * The MessageFormat pattern to format a page progress.
+ * The default <pre>{0} of {1,choice,0#> |1#}{2}</pre> formats as <pre>2 of 3</pre>.
+ * if the total number of records or pages is unknown, the pattern formats as <pre>2 of > 3</pre>.
+ * You can use <code>setPageProgressTextPattern()</code>
+ * to change this to whatever value you like.
*/
- public static final String DEFAULT_MORE_INDICATOR = ">";
+ private String pageProgressTextPattern = DEFAULT_PAGE_PROGRESS_TEXT_PATTERN;
+ /** default MessageFormat pattern for the record progress text */
+ public static final String DEFAULT_RECORD_PROGRESS_TEXT_PATTERN = "{0} - {1} of {2,choice,0#> |1#}{3}";
+
/**
- * The value used to indicate that the total number of records or pages is
- * unknown (default: ">"). You can use <code>setMoreIndicator()</code>
- * to change this to whatever value you like (e.g. "more than").
+ * The MessageFormat pattern to format a record progress.
+ * The default <pre>{0} - {1} of {2,choice,0#> |1#}{3}</pre> formats as <pre>1 - 25 of 100</pre>.
+ * if the total number of records or pages is unknown, the pattern formats as <pre>1 - 25 of > 100</pre>.
+ * You can use <code>setRecordProgressTextPattern()</code>
+ * to change this to whatever value you like.
*/
- private String moreIndicator = DEFAULT_MORE_INDICATOR;
+ private String recordProgressTextPattern = DEFAULT_RECORD_PROGRESS_TEXT_PATTERN;
/**
* The default value for the maximum number of pages of data to be retained
@@ -215,7 +227,7 @@ public class LargeSelect<T> implements R
private Map<String, String> params = null;
/** Logging */
- private static Log log = LogFactory.getLog(LargeSelect.class);
+ private static final Logger log = LogManager.getLogger(LargeSelect.class);
/**
* Creates a LargeSelect whose results are returned as a <code>List</code>
@@ -408,11 +420,7 @@ public class LargeSelect<T> implements R
private synchronized List<T> getResults(final int start, final int size)
throws TorqueException
{
- if (log.isDebugEnabled())
- {
- log.debug("getResults(start: " + start
- + ", size: " + size + ") invoked.");
- }
+ log.debug("getResults(start: {}, size: {}) invoked.", start, size);
if (size > memoryLimit)
{
@@ -425,13 +433,9 @@ public class LargeSelect<T> implements R
// retrieved.
if (start >= blockBegin && (start + size - 1) <= blockEnd)
{
- if (log.isDebugEnabled())
- {
- log.debug("getResults(): Sleeping until "
- + "start+size-1 (" + (start + size - 1)
- + ") > currentlyFilledTo (" + currentlyFilledTo
- + ") && !queryCompleted (!" + queryCompleted + ")");
- }
+ log.debug("getResults(): Sleeping until "
+ + "start+size-1 ({}) > currentlyFilledTo ({}) && !queryCompleted (!{})",
+ start + size - 1, currentlyFilledTo, queryCompleted);
while (((start + size - 1) > currentlyFilledTo) && !queryCompleted)
{
try
@@ -449,11 +453,9 @@ public class LargeSelect<T> implements R
// might want at least 2 sets of data.
else if (start < blockBegin && start >= 0)
{
- if (log.isDebugEnabled())
- {
- log.debug("getResults(): Paging backwards as start (" + start
- + ") < blockBegin (" + blockBegin + ") && start >= 0");
- }
+ log.debug("getResults(): Paging backwards as start "
+ + "({}) < blockBegin ({}) && start >= 0",
+ start, blockBegin);
stopQuery();
if (memoryLimit >= 2 * size)
{
@@ -476,12 +478,9 @@ public class LargeSelect<T> implements R
// Assume we are moving on, do not retrieve any records prior to start.
else if ((start + size - 1) > blockEnd)
{
- if (log.isDebugEnabled())
- {
- log.debug("getResults(): Paging past end of loaded data as "
- + "start+size-1 (" + (start + size - 1)
- + ") > blockEnd (" + blockEnd + ")");
- }
+ log.debug("getResults(): Paging past end of loaded data as start+size-1 "
+ + "({}) > blockEnd ({})",
+ start + size - 1, blockEnd);
stopQuery();
blockBegin = start;
blockEnd = blockBegin + memoryLimit - 1;
@@ -489,7 +488,7 @@ public class LargeSelect<T> implements R
// Re-invoke getResults() to provide the wait processing.
return getResults(start, size);
}
-
+
else
{
throw new IllegalArgumentException("Parameter configuration not "
@@ -499,13 +498,10 @@ public class LargeSelect<T> implements R
int fromIndex = start - blockBegin;
int toIndex = fromIndex + Math.min(size, results.size() - fromIndex);
- if (log.isDebugEnabled())
- {
- log.debug("getResults(): Retrieving records from results elements "
- + "start-blockBegin (" + fromIndex + ") through "
- + "fromIndex + Math.min(size, results.size() - fromIndex) ("
- + toIndex + ")");
- }
+ log.debug("getResults(): Retrieving records from results elements "
+ + "start-blockBegin ({}) through fromIndex + "
+ + "Math.min(size, results.size() - fromIndex) ({})",
+ fromIndex, toIndex);
List<T> returnResults;
@@ -545,11 +541,10 @@ public class LargeSelect<T> implements R
// Execute the query.
if (log.isDebugEnabled())
{
- String query = SqlBuilder.buildQuery(criteria).toString();
- log.debug("run(): query = " + query);
- log.debug("run(): memoryLimit = " + memoryLimit);
- log.debug("run(): blockBegin = " + blockBegin);
- log.debug("run(): blockEnd = " + blockEnd);
+ log.debug("run(): query = {}", SqlBuilder.buildQuery(criteria).toString());
+ log.debug("run(): memoryLimit = {}", memoryLimit);
+ log.debug("run(): blockBegin = {}", blockBegin);
+ log.debug("run(): blockEnd = {}", blockEnd);
}
// Continue getting rows one page at a time until the memory limit
@@ -560,10 +555,7 @@ public class LargeSelect<T> implements R
&& !allRecordsRetrieved
&& currentlyFilledTo + pageSize <= blockEnd)
{
- if (log.isDebugEnabled())
- {
- log.debug("run(): Invoking BasePeerImpl.doSelect()");
- }
+ log.debug("run(): Invoking BasePeerImpl.doSelect()");
List<T> tempResults = peer.doSelect(
criteria,
@@ -625,15 +617,14 @@ public class LargeSelect<T> implements R
if (log.isDebugEnabled())
{
log.debug("run(): While loop terminated because either:");
- log.debug("run(): 1. qds.allRecordsRetrieved(): "
- + allRecordsRetrieved);
- log.debug("run(): 2. killThread: " + killThread);
- log.debug("run(): 3. !(currentlyFilledTo + size <= blockEnd): !"
- + (currentlyFilledTo + pageSize <= blockEnd));
- log.debug("run(): - currentlyFilledTo: " + currentlyFilledTo);
- log.debug("run(): - size: " + pageSize);
- log.debug("run(): - blockEnd: " + blockEnd);
- log.debug("run(): - results.size(): " + results.size());
+ log.debug("run(): 1. qds.allRecordsRetrieved(): {}", allRecordsRetrieved);
+ log.debug("run(): 2. killThread: {}", killThread);
+ log.debug("run(): 3. !(currentlyFilledTo + size <= blockEnd): !{}",
+ currentlyFilledTo + pageSize <= blockEnd);
+ log.debug("run(): - currentlyFilledTo: {}", currentlyFilledTo);
+ log.debug("run(): - size: {}", pageSize);
+ log.debug("run(): - blockEnd: {}", blockEnd);
+ log.debug("run(): - results.size(): {}", results.size());
}
}
catch (TorqueException e)
@@ -647,10 +638,7 @@ public class LargeSelect<T> implements R
// Make sure getResults() finally returns if we die.
queryCompleted = true;
- if (log.isDebugEnabled())
- {
- log.debug("Exiting query thread");
- }
+ log.debug("Exiting query thread");
}
}
@@ -661,10 +649,7 @@ public class LargeSelect<T> implements R
*/
private synchronized void startQuery(final int initialSize)
{
- if (log.isDebugEnabled())
- {
- log.debug("Starting query thread");
- }
+ log.debug("Starting query thread");
if (!threadRunning)
{
pageSize = initialSize;
@@ -674,10 +659,7 @@ public class LargeSelect<T> implements R
thread.setName("LargeSelect query Thread");
thread.start();
threadRunning = true;
- if (log.isDebugEnabled())
- {
- log.debug("query thread started");
- }
+ log.debug("query thread started");
}
}
@@ -689,10 +671,7 @@ public class LargeSelect<T> implements R
*/
private synchronized void stopQuery() throws TorqueException
{
- if (log.isDebugEnabled())
- {
- log.debug("stopQuery(): Stopping query thread");
- }
+ log.debug("stopQuery(): Stopping query thread");
if (threadRunning)
{
killThread = true;
@@ -707,10 +686,7 @@ public class LargeSelect<T> implements R
}
killThread = false;
- if (log.isDebugEnabled())
- {
- log.debug("stopQuery(): query thread stopped.");
- }
+ log.debug("stopQuery(): query thread stopped.");
}
}
@@ -807,23 +783,68 @@ public class LargeSelect<T> implements R
}
/**
- * Provide a way of changing the more pages/records indicator.
- *
- * @param moreIndicator the indicator to use in place of the default
- * (">").
+ * Retrieve the MessageFormat pattern for the page progress
+ * The default is <pre>{0} of {1,choice,0#> |1#}{2}</pre>
+ *
+ * @return the pattern as a string
+ */
+ public String getPageProgressTextPattern()
+ {
+ return pageProgressTextPattern;
+ }
+
+ /**
+ * Set the MessageFormat pattern for the page progress.
+ * The default is <pre>{0} of {1,choice,0#> |1#}{2}</pre>
+ * <p>
+ * The pattern contains three placeholders
+ * <ul>
+ * <li>{0} - the current page</li>
+ * <li>{1} - 0 if the total number of pages is not yet known, 1 otherwise</li>
+ * <li>{2} - the total number of pages</li>
+ * </ul>
+ * <p>
+ * Localized example in German:<br>
+ * <pre>Seite {0} von {1,choice,0#mehr als |1#}{2}</pre>
+ *
+ * @param pageProgressTextPattern
*/
- public void setMoreIndicator(final String moreIndicator)
+ public void setPageProgressTextPattern(String pageProgressTextPattern)
{
- this.moreIndicator = moreIndicator;
+ this.pageProgressTextPattern = pageProgressTextPattern;
}
/**
- * Retrieve the more pages/records indicator.
- * @return string indicating if there are more pages/records
+ * Retrieve the MessageFormat pattern for the record progress
+ * The default is <pre>{0} - {1} of {2,choice,0#> |1#}{3}</pre>
+ *
+ * @return the pattern as a string
+ */
+ public String getRecordProgressTextPattern()
+ {
+ return recordProgressTextPattern;
+ }
+
+ /**
+ * Set the MessageFormat pattern for the record progress.
+ * The default is <pre>{0} - {1} of {2,choice,0#> |1#}{3}</pre>
+ * <p>
+ * The pattern contains four placeholders
+ * <ul>
+ * <li>{0} - number of the first record on the page</li>
+ * <li>{1} - number of the last record on the page</li>
+ * <li>{2} - 0 if the total number of records is not yet known, 1 otherwise</li>
+ * <li>{3} - the total number of records</li>
+ * </ul>
+ * <p>
+ * Localized example in German:<br>
+ * <pre>Datensätze {0} bis {1} von {2,choice,0#mehr als |1#}{3}</pre>
+ *
+ * @param recordProgressTextPattern
*/
- public String getMoreIndicator()
+ public void setRecordProgressTextPattern(String recordProgressTextPattern)
{
- return this.moreIndicator;
+ this.recordProgressTextPattern = recordProgressTextPattern;
}
/**
@@ -861,16 +882,10 @@ public class LargeSelect<T> implements R
*/
public String getPageProgressText()
{
- StringBuilder result = new StringBuilder();
- result.append(getCurrentPageNumber());
- result.append(" of ");
- if (!totalsFinalized)
- {
- result.append(moreIndicator);
- result.append(" ");
- }
- result.append(getTotalPages());
- return result.toString();
+ return MessageFormat.format(getPageProgressTextPattern(),
+ getCurrentPageNumber(),
+ totalsFinalized ? 1 : 0,
+ getTotalPages());
}
/**
@@ -936,18 +951,11 @@ public class LargeSelect<T> implements R
*/
public String getRecordProgressText() throws TorqueException
{
- StringBuilder result = new StringBuilder();
- result.append(getFirstRecordNoForPage());
- result.append(" - ");
- result.append(getLastRecordNoForPage());
- result.append(" of ");
- if (!totalsFinalized)
- {
- result.append(moreIndicator);
- result.append(" ");
- }
- result.append(getTotalRecords());
- return result.toString();
+ return MessageFormat.format(getRecordProgressTextPattern(),
+ getFirstRecordNoForPage(),
+ getLastRecordNoForPage(),
+ totalsFinalized ? 1 : 0,
+ getTotalRecords());
}
/**
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.