Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

JavaFX and Mongodb

 
Greenhorn
Posts: 13
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I was told to create a desktop application written in java, I chose JavaFX for creating rich UI.

I test my app with dummy data and it works fine, now I have to work with MongoDB which would be a local database in a machine on which the app would be installed. data is streaming and injected into the database within seconds, and every for example 2 seconds I have to query for newer data and show them in the app.

but I don't know how to make a data layer in my app that would communicate with the UI layer. (how to write POJO and DAO classes, make the data layer run in the background and not block the UI thread)

should I use Spring Boot to make my app? I have read that JavaFX and Spring Boot have their own application entry point

I have never got my hands dirty with the Spring framework.

actually it's the first time I'm creating a desktop app and I have no experience in working with MongoDB.

I would appreciate any idea or advice.

Thanks.
 
Rancher
Posts: 214
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer the part I know:

You can create a new Thread for your database access code, if you want. To do this, define a new Thread, and in the argument of the constructor, create a new (or use an existing) Runnable. Runnable is an interface which defines a simple run() method, so you can simply make an anonymous runnable. Make sure to call thread.start(), instead of thread.run()!

When you want to make updates to the UI from the new Thread you made, make sure to call Platform.runLater() or it won't let you do it. No threads besides the UI thread are allowed to update the UI, so Platform.runLater schedules a UI update on the UI thread.

So you can think of the process like this:
- UI element has an event triggered on it (like a button press)
- UI element schedules and launches a new Thread
- UI thread continues unblocked
- Database thread accesses MongoDB
- Database thread schedules a UI modification on the UI thread
- UI thread performs desired modification

POJO are plain old java objects. Essentially it's an object with no real custom behavior, it just has private fields and public getters/setters and the equals/hashcode method implemented. The POJO should be the model object that you want to store in your database. In AWS (which I have experience with) we convert those into a data transfer object which specifies the hash key and sort key, I imagine the DAO for mongodb is similar.
 
Marshal
Posts: 25934
69
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

zeinab sheikhi wrote:actually it's the first time I'm creating a desktop app and I have no experience in working with MongoDB.



Then (in my opinion) it would be a bad idea to add Spring to the list of technologies you have to learn for this project. Stick with Zachary's suggestions, they look like a good outline for you to start working on.

And, welcome to the Ranch!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic