Skip to content

Instantly share code, notes, and snippets.

@dmi3coder
Created April 26, 2020 13:13
Show Gist options
  • Save dmi3coder/8bacb75627659bf25bb6b6171601effd to your computer and use it in GitHub Desktop.
Save dmi3coder/8bacb75627659bf25bb6b6171601effd to your computer and use it in GitHub Desktop.
Example of Picocli Quarkus command that modifies db entity
package org.acme.getting.started.command;
import org.acme.getting.started.data.Setting;
import picocli.CommandLine;
import javax.enterprise.context.Dependent;
import javax.transaction.Transactional;
@Dependent
@CommandLine.Command(name = "set")
public class SetCommand implements Runnable {
@CommandLine.Parameters(index = "0") TableType type;
@CommandLine.Parameters(index = "1") String key;
@CommandLine.Parameters(index = "2") String value;
@Override
@Transactional
public void run() {
if (type == TableType.SETTING) { //make a switch when you have more options
Setting setting = Setting.find("key = ?1", key).firstResult();
if(setting == null) {
setting = new Setting();
}
setting.key = key;
setting.value = value;
setting.persist();
}
}
enum TableType { SETTING }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment