Created
April 26, 2020 13:13
-
-
Save dmi3coder/8bacb75627659bf25bb6b6171601effd to your computer and use it in GitHub Desktop.
Example of Picocli Quarkus command that modifies db entity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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