# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /home/matthias/NetBeansProjects/main-golden # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: db.dataview/src/org/netbeans/modules/db/dataview/table/ResultSetCellRenderer.java --- db.dataview/src/org/netbeans/modules/db/dataview/table/ResultSetCellRenderer.java +++ db.dataview/src/org/netbeans/modules/db/dataview/table/ResultSetCellRenderer.java @@ -58,6 +58,7 @@ import javax.swing.table.TableCellRenderer; import org.jdesktop.swingx.renderer.*; import org.netbeans.modules.db.dataview.util.DataViewUtils; +import org.netbeans.modules.db.dataview.util.LobHelper; import org.netbeans.modules.db.dataview.util.TimeType; import org.netbeans.modules.db.dataview.util.TimestampType; @@ -227,24 +228,9 @@ if (!(value instanceof Blob)) { throw new IllegalArgumentException("BlobCellRenderer can only be used for Blobs"); } - try { - Long size = ((Blob) value).length(); - StringBuilder stringValue = new StringBuilder(); - stringValue.append(""); - return super.getTableCellRendererComponent(table, stringValue.toString(), isSelected, hasFocus, row, column); - } catch (SQLException ex) { - return super.getTableCellRendererComponent(table, "", isSelected, hasFocus, row, column); } - } -} class ClobCellRenderer extends CellFocusCustomRenderer { @Override @@ -254,41 +240,11 @@ "ClobCellRenderer can only be used for Clobs"); //NOI18N } Clob clobValue = (Clob) value; - StringBuilder contentPart = new StringBuilder(); - StringBuilder clobDescription = new StringBuilder(""); //NOI18N - - try { - long size = clobValue.length(); - long retrievalCount = Math.min(size, 255); - String sampleContent = clobValue.getSubString(1, (int) retrievalCount); - contentPart.append(sampleContent.replaceAll("[\n\r]+", " "));//NOI18N - if (size > 255) { - contentPart.append(" [...]"); //NOI18N - } - } catch (SQLException ex) { - Logger.getLogger(this.getClass().getName()).log(Level.INFO, - "Failed to retrieve CLOB content", //NOI18N - ex); - contentPart.append(clobDescription.toString()); - } Component renderer = super.getTableCellRendererComponent(table, - contentPart.toString(), isSelected, hasFocus, row, column); + LobHelper.clobToString(clobValue), isSelected, hasFocus, row, column); if (renderer instanceof JComponent) { - ((JComponent) renderer).setToolTipText(clobDescription.toString()); + ((JComponent) renderer).setToolTipText(LobHelper.clobToDescription(clobValue)); } return renderer; } Index: db.dataview/src/org/netbeans/modules/db/dataview/table/StringFallbackRowSorter.java --- db.dataview/src/org/netbeans/modules/db/dataview/table/StringFallbackRowSorter.java +++ db.dataview/src/org/netbeans/modules/db/dataview/table/StringFallbackRowSorter.java @@ -41,9 +41,12 @@ */ package org.netbeans.modules.db.dataview.table; +import java.sql.Blob; +import java.sql.Clob; import java.util.Comparator; import javax.swing.table.TableModel; import org.jdesktop.swingx.sort.TableSortController; +import org.netbeans.modules.db.dataview.util.LobHelper; /** * RowSorter that falls back to comparing values by their string representation @@ -54,20 +57,35 @@ * string and date) */ public class StringFallbackRowSorter extends TableSortController { - - public StringFallbackRowSorter() { - } - public StringFallbackRowSorter(TableModel model) { super(model); } @Override public Comparator getComparator(int column) { - return new StringFallBackComparator(super.getComparator(column)); + Comparator superComparator = super.getComparator(0); + Class klass = getModel().getColumnClass(column); + if (Blob.class.isAssignableFrom(klass)) { + superComparator = LobHelper.getBlobComparator(); + } else if (Clob.class.isAssignableFrom(klass)) { + superComparator = LobHelper.getClobComparator(); } + return new StringFallBackComparator(superComparator); } + @Override + protected boolean useToString(int column) { + Class klass = getModel().getColumnClass(column); + if (Blob.class.isAssignableFrom(klass) + || Clob.class.isAssignableFrom(klass)) { + return false; + } + return super.useToString(column); + } + + +} + \ No newline at end of file class StringFallBackComparator implements Comparator { private Comparator delegate; Index: db.dataview/src/org/netbeans/modules/db/dataview/table/SuperPatternFilter.java --- db.dataview/src/org/netbeans/modules/db/dataview/table/SuperPatternFilter.java +++ db.dataview/src/org/netbeans/modules/db/dataview/table/SuperPatternFilter.java @@ -45,10 +45,13 @@ * * @author ahimanikya */ +import java.sql.Blob; +import java.sql.Clob; import java.util.regex.Pattern; import javax.swing.RowFilter; import javax.swing.table.TableModel; import static org.netbeans.modules.db.dataview.table.SuperPatternFilter.MODE.LITERAL_FIND; +import org.netbeans.modules.db.dataview.util.LobHelper; public class SuperPatternFilter extends RowFilter { @@ -98,14 +101,21 @@ } public boolean include(RowFilter.Entry entry) { - return testValue(entry.getValue(col)); + return testValue(entry.getStringValue(col)); } protected boolean testValue(final Object value) { if (value == null) { return false; } - final String valueStr = value.toString(); + final String valueStr; + if (value instanceof Blob) { + valueStr = LobHelper.blobToString((Blob) value); + } else if (value instanceof Clob) { + valueStr = LobHelper.clobToString((Clob) value); + } else { + valueStr = value.toString(); + } switch (mode) { case LITERAL_FIND: if (filterStr == null || filterStr.length() == 0) { @@ -127,4 +137,6 @@ throw new RuntimeException(UNKOWN_MODE); } } + + } Index: db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/BlobFieldTableCellEditor.java --- db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/BlobFieldTableCellEditor.java +++ db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/BlobFieldTableCellEditor.java @@ -60,6 +60,7 @@ import javax.swing.table.TableCellEditor; import org.netbeans.api.progress.ProgressUtils; import org.netbeans.modules.db.dataview.util.FileBackedBlob; +import org.netbeans.modules.db.dataview.util.LobHelper; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.cookies.OpenCookie; @@ -165,23 +166,8 @@ if (currentValue != null) { saveContentMenuItem.setEnabled(true); miOpenImageMenuItem.setEnabled(true); - try { - long size = currentValue.length(); - StringBuilder stringValue = new StringBuilder(); - stringValue.append(""); - button.setText(stringValue.toString()); - } catch (SQLException ex) { - button.setText(""); - } - } else { saveContentMenuItem.setEnabled(false); miOpenImageMenuItem.setEnabled(false); button.setText(""); Index: db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/ClobFieldTableCellEditor.java --- db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/ClobFieldTableCellEditor.java +++ db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/ClobFieldTableCellEditor.java @@ -57,6 +57,7 @@ import javax.swing.table.TableCellEditor; import org.netbeans.api.progress.ProgressUtils; import org.netbeans.modules.db.dataview.util.FileBackedClob; +import org.netbeans.modules.db.dataview.util.LobHelper; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.util.Exceptions; @@ -190,23 +191,8 @@ boolean editable = table.getModel().isCellEditable(currentModelRow, currentModelColumn); if (currentValue != null) { saveContentMenuItem.setEnabled(true); - try { - long size = currentValue.length(); - StringBuilder stringValue = new StringBuilder(); - stringValue.append(""); - button.setText(stringValue.toString()); - } catch (SQLException ex) { - button.setText(""); - } - } else { saveContentMenuItem.setEnabled(false); button.setText(""); } Index: db.dataview/src/org/netbeans/modules/db/dataview/util/LobHelper.java --- db.dataview/src/org/netbeans/modules/db/dataview/util/LobHelper.java +++ db.dataview/src/org/netbeans/modules/db/dataview/util/LobHelper.java @@ -0,0 +1,199 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2014 Sun Microsystems, Inc. + */ +package org.netbeans.modules.db.dataview.util; + +import java.sql.Blob; +import java.sql.Clob; +import java.sql.SQLException; +import java.util.Comparator; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.jdesktop.swingx.renderer.StringValue; + +public class LobHelper { + private static final Logger LOG = Logger.getLogger(LobHelper.class.getName()); + + private static final Comparator blobComparator + = new Comparator() { + public int compare(Blob o1, Blob o2) { + if (o1 == null && o2 == null) { + return 0; + } + if (o1 == null) { + return -1; + } + if (o2 == null) { + return 1; + } + try { + return Long.compare(o1.length(), o2.length()); + } catch (SQLException ex) { + return 0; + } + } + }; + + private static final Comparator clobComparator + = new Comparator() { + public int compare(Clob o1, Clob o2) { + if (o1 == null && o2 == null) { + return 0; + } + if (o1 == null) { + return -1; + } + if (o2 == null) { + return 1; + } + String s1 = clobToString(o1); + String s2 = clobToString(o2); + return s1.compareToIgnoreCase(s2); + } + }; + + private static final StringValue blobConverter + = new StringValue() { + + @Override + public String getString(Object o) { + if(o == null) { + return ""; + } else if (o instanceof Blob) { + return blobToString((Blob) o); + } else { + return ""; + } + } + + }; + + private static final StringValue clobConverter + = new StringValue() { + + @Override + public String getString(Object o) { + if (o == null) { + return ""; + } else if (o instanceof Clob) { + return clobToString((Clob) o); + } else { + return ""; + } + } + + }; + + public static Comparator getBlobComparator() { + return blobComparator; + } + + public static Comparator getClobComparator() { + return clobComparator; + } + + public static StringValue getBlobConverter() { + return blobConverter; + } + + public static StringValue getClobConverter() { + return clobConverter; + } + + public static String blobToString(Blob blob) { + try { + Long size = blob.length(); + StringBuilder stringValue = new StringBuilder(); + stringValue.append(""); + return stringValue.toString(); + } catch (SQLException ex) { + return ""; + } + } + + public static String clobToString(Clob clobValue) { + StringBuilder contentPart = new StringBuilder(); + try { + long size = clobValue.length(); + long retrievalCount = Math.min(size, 255); + String sampleContent = clobValue.getSubString(1, (int) retrievalCount); + contentPart.append(sampleContent.replaceAll("[\n\r]+", " "));//NOI18N + if (size > 255) { + contentPart.append(" [...]"); //NOI18N + } + return contentPart.toString(); + } catch (SQLException ex) { + LOG.log(Level.INFO, + "Failed to retrieve CLOB content", //NOI18N + ex); + return clobToDescription(clobValue); + } + } + + public static String clobToDescription(Clob clobValue) { + StringBuilder clobDescription = new StringBuilder(""); + + return clobDescription.toString(); + } +}