943,852 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1995
  • Java RSS
May 12th, 2008
0

binding properties

Expand Post »
I have the tutorial running with a entire database displayed.
I am working with the tutorial at:
http://www.netbeans.org/kb/articles/mysql.html

The above tutorial creates a jDesktopAPP. with components bound to the table.

I am trying to add a button (basically).

I am in the process of understanding binding.

the program loads with <list> which is the entire database.

I created a new query (createQuery())

I would like to clear that list and repoulate it with a getResultSet()

As far as binding goes I have never acessed propertiest to set them or accessed properties

to work with them.

Could some one give me some idea where to start?

I have coded in a combobox,textfield,button(@Action)and actionPerformed()
Right now everything compiles yet the query is not created.

Can someone tell me some basic procedures I must follow to utilize persistence?

All this code does is add the above mentioned components and I added an error message to

try to put my question into context.
Thank for your time.



Java Syntax (Toggle Plain Text)
  1. private void searchJComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {
  2.  
  3.  
  4. setSearchItem((String) searchJComboBox1.getSelectedItem());
  5. if (searchJComboBox1.getSelectedItem().equals("by Artist")) {
  6. String holdQuery = searchJComboBox1.getSelectedItem().toString();
  7. setSearchInput(holdQuery);
  8.  
  9. //searchJTextField1.setText(getSearchQuery());
  10. }
  11. if (searchJComboBox1.getSelectedItem().equals("by Song")) {
  12. String holdQuery = searchJComboBox1.getSelectedItem().toString();
  13. setSearchInput(holdQuery);
  14.  
  15. //searchJTextField1.setText(getSearchQuery());
  16. }
  17. }
  18.  
  19. private void searchJButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  20.  
  21.  
  22. if (searchJComboBox1.getSelectedItem().equals("by Artist")) {
  23. String like = searchJTextField1.getText();
  24. setSearchQueryString("SELECT c FROM content c WHERE c.artist LIKE :like");
  25. searchQuery1 = entityManager.createQuery(getSearchQueryString());
  26. searchQuery1.setParameter("like", "%" + searchJTextField1.getText() + "%");
  27. List<Content> List = searchQuery1.getResultList();
  28. }
  29. if (searchJComboBox1.getSelectedItem().equals("by Song")) {
  30. String like = searchJTextField1.getText();
  31. setSearchQueryString("SELECT c FROM content c WHERE c.song LIKE :like");
  32. searchQuery1 = entityManager.createQuery(getSearchQueryString());
  33. searchQuery1.setParameter("like", "%" + searchJTextField1.getText() + "%");
  34. List<Content> List = searchQuery1.getResultList();
  35. }
  36. }
  37.  
  38. @Action
  39. public Task searchSplash() {
  40.  
  41.  
  42. return new SearchSplashTask(getApplication());
  43. }
  44.  
  45. private class SearchSplashTask extends Task {
  46.  
  47. SearchSplashTask(org.jdesktop.application.Application app) {
  48. super(app);
  49. }
  50.  
  51. @SuppressWarnings("unchecked")
  52. @Override
  53. protected Void doInBackground() {
  54. try {
  55. setProgress(0, 0, 4);
  56. setMessage("Rolling back the current changes...");
  57. setProgress(1, 0, 4);
  58. entityManager.getTransaction().rollback();
  59. Thread.sleep(1000L); // remove for real app
  60.  
  61. setProgress(2, 0, 4);
  62.  
  63. setMessage("Starting a new transaction...");
  64. entityManager.getTransaction().begin();
  65. Thread.sleep(500L); // remove for real app
  66.  
  67. setProgress(3, 0, 4);
  68.  
  69. setMessage("Fetching new data...");
  70. java.util.Collection data = searchQuery1.getResultList();
  71.  
  72.  
  73. for (Object entity : data) {
  74. entityManager.refresh(entity);
  75. }
  76.  
  77. Thread.sleep(1300L); // remove for real app
  78.  
  79. setProgress(4, 0, 4);
  80.  
  81. Thread.sleep(150L); // remove for real app
  82.  
  83. list.clear();
  84. //list.addAll(search);
  85. } catch (InterruptedException ignore) {
  86. }
  87. return null;
  88. }
  89.  
  90. @Override
  91. protected void finished() {
  92. setMessage("Done.");
  93. setSaveNeeded(false);
  94. }
  95. }

