Seeds keeper

Java (11), JavaFX (Tabbed document interface), DBMS Apache Derby

My wife gave me the idea for this app. She grows tomatoes, peppers, and other plants as a hobby. She buys packets of seeds and grows a few plants of each variety. Often, she has leftover seeds, and sometimes we buy a variety but can't plant it that season. We're programmers, not farmers, and we have very little space to grow tomatoes.

So, she accumulated several thousand packets of seeds, and we need to track them on our computer. A spreadsheet is impossible: the plant photos alone take up over 10 GB. A spreadsheet would do the job, but it would be incredibly slow. So my wife came up with a program to track these thousands of packets.

And I need to practice with the database (Apache Derby), try out a development new type of user interface (Tabbed document interface), a new UI development kit (JavaFX), and figure out how to create such a program in a few thousand lines. At the same time, the conciseness of the code must not compromise the user interface and the necessary functionality.

Eclipse was used for development. The project is located here: https://github.com/weekend-game/seedskeeper/ (EN) and here: https://gitflic.ru/project/weekend-game/seedskeeper/ (RU).

How to run the program

Download the repository to your computer. Everything you need for the program is located in the app folder. Navigate to the app folder and run the program by double-clicking the SeedsKeeper.jar file or, if the program doesn't start, double-click the SeedsKeeper.bat file. If the program doesn't start, download and install Java 11 or later and repeat the steps above.

How to open a project in Eclipse

In Eclipse, select "Import..." from the "File" menu. In the window that opens, select "Existing projects into workspace." Navigate to the folder with the downloaded repository and click "Finish." The project will open in Eclipse. In the Package Explorer (on the left side of the screen), double-click the SeedKeeper.java file. The file will open for editing (in the center of the screen). Run the program by pressing Ctrl+F11 or using your preferred method for running programs in Eclipse.

I should note that this project will require several third-party libraries. That's why I decided to create a Maven project rather than just an Eclipse project. The project is already created, so you don't need to create anything else, unless you're working on a new project. But I'll describe it just in case.

How to Create a Maven Project in Eclipse

Select File – New – Maven Project from the menu. The "New Maven Project" window will appear.

Check the "Create a simple project" checkbox.

Uncheck the "Use default Workspace location" checkbox and specify the project folder in the "Location" field. For example: C:\Dropbox\Weekend game\SeedsKeeper. Click "Next".

On the next page, specify:

	Artifact Id: SeedsKeeper
	Version: 0.1.0
	Packaging: jar
	Name: SeedsKeeper
	Description: Accounting of seeds

Click "Finish".

A SeedsKeeper folder will be created in the C:\Dropbox\Weekend game\ folder, and the project files will be placed there.

Eclipse creates the project for Java 8. At least, that's how it worked for me. To use Java 11, open the project properties window and, on the "Java Build Path" page, in the "Libraries" tab, remove the "JRE System Library [JavaSE-1.8]" line. On the right, click the Add library... button, select JRE System Library, click the "Execution environment" radio button, and select the desired version of "Java (11.0.10)." Then, add all the necessary dependencies to the pom.xml file.

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11.0.2</version>>
        </dependency>

        ...

    </dependencies>
DBMS

Choosing a DBMS

When choosing a DBMS, I considered the following:

  • The DBMS should be able to be embedded into the application. Launching any additional programs before using my application would somewhat detract from the user's enjoyment of viewing their seed collection.
  • My program is written in Java, and the DBMS should be written in Java. Of course, you can make anything work with Java, but I don't want to waste time on that.
  • I know SQL and would like to use it, not anything else, which means the DBMS should be relational.
  • I should use the first DBMS I come across that meets my first three requirements, since my goal is to create a crop tracking program, not to study the current state of the DBMS market.

I chose Apache Derby. A large amount of high-quality documentation on this DBMS can be found on the Derby website. But to create a seed tracking application, I needed the following.

Installing Derby requires:

  • Download the DBMS files and place them in a folder. I'm running Windows 10 and using Java 11, so I chose version 10.15.2.0, which I downloaded and placed in the C:\Programs\Derby\ folder.
  • Create the DERBY_HOME system variable with the path to the DBMS. I used C:\Programs\Derby.
  • Add %DERBY_HOME%\bin to the PATH system variable.

Creating and Working with a Database

  • Run a command prompt in the folder where you want to store the database. The repository includes the dos.bat file for this.
  • Run the Derby ij utility. To do this, enter: java -jar "%DERBY_HOME%/lib/derbyrun.jar" ij
  • Create or connect to the db database. To do this, enter: CONNECT 'jdbc:derby:db;user=user;create=true';
  • You can enter any SQL commands here, and they will be executed by the DBMS. For example, you can run the script for creating database tables with the command: RUN 'create_tables.sql'
  • Exit the Derby ij utility. To do this, enter: EXIT;

Don't forget to include the ; after each command.

The application's interaction with the database will be based on JDBC. I don't see any point in using an ORM, such as Hibernate, for such a simple application that will use no more than a dozen tables.