You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/03/26 10:01:40 UTC

[GitHub] [netbeans] matthiasblaesing commented on a change in pull request #3868: SQL History loss: Reimplement atomatic saving by writing to tempfile and moving to target

matthiasblaesing commented on a change in pull request #3868:
URL: https://github.com/apache/netbeans/pull/3868#discussion_r835746162



##########
File path: ide/db.core/src/org/netbeans/modules/db/sql/history/SQLHistoryManager.java
##########
@@ -205,40 +209,34 @@ void removePropertyChangeListener(PropertyChangeListener listener) {
         @Override
         public void run() {
             try {
-                final FileObject targetFile = getHistoryRoot(true);
-                targetFile.getFileSystem().
-                        runAtomicAction(new FileSystem.AtomicAction() {
-                    @Override
-                    public void run() throws IOException {
-                        ;
-                        try (OutputStream os = targetFile.getOutputStream()) {
-                            XMLStreamWriter xsw = XMLOutputFactory
-                                    .newInstance()
-                                    .createXMLStreamWriter(os);
-                            
-                            xsw.writeStartDocument();
-                            xsw.writeCharacters(CONTENT_NEWLINE);
-                            xsw.writeStartElement(TAG_HISTORY);
-                            xsw.writeCharacters(CONTENT_NEWLINE);
-                            for(SQLHistoryEntry sqe: sqlHistory) {
-                                xsw.writeStartElement(TAG_SQL);
-                                xsw.writeAttribute(ATTR_DATE, sqe.getDateXMLVariant());
-                                xsw.writeAttribute(ATTR_URL, sqe.getUrl());
-                                xsw.writeCharacters(sqe.getSql());
-                                xsw.writeEndElement();
-                                xsw.writeCharacters(CONTENT_NEWLINE);
-                            }
-                            xsw.writeEndElement();
-                            xsw.flush();
-                            xsw.close();
-                        } catch (IOException | XMLStreamException ex) {
-                            LOGGER.log(Level.INFO, ex.getMessage(), ex);
-                        } finally {
-                            PROPERTY_CHANGE_SUPPORT.firePropertyChange(
-                                    PROP_SAVED, null, null);
-                        }
+                final FileObject targetFileObject = getHistoryRoot(true);
+                final Path targetFile = FileUtil.toFile(targetFileObject).toPath();
+                final Path tempfile = Files.createTempFile(targetFile.getParent(), SQL_HISTORY_BASE, SQL_HISTORY_EXT);
+                try ( OutputStream os = Files.newOutputStream(tempfile)) {
+                    XMLStreamWriter xsw = XMLOutputFactory
+                            .newInstance()
+                            .createXMLStreamWriter(os);
+
+                    xsw.writeStartDocument();
+                    xsw.writeCharacters(CONTENT_NEWLINE);
+                    xsw.writeStartElement(TAG_HISTORY);
+                    xsw.writeCharacters(CONTENT_NEWLINE);
+                    for (SQLHistoryEntry sqe : sqlHistory) {
+                        xsw.writeStartElement(TAG_SQL);
+                        xsw.writeAttribute(ATTR_DATE, sqe.getDateXMLVariant());
+                        xsw.writeAttribute(ATTR_URL, sqe.getUrl());
+                        xsw.writeCharacters(sqe.getSql());
+                        xsw.writeEndElement();
+                        xsw.writeCharacters(CONTENT_NEWLINE);
                     }
-                });
+                    xsw.writeEndElement();
+                    xsw.flush();
+                    xsw.close();
+                } catch (IOException | XMLStreamException ex) {
+                    LOGGER.log(Level.INFO, ex.getMessage(), ex);

Review comment:
       Valid point - indeed this catch is invalid and should not be there. I pushed an update (new commit, I intent to squash before merge).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists