-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
406 changed files
with
26,900 additions
and
5,546 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,6 @@ | |
# IntelliJ | ||
out/ | ||
|
||
|
||
>>>>>>> origin/main | ||
# Compiled class file | ||
*.class | ||
|
||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.kunlab.kpm</groupId> | ||
<artifactId>TeamKunPluginManager</artifactId> | ||
<version>3.0.0</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>KPMAlias</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.kunlab.kpm</groupId> | ||
<artifactId>KPMCommon</artifactId> | ||
<version>3.0.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kunlab.kpm</groupId> | ||
<artifactId>KPMModels</artifactId> | ||
<version>3.0.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kunlab.kpm</groupId> | ||
<artifactId>KPMResolver</artifactId> | ||
<version>3.0.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
139 changes: 139 additions & 0 deletions
139
KPMAlias/src/main/java/org/kunlab/kpm/alias/AliasProviderImpl.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package org.kunlab.kpm.alias; | ||
|
||
import com.zaxxer.hikari.HikariDataSource; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.kunlab.kpm.alias.interfaces.Alias; | ||
import org.kunlab.kpm.alias.interfaces.AliasProvider; | ||
import org.kunlab.kpm.alias.interfaces.AliasSource; | ||
import org.kunlab.kpm.db.ResultRow; | ||
import org.kunlab.kpm.db.Transaction; | ||
|
||
import java.nio.file.Path; | ||
import java.sql.Statement; | ||
|
||
public class AliasProviderImpl implements AliasProvider | ||
{ | ||
@Getter(AccessLevel.PACKAGE) | ||
private final HikariDataSource db; | ||
|
||
public AliasProviderImpl(@NotNull Path path) | ||
{ | ||
this.db = Transaction.createDataSource(path); | ||
|
||
this.initializeTables(); | ||
} | ||
|
||
private void initializeTables() | ||
{ | ||
Transaction.create(this.db) | ||
.doTransaction((tr) -> { | ||
Statement stmt = tr.getConnection().createStatement(); | ||
|
||
stmt.execute("CREATE TABLE IF NOT EXISTS alias(" + | ||
"alias TEXT NOT NULL PRIMARY KEY," + | ||
"query TEXT NOT NULL," + | ||
"source_id TEXT NOT NULL" + | ||
")"); | ||
|
||
stmt.execute("CREATE TABLE IF NOT EXISTS source(" + | ||
"name TEXT PRIMARY KEY NOT NULL," + | ||
"source TEXT NOT NULL," + | ||
"type TEXT NOT NULL" + | ||
")"); | ||
}); | ||
} | ||
|
||
@Override | ||
public void close() | ||
{ | ||
this.db.close(); | ||
} | ||
|
||
@Override | ||
public AliasUpdaterImpl createUpdater(@NotNull String sourceName, @NotNull String sourceURL) | ||
{ | ||
return new AliasUpdaterImpl(sourceName, sourceURL, this); | ||
} | ||
|
||
/** | ||
* エイリアスが存在するかどうかを返します。 | ||
* | ||
* @param query エイリアス対象のkueri | ||
* @return エイリアスが存在するかどうか | ||
*/ | ||
@Override | ||
public boolean hasAlias(@NotNull String query) | ||
|
||
{ | ||
return Transaction.create(this.db, "SELECT COUNT(*) FROM alias WHERE query = ?") | ||
.set(1, query) | ||
.isExists(); | ||
} | ||
|
||
@Override | ||
public boolean hasSource(String id) | ||
{ | ||
return Transaction.create(this.db, "SELECT COUNT(*) FROM source WHERE name = ?") | ||
.set(1, id) | ||
.isExists(); | ||
} | ||
|
||
@Override | ||
public AliasSource getSource(String id) | ||
{ | ||
try (Transaction transaction = Transaction.create(this.db, "SELECT * FROM source WHERE name = ?") | ||
.set(1, id); | ||
ResultRow row = transaction | ||
.executeQuery() | ||
.stream() | ||
.findFirst().orElse(null)) | ||
{ | ||
if (row == null) | ||
return null; | ||
|
||
return new AliasSourceImpl( | ||
row.getString("name"), | ||
row.getString("source"), | ||
AliasSourceType.valueOf(row.getString("type")) | ||
); | ||
} | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public Alias getQueryByAlias(String alias) | ||
{ | ||
try (Transaction transaction = Transaction.create(this.db, "SELECT * FROM alias WHERE alias = ?") | ||
.set(1, alias); | ||
ResultRow row = transaction | ||
.executeQuery() | ||
.stream() | ||
.findFirst().orElse(null)) | ||
{ | ||
if (row == null) | ||
return null; | ||
|
||
return new AliasRecord( | ||
row.getString("alias"), | ||
row.getString("query"), | ||
row.getString("source_id") | ||
); | ||
} | ||
} | ||
|
||
@Override | ||
public int countAliases() | ||
{ | ||
try (Transaction transaction = Transaction.create(this.db, "SELECT COUNT(alias) FROM alias")) | ||
{ | ||
return transaction.executeQuery().stream() | ||
.findFirst() | ||
.map(row -> row.getInt("COUNT(alias)")) | ||
.orElse(0); | ||
} | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
KPMAlias/src/main/java/org/kunlab/kpm/alias/AliasSourceImpl.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.kunlab.kpm.alias; | ||
|
||
import lombok.Value; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.kunlab.kpm.alias.interfaces.AliasSource; | ||
|
||
@Value | ||
class AliasSourceImpl implements AliasSource | ||
{ | ||
@NotNull | ||
String name; | ||
@NotNull | ||
String source; | ||
|
||
@NotNull | ||
AliasSourceType type; | ||
} |
Oops, something went wrong.