aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Koskinen <anna@vaadin.com>2013-01-31 17:29:25 +0200
committerAnna Koskinen <anna@vaadin.com>2013-02-05 15:57:45 +0200
commit515d3c39e3a02e4dc266cac7fd6919748a10e243 (patch)
treea8c5ca2a6e2d2fe813f7827d26bc6cf7e67f6977
parentd597fe70a98ae356414c27d1372005023053f44c (diff)
downloadvaadin-framework-515d3c39e3a02e4dc266cac7fd6919748a10e243.tar.gz
vaadin-framework-515d3c39e3a02e4dc266cac7fd6919748a10e243.zip
Merge of (#10563) to Vaadin 7.
Use template strings and log level checks to improve performance when logging is disabled. Change-Id: I48d370f523c6361ce8704afc7a0903412b31b2a0
-rw-r--r--server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java11
-rw-r--r--server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java18
-rw-r--r--server/src/com/vaadin/event/ListenerMethod.java8
-rw-r--r--server/src/com/vaadin/ui/Table.java79
-rw-r--r--server/src/com/vaadin/ui/TreeTable.java7
5 files changed, 71 insertions, 52 deletions
diff --git a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
index 2ad48aff8c..64c16b2798 100644
--- a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
+++ b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
@@ -1127,7 +1127,7 @@ public class SQLContainer implements Container, Container.Filterable,
refresh(false);
}
getLogger().log(Level.FINER,
- "Updated row count. New count is: " + size);
+ "Updated row count. New count is: {0}", size);
} catch (SQLException e) {
throw new RuntimeException("Failed to update item set size.", e);
}
@@ -1249,7 +1249,8 @@ public class SQLContainer implements Container, Container.Filterable,
"The query delegate doesn't support sorting", e);
}
delegate.beginTransaction();
- rs = delegate.getResults(currentOffset, pageLength * CACHE_RATIO);
+ int fetchedRows = pageLength * CACHE_RATIO;
+ rs = delegate.getResults(currentOffset, fetchedRows);
rsmd = rs.getMetaData();
List<String> pKeys = delegate.getPrimaryKeyColumns();
// }
@@ -1330,10 +1331,8 @@ public class SQLContainer implements Container, Container.Filterable,
rs.getStatement().close();
rs.close();
delegate.commit();
- getLogger().log(
- Level.FINER,
- "Fetched " + pageLength * CACHE_RATIO
- + " rows starting from " + currentOffset);
+ getLogger().log(Level.FINER, "Fetched {0} rows starting from {1}",
+ new Object[] { fetchedRows, currentOffset });
} catch (SQLException e) {
getLogger().log(Level.WARNING,
"Failed to fetch rows, rolling back", e);
diff --git a/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java b/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java
index 246384ee57..eba8b652af 100644
--- a/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java
+++ b/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java
@@ -241,7 +241,7 @@ public class TableQuery implements QueryDelegate,
PreparedStatement pstmt = activeConnection.prepareStatement(
sh.getQueryString(), primaryKeyColumns.toArray(new String[0]));
sh.setParameterValuesToStatement(pstmt);
- getLogger().log(Level.FINE, "DB -> " + sh.getQueryString());
+ getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString());
int result = pstmt.executeUpdate();
if (result > 0) {
/*
@@ -408,7 +408,7 @@ public class TableQuery implements QueryDelegate,
}
PreparedStatement pstmt = c.prepareStatement(sh.getQueryString());
sh.setParameterValuesToStatement(pstmt);
- getLogger().log(Level.FINE, "DB -> " + sh.getQueryString());
+ getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString());
return pstmt.executeQuery();
}
@@ -434,7 +434,7 @@ public class TableQuery implements QueryDelegate,
}
pstmt = c.prepareStatement(sh.getQueryString());
sh.setParameterValuesToStatement(pstmt);
- getLogger().log(Level.FINE, "DB -> " + sh.getQueryString());
+ getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString());
int retval = pstmt.executeUpdate();
return retval;
} finally {
@@ -477,7 +477,7 @@ public class TableQuery implements QueryDelegate,
pstmt = c.prepareStatement(sh.getQueryString(),
primaryKeyColumns.toArray(new String[0]));
sh.setParameterValuesToStatement(pstmt);
- getLogger().log(Level.FINE, "DB -> " + sh.getQueryString());
+ getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString());
int result = pstmt.executeUpdate();
genKeys = pstmt.getGeneratedKeys();
RowId newId = getNewRowId(row, genKeys);
@@ -590,8 +590,10 @@ public class TableQuery implements QueryDelegate,
}
return new RowId(newRowId.toArray());
} catch (Exception e) {
- getLogger().log(Level.FINE,
- "Failed to fetch key values on insert: " + e.getMessage());
+ getLogger()
+ .log(Level.FINE,
+ "Failed to fetch key values on insert: {0}",
+ e.getMessage());
return null;
}
}
@@ -606,8 +608,8 @@ public class TableQuery implements QueryDelegate,
@Override
public boolean removeRow(RowItem row) throws UnsupportedOperationException,
SQLException {
- getLogger().log(Level.FINE,
- "Removing row with id: " + row.getId().getId()[0].toString());
+ getLogger().log(Level.FINE, "Removing row with id: {0}",
+ row.getId().getId()[0].toString());
if (executeUpdate(sqlGenerator.generateDeleteQuery(getTableName(),
primaryKeyColumns, versionColumn, row)) == 1) {
return true;
diff --git a/server/src/com/vaadin/event/ListenerMethod.java b/server/src/com/vaadin/event/ListenerMethod.java
index 16a8121901..a0ecdc4769 100644
--- a/server/src/com/vaadin/event/ListenerMethod.java
+++ b/server/src/com/vaadin/event/ListenerMethod.java
@@ -91,10 +91,10 @@ public class ListenerMethod implements EventListener, Serializable {
out.writeObject(name);
out.writeObject(paramTypes);
} catch (NotSerializableException e) {
- getLogger().warning(
- "Error in serialization of the application: Class "
- + target.getClass().getName()
- + " must implement serialization.");
+ getLogger()
+ .log(Level.WARNING,
+ "Error in serialization of the application: Class {0} must implement serialization.",
+ target.getClass().getName());
throw e;
}
diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java
index 10752140db..940001fb51 100644
--- a/server/src/com/vaadin/ui/Table.java
+++ b/server/src/com/vaadin/ui/Table.java
@@ -1840,9 +1840,10 @@ public class Table extends AbstractSelect implements Action.Container,
* @return
*/
private Object[][] getVisibleCellsInsertIntoCache(int firstIndex, int rows) {
- getLogger().finest(
- "Insert " + rows + " rows at index " + firstIndex
- + " to existing page buffer requested");
+ getLogger()
+ .log(Level.FINEST,
+ "Insert {0} rows at index {1} to existing page buffer requested",
+ new Object[] { rows, firstIndex });
// Page buffer must not become larger than pageLength*cacheRate before
// or after the current page
@@ -1945,14 +1946,16 @@ public class Table extends AbstractSelect implements Action.Container,
}
}
pageBuffer = newPageBuffer;
- getLogger().finest(
- "Page Buffer now contains "
- + pageBuffer[CELL_ITEMID].length
- + " rows ("
- + pageBufferFirstIndex
- + "-"
- + (pageBufferFirstIndex
- + pageBuffer[CELL_ITEMID].length - 1) + ")");
+ if (getLogger().isLoggable(Level.FINEST)) {
+ getLogger().log(
+ Level.FINEST,
+ "Page Buffer now contains {0} rows ({1}-{2})",
+ new Object[] {
+ pageBuffer[CELL_ITEMID].length,
+ pageBufferFirstIndex,
+ (pageBufferFirstIndex
+ + pageBuffer[CELL_ITEMID].length - 1) });
+ }
return cells;
}
@@ -1969,9 +1972,11 @@ public class Table extends AbstractSelect implements Action.Container,
*/
private Object[][] getVisibleCellsNoCache(int firstIndex, int rows,
boolean replaceListeners) {
- getLogger().finest(
- "Render visible cells for rows " + firstIndex + "-"
- + (firstIndex + rows - 1));
+ if (getLogger().isLoggable(Level.FINEST)) {
+ getLogger().log(Level.FINEST,
+ "Render visible cells for rows {0}-{1}",
+ new Object[] { firstIndex, (firstIndex + rows - 1) });
+ }
final Object[] colids = getVisibleColumns();
final int cols = colids.length;
@@ -2214,9 +2219,11 @@ public class Table extends AbstractSelect implements Action.Container,
}
protected void registerComponent(Component component) {
- getLogger().finest(
- "Registered " + component.getClass().getSimpleName() + ": "
- + component.getCaption());
+ getLogger().log(
+ Level.FINEST,
+ "Registered {0}: {1}",
+ new Object[] { component.getClass().getSimpleName(),
+ component.getCaption() });
if (component.getParent() != this) {
component.setParent(this);
}
@@ -2247,9 +2254,11 @@ public class Table extends AbstractSelect implements Action.Container,
* @param count
*/
private void unregisterComponentsAndPropertiesInRows(int firstIx, int count) {
- getLogger().finest(
- "Unregistering components in rows " + firstIx + "-"
- + (firstIx + count - 1));
+ if (getLogger().isLoggable(Level.FINEST)) {
+ getLogger().log(Level.FINEST,
+ "Unregistering components in rows {0}-{1}",
+ new Object[] { firstIx, (firstIx + count - 1) });
+ }
Object[] colids = getVisibleColumns();
if (pageBuffer != null && pageBuffer[CELL_ITEMID].length > 0) {
int bufSize = pageBuffer[CELL_ITEMID].length;
@@ -2329,9 +2338,11 @@ public class Table extends AbstractSelect implements Action.Container,
* a set of components that should be unregistered.
*/
protected void unregisterComponent(Component component) {
- getLogger().finest(
- "Unregistered " + component.getClass().getSimpleName() + ": "
- + component.getCaption());
+ getLogger().log(
+ Level.FINEST,
+ "Unregistered {0}: {1}",
+ new Object[] { component.getClass().getSimpleName(),
+ component.getCaption() });
component.setParent(null);
/*
* Also remove property data sources to unregister listeners keeping the
@@ -2765,9 +2776,13 @@ public class Table extends AbstractSelect implements Action.Container,
}
}
}
- getLogger().finest(
- "Client wants rows " + reqFirstRowToPaint + "-"
- + (reqFirstRowToPaint + reqRowsToPaint - 1));
+ if (getLogger().isLoggable(Level.FINEST)) {
+ getLogger().log(
+ Level.FINEST,
+ "Client wants rows {0}-{1}",
+ new Object[] { reqFirstRowToPaint,
+ (reqFirstRowToPaint + reqRowsToPaint - 1) });
+ }
clientNeedsContentRefresh = true;
}
@@ -3148,9 +3163,9 @@ public class Table extends AbstractSelect implements Action.Container,
target.startTag("prows");
if (!shouldHideAddedRows()) {
- getLogger().finest(
- "Paint rows for add. Index: " + firstIx + ", count: "
- + count + ".");
+ getLogger().log(Level.FINEST,
+ "Paint rows for add. Index: {0}, count: {1}.",
+ new Object[] { firstIx, count });
// Partial row additions bypass the normal caching mechanism.
Object[][] cells = getVisibleCellsInsertIntoCache(firstIx, count);
@@ -3173,9 +3188,9 @@ public class Table extends AbstractSelect implements Action.Container,
indexInRowbuffer, itemId);
}
} else {
- getLogger().finest(
- "Paint rows for remove. Index: " + firstIx + ", count: "
- + count + ".");
+ getLogger().log(Level.FINEST,
+ "Paint rows for remove. Index: {0}, count: {1}.",
+ new Object[] { firstIx, count });
removeRowsFromCacheAndFillBottom(firstIx, count);
target.addAttribute("hide", true);
}
diff --git a/server/src/com/vaadin/ui/TreeTable.java b/server/src/com/vaadin/ui/TreeTable.java
index b5c026c9df..e150db9423 100644
--- a/server/src/com/vaadin/ui/TreeTable.java
+++ b/server/src/com/vaadin/ui/TreeTable.java
@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
import java.util.logging.Logger;
import com.vaadin.data.Collapsible;
@@ -252,9 +253,11 @@ public class TreeTable extends Table implements Hierarchical {
boolean removed = openItems.remove(itemId);
if (!removed) {
openItems.add(itemId);
- getLogger().finest("Item " + itemId + " is now expanded");
+ getLogger().log(Level.FINEST, "Item {0} is now expanded",
+ itemId);
} else {
- getLogger().finest("Item " + itemId + " is now collapsed");
+ getLogger().log(Level.FINEST, "Item {0} is now collapsed",
+ itemId);
}
clearPreorderCache();
}