Java Syntax (Toggle Plain Text)
  1. entityManager = java.beans.Beans.isDesignTime() ? null :
  2.  
  3. javax.persistence.Persistence.createEntityManagerFactory
  4.  
  5. ("splashbookdbPU").createEntityManager();
  6. org.jdesktop.application.ResourceMap resourceMap =
  7.  
  8. org.jdesktop.application.Application.getInstance
  9.  
  10. (splashtemplateda.SplashTemplateDAApp.class).getContext().getResourceMap
  11.  
  12. (SplashTemplateDAView.class);
  13. query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery
  14.  
  15. (resourceMap.getString("query.query")); // NOI18N
  16. list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() :
  17.  
  18. org.jdesktop.observablecollections.ObservableCollections.observableList
  19.  
  20. (query.getResultList());
  21. searchQuery1 = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery
  22.  
  23. (null);


Java Syntax (Toggle Plain Text)
  1.  
  2.  
  3.  
  4. init:
  5. deps-jar:
  6. Copying 1 file to
  7.  
  8. C:\Users\depot\Documents\ceyesuma\program_cache\in_progress\Enterprise\splashbookinprogress
  9.  
  10. \target\SplashTemplateDA\build\classes
  11. compile:
  12. run:
  13. [TopLink Info]: 2008.05.12 05:49:17.417--ServerSession(25094328)--TopLink, version: Oracle
  14.  
  15. TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))
  16. [TopLink Info]: 2008.05.12 05:49:19.438--ServerSession(25094328)--
  17.  
  18. file:/C:/Users/depot/Documents/ceyesuma/program_cache/in_progress/Enterprise/splashbookinpr
  19.  
  20. ogress/target/SplashTemplateDA/build/classes/-splashbookdbPU login successful
  21. May 12, 2008 5:49:20 PM org.jdesktop.application.Application$1 run
  22. SEVERE: Application class splashtemplateda.SplashTemplateDAApp failed to launch
  23. java.lang.IllegalArgumentException: An exception occured while creating a query in
  24.  
  25. EntityManager
  26. at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery
  27.  
  28. (EntityManagerImpl.java:209)
  29. at splashtemplateda.SplashTemplateDAView.initComponents
  30.  
  31. (SplashTemplateDAView.java:360)
  32. at splashtemplateda.SplashTemplateDAView.<init>(SplashTemplateDAView.java:42)
  33. at splashtemplateda.SplashTemplateDAApp.startup(SplashTemplateDAApp.java:19)
  34. at org.jdesktop.application.Application$1.run(Application.java:171)
  35. at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
  36. at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
  37. at java.awt.EventDispatchThread.pumpOneEventForFilters
  38.  
  39. (EventDispatchThread.java:273)
  40. at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
  41. at java.awt.EventDispatchThread.pumpEventsForHierarchy
  42.  
  43. (EventDispatchThread.java:173)
  44. at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
  45. at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
  46. at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
  47. Caused by: Exception [TOPLINK-8002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs
  48.  
  49. (12/06/2007))): oracle.toplink.essentials.exceptions.EJBQLException
  50. Exception Description: General Problem parsing the query [null]. The parser returned the
  51.  
  52. following [null].
  53. Internal Exception: java.lang.NullPointerException
  54. at oracle.toplink.essentials.exceptions.EJBQLException.generalParsingException
  55.  
  56. (EJBQLException.java:140)
  57. at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.buildParserFor
  58.  
  59. (EJBQLParser.java:155)
  60. at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.buildParseTree
  61.  
  62. (EJBQLParser.java:126)
  63. at
  64.  
  65. oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery
  66.  
  67. (EJBQueryImpl.java:215)
  68. at
  69.  
  70. oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery
  71.  
  72. (EJBQueryImpl.java:189)
  73. at
  74.  
  75. oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery
  76.  
  77. (EJBQueryImpl.java:153)
  78. at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>
  79.  
  80. (EJBQueryImpl.java:114)
  81. at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>
  82.  
  83. (EJBQueryImpl.java:99)
  84. at oracle.toplink.essentials.internal.ejb.cmp3.EJBQueryImpl.<init>
  85.  
  86. (EJBQueryImpl.java:86)
  87. at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery
  88.  
  89. (EntityManagerImpl.java:204)
  90. ... 12 more
  91. Caused by: java.lang.NullPointerException
  92. at java.io.StringReader.<init>(StringReader.java:33)
  93. at
  94.  
  95. oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParserBuilder.buildParser
  96.  
  97. (EJBQLParserBuilder.java:61)
  98. at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.buildParserFor
  99.  
  100. (EJBQLParser.java:149)
  101. ... 20 more
  102. Exception in thread "AWT-EventQueue-0" java.lang.Error: Application class
  103.  
  104. splashtemplateda.SplashTemplateDAApp failed to launch
  105. at org.jdesktop.application.Application$1.run(Application.java:177)
  106. at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
  107. at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
  108. at java.awt.EventDispatchThread.pumpOneEventForFilters
  109.  
  110. (EventDispatchThread.java:273)
  111. at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
  112. at java.awt.EventDispatchThread.pumpEventsForHierarchy
  113.  
  114. (EventDispatchThread.java:173)
  115. at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
  116. at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
  117. at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
  118. Caused by: java.lang.IllegalArgumentException: An exception occured while creating a query
  119.  
  120. in EntityManager
  121. at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery
  122.  
  123. (EntityManagerImpl.java:209)
  124. at splashtemplateda.SplashTemplateDAView.initComponents
  125.  
  126. (SplashTemplateDAView.java:360)
  127. at splashtemplateda.SplashTemplateDAView.<init>(SplashTemplateDAView.java:42)
  128. at splashtemplateda.SplashTemplateDAApp.startup(SplashTemplateDAApp.java:19)
  129. at org.jdesktop.application.Application$1.run(Application.java:171)
  130. ... 8 more
  131. Caused by: Exception [TOPLINK-8002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs
  132.  
  133. (12/06/2007))): oracle.toplink.essentials.exceptions.EJBQLException
  134. Exception Description: General Problem parsing the query [null]. The parser returned the
  135.  
  136. following [null].
  137. Internal Exception: java.lang.NullPointerException
  138. at oracle.toplink.essentials.exceptions.EJBQLException.generalParsingException
  139.  
  140. (EJBQLException.java:140)
  141. at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.buildParserFor
  142.  
  143. (EJBQLParser.java:155)
  144. at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.buildParseTree
  145.  
  146. (EJBQLParser.java:126)
  147. at
  148.  
  149. oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery
  150.  
  151. (EJBQueryImpl.java:215)
  152. at
  153.  
  154. oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery
  155.  
  156. (EJBQueryImpl.java:189)
  157. at
  158.  
  159. oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery
  160.  
  161. (EJBQueryImpl.java:153)
  162. at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>
  163.  
  164. (EJBQueryImpl.java:114)
  165. at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>
  166.  
  167. (EJBQueryImpl.java:99)
  168. at oracle.toplink.essentials.internal.ejb.cmp3.EJBQueryImpl.<init>
  169.  
  170. (EJBQueryImpl.java:86)
  171. at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery
  172.  
  173. (EntityManagerImpl.java:204)
  174. ... 12 more
  175. Caused by: java.lang.NullPointerException
  176. at java.io.StringReader.<init>(StringReader.java:33)
  177. at
  178.  
  179. oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParserBuilder.buildParser
  180.  
  181. (EJBQLParserBuilder.java:61)
  182. at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.buildParserFor
  183.  
  184. (EJBQLParser.java:149)
  185. ... 20 more
  186. BUILD SUCCESSFUL (total time: 11 seconds)
