Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confgure Speedment without UI?

I just found out about Speedment, a Java 8 Stream-based OR/M library, and have to say that I love the idea of it. No more crazy configurations or spending time sifting through 900 pages of Hibernation docs to find the right way to annotate my classes: Speedment just reads your database, generates Java classes for you and gives you a stream-based API to run DDL statements against them. Wicked cool.

However, the one big deal breaker is that it seems like you have to use the Speedment UI for configuring your DB connection. Furthermore, the docs don't seem to specify how you can do things like:

  • Specify which tables you want code generated against (maybe there's a few tables inside a database that you don't want models generated for
  • Execute stored procedures
  • Configure in-memory caches

etc. Looking on GitHub I can't seem to find how the code is wired together from the UI to produce a configuration object. Just wondering if there's a way to configure Speedment sans UI (perhaps via JSON or YAML), and if so, what configurations are available.

like image 974
smeeb Avatar asked Feb 12 '17 01:02

smeeb


1 Answers

It is possible to configure Speedment without the UI, but it requires some tinkering. Basically, to generate code from a database, you need to manually create a speedment.json-file and specify which schema to generate from manually.

  1. Create a new Maven Project (a pom.xml-file and a src/main/java-directory).
  2. Create a file /src/main/json/speedment.json
  3. Enter the following:
{
  "config" : {
    "name" : "yourproject",
    "packageName" : "com.yourcompany",
    "packageLocation" : "src/main/java/",
    "dbmses" : [{
      "name"      : "db0",
      "typeName"  : "MySQL",
      "ipAddress" : "127.0.0.1",
      "port"      : 3306,
      "schemas" : [{
        "name" : "your_db_schema"
      }]
    }]
  }
}
  1. Run the Maven goal: mvn speedment:reload -Ddbms.username=root -Dbms.password=password (with the credentials for your database)

  2. Finally, run the Maven goal: mvn speedment:generate

The first goal connects to the database and fills in any missing configuration details in the .json file. The second goal generates .java-code.

To disable a specific table, set the json-property "enabled" to false. Youc an also disable individual columns this way.

If you want, you can now configure the generation directly in the .json-file and then regenerate.

like image 133
Emil Forslund Avatar answered Nov 05 '22 17:11

Emil Forslund