Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.jagrosh:EasySQL:'
}
dependencies {
implementation("com.github.jagrosh:EasySQL:")
}
<dependency>
<groupId>com.github.jagrosh</groupId>
<artifactId>EasySQL</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.jagrosh" % "EasySQL" % ""
:dependencies [[com.github.jagrosh/EasySQL ""]]
Manage SQL Tables in H2 with less code
import com.jagrosh.easysql.*;
import com.jagrosh.easysql.columns.*;
import java.time.Instant;
public class LastSeenManager extends DataManager {
public final static SQLColumn<Long> USER_ID = new LongColumn("USER_ID", false, 0, true);
public final static SQLColumn<Instant> LAST_ACTIVE = new InstantColumn("LAST_ACTIVE", false, Instant.ofEpochSecond(0L));
public LastSeenManager(DatabaseConnector connector) {
super(connector, "LAST_SEEN");
}
public synchronized void setActive(long userId) {
readWrite(selectAll(USER_ID.is(userId)), results -> {
if(results.next()) {
LAST_ACTIVE.updateValue(results, Instant.now());
results.updateRow();
} else {
results.moveToInsertRow();
USER_ID.updateValue(results, userId);
LAST_ACTIVE.updateValue(results, Instant.now());
results.insertRow();
}
});
}
public synchronized Instant lastActive(User user) {
return read(select(USER_ID.is(user.getId()), LAST_ACTIVE), results -> {
if(results.next())
return LAST_ACTIVE.getValue(results);
return null;
});
}
}