Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-9839

Using try-with-resources with JDBC objects

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: Trunk
    • Fix Version/s: None
    • Component/s: framework
    • Labels:
      None

      Description

      Proposal to use try with resources for SQL objects like ResultSet and other objects. SQL classes have AutoCloseable interface.

      1. OFBIZ-9839.patch
        27 kB
        Pradhan Yash Sharma
      2. OFBIZ-9839.patch
        10 kB
        Pradhan Yash Sharma

        Issue Links

          Activity

          Hide
          jacques.le.roux Jacques Le Roux added a comment - - edited

          I'm all for it, please go Yash

          Show
          jacques.le.roux Jacques Le Roux added a comment - - edited I'm all for it, please go Yash
          Hide
          PradhanYashSharma Pradhan Yash Sharma added a comment -

          Attaching the first Patch.

          Show
          PradhanYashSharma Pradhan Yash Sharma added a comment - Attaching the first Patch.
          Hide
          jacques.le.roux Jacques Le Roux added a comment - - edited

          Thanks Yash,

          Your 1st patch is trunk at revision: 1812104.

          Show
          jacques.le.roux Jacques Le Roux added a comment - - edited Thanks Yash, Your 1st patch is trunk at revision: 1812104.
          Hide
          PradhanYashSharma Pradhan Yash Sharma added a comment -

          Attaching the second Patch file.

          Show
          PradhanYashSharma Pradhan Yash Sharma added a comment - Attaching the second Patch file.
          Hide
          PradhanYashSharma Pradhan Yash Sharma added a comment -

          Hello,
          While I was traversing the code found that these four (getTableNames, getColumnInfo, getIndexInfo, getReferenceInfo) methods are complicated and need refactoring. Proper resource handling is required and but due to its complex nature I cannot do it now, I am working in that direction.

          Show
          PradhanYashSharma Pradhan Yash Sharma added a comment - Hello, While I was traversing the code found that these four (getTableNames, getColumnInfo, getIndexInfo, getReferenceInfo) methods are complicated and need refactoring. Proper resource handling is required and but due to its complex nature I cannot do it now, I am working in that direction.
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Hi Yash,

          Did the tests pass at your end? Because here I get that:

          C:\projectsASF\ofbiz>svn up && g cleanAll eclipse loadAll testIntegration
          [...]
          2017-10-17 19:03:00,982 |main                 |EntitySaxReader               |E| An error occurred saving the data, rolling back transaction (true)
          org.xml.sax.SAXException: Cannot store value with incomplete primary key with more than 1 primary key field: [GenericEntity:SecurityGroupPermission][groupId,SUPER(java.lang.String)][permissionId,ASSETMAINT_AD
          MIN(java.lang.String)]
           at org.apache.ofbiz.entity.util.EntitySaxReader.endElement(EntitySaxReader.java:397) ~[ofbiz.jar:?]
              at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
              at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
              at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
                  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
                  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
                  at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
           at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
           at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
            at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
                  at javax.xml.parsers.SAXParser.parse(SAXParser.java:195) ~[?:1.8.0_112]
                  at org.apache.ofbiz.entity.util.EntitySaxReader.parse(EntitySaxReader.java:231) [ofbiz.jar:?]
            at org.apache.ofbiz.entity.util.EntitySaxReader.parse(EntitySaxReader.java:205) [ofbiz.jar:?]
            at org.apache.ofbiz.entity.util.EntityDataLoader.loadData(EntityDataLoader.java:263) [ofbiz.jar:?]
               at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.loadData(EntityDataLoadContainer.java:436) [ofbiz.jar:?]
              at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.loadDataForDelegator(EntityDataLoadContainer.java:183) [ofbiz.jar:?]
                  at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.init(EntityDataLoadContainer.java:115) [ofbiz.jar:?]
                  at org.apache.ofbiz.base.container.ContainerLoader.loadContainer(ContainerLoader.java:135) [ofbiz.jar:?]
                 at org.apache.ofbiz.base.container.ContainerLoader.loadContainersFromConfigurations(ContainerLoader.java:100) [ofbiz.jar:?]
              at org.apache.ofbiz.base.container.ContainerLoader.load(ContainerLoader.java:70) [ofbiz.jar:?]
           at org.apache.ofbiz.base.start.StartupControlPanel.loadStartupLoaders(StartupControlPanel.java:229) [ofbiz.jar:?]
                at org.apache.ofbiz.base.start.StartupControlPanel.start(StartupControlPanel.java:71) [ofbiz.jar:?]
              at org.apache.ofbiz.base.start.Start.main(Start.java:85) [ofbiz.jar:?]
          2017-10-17 19:03:00,991 |main                 |TransactionUtil               |I| Transaction rolled back
          org.apache.ofbiz.base.start.StartupException: Cannot init() dataload-container (org.apache.ofbiz.entity.GenericEntityException: [loadData]: Error loading XML Resource "file:/C:/projectsASF/ofbiz/plugins/asset
          maint/data/AssetMaintSecurityPermissionSeedData.xml"; Error was: A transaction error occurred reading data (A transaction error occurred reading data) ([loadData]: Error loading XML Resource "file:/C:/project
          sASF/ofbiz/plugins/assetmaint/data/AssetMaintSecurityPermissionSeedData.xml"; Error was: A transaction error occurred reading data (A transaction error occurred reading data)))
                  at org.apache.ofbiz.base.container.ContainerLoader.loadContainer(ContainerLoader.java:137)
                  at org.apache.ofbiz.base.container.ContainerLoader.loadContainersFromConfigurations(ContainerLoader.java:100)
                  at org.apache.ofbiz.base.container.ContainerLoader.load(ContainerLoader.java:70)
                  at org.apache.ofbiz.base.start.StartupControlPanel.loadStartupLoaders(StartupControlPanel.java:229)
                  at org.apache.ofbiz.base.start.StartupControlPanel.start(StartupControlPanel.java:71)
                  at org.apache.ofbiz.base.start.Start.main(Start.java:85)
          Caused by: org.apache.ofbiz.base.container.ContainerException: org.apache.ofbiz.entity.GenericEntityException: [loadData]: Error loading XML Resource "file:/C:/projectsASF/ofbiz/plugins/assetmaint/data/AssetM
          aintSecurityPermissionSeedData.xml"; Error was: A transaction error occurred reading data (A transaction error occurred reading data) ([loadData]: Error loading XML Resource "file:/C:/projectsASF/ofbiz/plugin
          s/assetmaint/data/AssetMaintSecurityPermissionSeedData.xml"; Error was: A transaction error occurred reading data (A transaction error occurred reading data))
                  at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.loadData(EntityDataLoadContainer.java:444)
                  at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.loadDataForDelegator(EntityDataLoadContainer.java:183)
                  at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.init(EntityDataLoadContainer.java:115)
                  at org.apache.ofbiz.base.container.ContainerLoader.loadContainer(ContainerLoader.java:135)
                  ... 5 more
          Caused by: org.apache.ofbiz.entity.GenericEntityException: [loadData]: Error loading XML Resource "file:/C:/projectsASF/ofbiz/plugins/assetmaint/data/AssetMaintSecurityPermissionSeedData.xml"; Error was: A tr
          ansaction error occurred reading data (A transaction error occurred reading data)
                  at org.apache.ofbiz.entity.util.EntityDataLoader.loadData(EntityDataLoader.java:270)
                  at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.loadData(EntityDataLoadContainer.java:436)
                  ... 8 more
          Caused by: org.xml.sax.SAXException: A transaction error occurred reading data
          org.xml.sax.SAXException: Cannot store value with incomplete primary key with more than 1 primary key field: [GenericEntity:SecurityGroupPermission][groupId,SUPER(java.lang.String)][permissionId,ASSETMAINT_AD
          MIN(java.lang.String)]
                  at org.apache.ofbiz.entity.util.EntitySaxReader.parse(EntitySaxReader.java:246)
                  at org.apache.ofbiz.entity.util.EntitySaxReader.parse(EntitySaxReader.java:205)
                  at org.apache.ofbiz.entity.util.EntityDataLoader.loadData(EntityDataLoader.java:263)
                  ... 9 more
          Caused by: org.xml.sax.SAXException: Cannot store value with incomplete primary key with more than 1 primary key field: [GenericEntity:SecurityGroupPermission][groupId,SUPER(java.lang.String)][permissionId,AS
          SETMAINT_ADMIN(java.lang.String)]
                  at org.apache.ofbiz.entity.util.EntitySaxReader.endElement(EntitySaxReader.java:397)
                  at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
                  at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
                  at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
                  at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
                  at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
                  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
                  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
                  at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
                  at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
                  at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
                  at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
                  at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
                  at org.apache.ofbiz.entity.util.EntitySaxReader.parse(EntitySaxReader.java:231)
                  ... 11 more
          :ofbiz --load-data FAILED
          
          FAILURE: Build failed with an exception.
          
          * What went wrong:
          Execution failed for task ':ofbiz --load-data'.
          > Process 'command 'C:\Program Files\Java\jdk1.8.0_112\bin\java.exe'' finished with non-zero exit value 1
          
          * Try:
          Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
          
          BUILD FAILED
          
          Total time: 2 mins 38.409 secs
          
          Show
          jacques.le.roux Jacques Le Roux added a comment - Hi Yash, Did the tests pass at your end? Because here I get that: C:\projectsASF\ofbiz>svn up && g cleanAll eclipse loadAll testIntegration [...] 2017-10-17 19:03:00,982 |main |EntitySaxReader |E| An error occurred saving the data, rolling back transaction ( true ) org.xml.sax.SAXException: Cannot store value with incomplete primary key with more than 1 primary key field: [GenericEntity:SecurityGroupPermission][groupId,SUPER(java.lang. String )][permissionId,ASSETMAINT_AD MIN(java.lang. String )] at org.apache.ofbiz.entity.util.EntitySaxReader.endElement(EntitySaxReader.java:397) ~[ofbiz.jar:?] at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) ~[xercesImpl-2.9.1.jar:?] at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source) ~[xercesImpl-2.9.1.jar:?] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source) ~[xercesImpl-2.9.1.jar:?] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) ~[xercesImpl-2.9.1.jar:?] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[xercesImpl-2.9.1.jar:?] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?] at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?] at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?] at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source) ~[xercesImpl-2.9.1.jar:?] at javax.xml.parsers.SAXParser.parse(SAXParser.java:195) ~[?:1.8.0_112] at org.apache.ofbiz.entity.util.EntitySaxReader.parse(EntitySaxReader.java:231) [ofbiz.jar:?] at org.apache.ofbiz.entity.util.EntitySaxReader.parse(EntitySaxReader.java:205) [ofbiz.jar:?] at org.apache.ofbiz.entity.util.EntityDataLoader.loadData(EntityDataLoader.java:263) [ofbiz.jar:?] at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.loadData(EntityDataLoadContainer.java:436) [ofbiz.jar:?] at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.loadDataForDelegator(EntityDataLoadContainer.java:183) [ofbiz.jar:?] at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.init(EntityDataLoadContainer.java:115) [ofbiz.jar:?] at org.apache.ofbiz.base.container.ContainerLoader.loadContainer(ContainerLoader.java:135) [ofbiz.jar:?] at org.apache.ofbiz.base.container.ContainerLoader.loadContainersFromConfigurations(ContainerLoader.java:100) [ofbiz.jar:?] at org.apache.ofbiz.base.container.ContainerLoader.load(ContainerLoader.java:70) [ofbiz.jar:?] at org.apache.ofbiz.base.start.StartupControlPanel.loadStartupLoaders(StartupControlPanel.java:229) [ofbiz.jar:?] at org.apache.ofbiz.base.start.StartupControlPanel.start(StartupControlPanel.java:71) [ofbiz.jar:?] at org.apache.ofbiz.base.start.Start.main(Start.java:85) [ofbiz.jar:?] 2017-10-17 19:03:00,991 |main |TransactionUtil |I| Transaction rolled back org.apache.ofbiz.base.start.StartupException: Cannot init() dataload-container (org.apache.ofbiz.entity.GenericEntityException: [loadData]: Error loading XML Resource "file:/C:/projectsASF/ofbiz/plugins/asset maint/data/AssetMaintSecurityPermissionSeedData.xml "; Error was: A transaction error occurred reading data (A transaction error occurred reading data) ([loadData]: Error loading XML Resource " file:/C:/project sASF/ofbiz/plugins/assetmaint/data/AssetMaintSecurityPermissionSeedData.xml"; Error was: A transaction error occurred reading data (A transaction error occurred reading data))) at org.apache.ofbiz.base.container.ContainerLoader.loadContainer(ContainerLoader.java:137) at org.apache.ofbiz.base.container.ContainerLoader.loadContainersFromConfigurations(ContainerLoader.java:100) at org.apache.ofbiz.base.container.ContainerLoader.load(ContainerLoader.java:70) at org.apache.ofbiz.base.start.StartupControlPanel.loadStartupLoaders(StartupControlPanel.java:229) at org.apache.ofbiz.base.start.StartupControlPanel.start(StartupControlPanel.java:71) at org.apache.ofbiz.base.start.Start.main(Start.java:85) Caused by: org.apache.ofbiz.base.container.ContainerException: org.apache.ofbiz.entity.GenericEntityException: [loadData]: Error loading XML Resource "file:/C:/projectsASF/ofbiz/plugins/assetmaint/data/AssetM aintSecurityPermissionSeedData.xml "; Error was: A transaction error occurred reading data (A transaction error occurred reading data) ([loadData]: Error loading XML Resource " file:/C:/projectsASF/ofbiz/plugin s/assetmaint/data/AssetMaintSecurityPermissionSeedData.xml"; Error was: A transaction error occurred reading data (A transaction error occurred reading data)) at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.loadData(EntityDataLoadContainer.java:444) at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.loadDataForDelegator(EntityDataLoadContainer.java:183) at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.init(EntityDataLoadContainer.java:115) at org.apache.ofbiz.base.container.ContainerLoader.loadContainer(ContainerLoader.java:135) ... 5 more Caused by: org.apache.ofbiz.entity.GenericEntityException: [loadData]: Error loading XML Resource "file:/C:/projectsASF/ofbiz/plugins/assetmaint/data/AssetMaintSecurityPermissionSeedData.xml" ; Error was: A tr ansaction error occurred reading data (A transaction error occurred reading data) at org.apache.ofbiz.entity.util.EntityDataLoader.loadData(EntityDataLoader.java:270) at org.apache.ofbiz.entityext.data.EntityDataLoadContainer.loadData(EntityDataLoadContainer.java:436) ... 8 more Caused by: org.xml.sax.SAXException: A transaction error occurred reading data org.xml.sax.SAXException: Cannot store value with incomplete primary key with more than 1 primary key field: [GenericEntity:SecurityGroupPermission][groupId,SUPER(java.lang. String )][permissionId,ASSETMAINT_AD MIN(java.lang. String )] at org.apache.ofbiz.entity.util.EntitySaxReader.parse(EntitySaxReader.java:246) at org.apache.ofbiz.entity.util.EntitySaxReader.parse(EntitySaxReader.java:205) at org.apache.ofbiz.entity.util.EntityDataLoader.loadData(EntityDataLoader.java:263) ... 9 more Caused by: org.xml.sax.SAXException: Cannot store value with incomplete primary key with more than 1 primary key field: [GenericEntity:SecurityGroupPermission][groupId,SUPER(java.lang. String )][permissionId,AS SETMAINT_ADMIN(java.lang. String )] at org.apache.ofbiz.entity.util.EntitySaxReader.endElement(EntitySaxReader.java:397) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source) at javax.xml.parsers.SAXParser.parse(SAXParser.java:195) at org.apache.ofbiz.entity.util.EntitySaxReader.parse(EntitySaxReader.java:231) ... 11 more :ofbiz --load-data FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':ofbiz --load-data'. > Process 'command 'C:\Program Files\Java\jdk1.8.0_112\bin\java.exe'' finished with non-zero exit value 1 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 2 mins 38.409 secs
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Yash, OK forget it, it's not related with your changes. I can reproduce locally w/o your changes.

          Show
          jacques.le.roux Jacques Le Roux added a comment - Yash, OK forget it, it's not related with your changes. I can reproduce locally w/o your changes.
          Hide
          jacques.le.roux Jacques Le Roux added a comment - - edited

          Thanks Yash,

          Your 2nd patch is trunk at revision: 1812466

          Show
          jacques.le.roux Jacques Le Roux added a comment - - edited Thanks Yash, Your 2nd patch is trunk at revision: 1812466
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Hi Yash,

          While I was traversing the code found that these four (getTableNames, getColumnInfo, getIndexInfo, getReferenceInfo) methods are complicated and need refactoring. Proper resource handling is required and but due to its complex nature I cannot do it now, I am working in that direction.

          Please create another Jira for the refactoring, thanks

          Show
          jacques.le.roux Jacques Le Roux added a comment - Hi Yash, While I was traversing the code found that these four (getTableNames, getColumnInfo, getIndexInfo, getReferenceInfo) methods are complicated and need refactoring. Proper resource handling is required and but due to its complex nature I cannot do it now, I am working in that direction. Please create another Jira for the refactoring, thanks

            People

            • Assignee:
              PradhanYashSharma Pradhan Yash Sharma
              Reporter:
              PradhanYashSharma Pradhan Yash Sharma
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Development