Similar Threads
Reputation Points: 7
Solved Threads: 2
Posting Pro
ceyesuma is offline Offline
524 posts
since Aug 2007
May 12th, 2008
0

Re: binding properties

I think I need some of this:

Java Syntax (Toggle Plain Text)
  1. try {
  2. entityManager.getTransaction().commit();
  3. entityManager.getTransaction().begin();
  4. } catch (RollbackException rex) {
  5. rex.printStackTrace();
  6. entityManager.getTransaction().begin();
  7. List<splashtemplateda.Content> merged = new ArrayList<splashtemplateda.Content>(list.size());
  8. for (splashtemplateda.Content c : list) {
  9. merged.add(entityManager.merge(c));
  10. }
  11. list.clear();
  12. list.addAll(merged);
  13. }
  14. return null;
  15. }
If I mastertable.clear()
is it possible that
where merge could hold the getResultSet()
Reputation Points: 7
Solved Threads: 2
Posting Pro
ceyesuma is offline Offline
524 posts
since Aug 2007
May 13th, 2008
0

Re: binding properties

Scratch this one. As usual I made it much more complicated than it had to be. The solution was much easier than I made it
Reputation Points: 7
Solved Threads: 2
Posting Pro
ceyesuma is offline Offline
524 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: display the System.out.print msgs
Next Thread in Java Forum Timeline: Errors writing to file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC