Skip to content

Commit

Permalink
Merge pull request #5 from ELDEpendenci/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 authored May 2, 2022
2 parents 447105c + 01b0f96 commit 53036b8
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 41 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: build plugin

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

on:
push:
branches:
- develop

jobs:
build_plugin:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v3
with:
java-version: '16'
distribution: 'adopt'
- name: Build with Maven
run: mvn --batch-mode package
- name: upload artifacts
uses: actions/upload-artifact@v1
with:
name: ELDependenci-SQL
path: ./eldependenci-sql-plugin/target/
32 changes: 3 additions & 29 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,11 @@ jobs:
- name: Checkout Source Code
id: checkout-source
uses: actions/checkout@v2
- name: Set up JDK 16
id: setup-java
uses: actions/setup-java@v1
- uses: eric2788/maven-jar-publish@v2
with:
java-version: 16
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Delete tag and release
id: delete-tag-release
uses: dev-drprasad/[email protected]
with:
tag_name: ${{ env.version }}
delete_release: true
- name: Create Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ env.version }}
release_name: Release ${{ github.repository }}-${{ env.version }}
body: |
版本更新請到[這裏](https://eric2788.gitbook.io/eldependenci-sql/references/update/v0.0.5)查看。
draft: false
prerelease: false
- name: Upload Release jar
id: upload-release-asset
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./${{ env.plugin_name }}/target/${{ env.plugin_name }}-${{env.version}}.jar # 請根據你插件名稱進行的修改
asset_name: ${{ env.plugin_name }}-${{ env.version }}.jar # 請根據你插件名稱進行的修改
asset_content_type: application/java-archive
body: 版本更新請到[這裏](https://eric2788.gitbook.io/eldependenci-sql/references/update/v0.0.5)查看。
upload-module: './eldependenci-sql-plugin'
- name: 'Update javadocs'
id: update-javadoc
uses: eric2788/push-javadoc-branch@main
Expand Down
2 changes: 1 addition & 1 deletion eldependenci-sql-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eldependenci-sql-module</artifactId>
<groupId>org.eldependenci</groupId>
<version>0.0.5</version>
<version>0.0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package chu77.eldependenci.sql;

import chu77.eldependenci.sql.config.Dbconfig;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.hibernate.dialect.Dialect;
import org.springframework.data.jpa.repository.JpaRepository;

import javax.annotation.Nullable;
import javax.sql.DataSource;
import java.util.*;
import java.util.stream.Collectors;

public final class ELDSQLInstallation implements SQLInstallation {


private final Set<Class<?>> entitySet = new HashSet<>();
private final Map<Class<?>, Class<?>[]> customImplements = new HashMap<>();

private final CustomSource customSource = new CustomSource();

@Override
public void bindEntities(Class<?>... entities) {
this.entitySet.addAll(Arrays.asList(entities));
Expand All @@ -23,6 +28,12 @@ public void bindJpaRepository(Class<? extends JpaRepository<?, ?>> repository, C
this.customImplements.put(repository, customImplements);
}

@Override
public void injectDataSource(DataSource dataSource, Class<? extends Dialect> dialect) {
this.customSource.dataSource = dataSource;
this.customSource.dialect = dialect;
}

public Set<Class<?>> getEntitySet() {
return ImmutableSet.copyOf(entitySet);
}
Expand All @@ -35,4 +46,21 @@ public <T> Set<Class<T>> getRepositories(){
public Map<Class<?>, Class<?>[]> getCustomImplements() {
return ImmutableMap.copyOf(customImplements);
}


public CustomSource getCustomSource() {
return customSource;
}

public static class CustomSource {
@Nullable
public DataSource dataSource;
@Nullable
public Class<? extends Dialect> dialect;

public boolean notInstalled(){
return dataSource == null || dialect == null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import chu77.eldependenci.sql.jpa.JpaRepositoryModule;
import chu77.eldependenci.sql.manager.JpaFactoryManager;
import chu77.eldependenci.sql.manager.SQLDataSourceManager;
import chu77.eldependenci.sql.manager.datasource.CustomDataSource;
import chu77.eldependenci.sql.manager.datasource.ELDDataSourceFactory;
import chu77.eldependenci.sql.manager.datasource.MySQLDataSourceFactory;
import chu77.eldependenci.sql.manager.datasource.MySQLDataSource;
import chu77.eldependenci.sql.manager.datasource.SQLiteDataSource;
import com.ericlam.mc.eld.AddonManager;
import com.ericlam.mc.eld.ELDBukkitAddon;
Expand All @@ -28,8 +29,9 @@ protected void bindServices(ServiceCollection serviceCollection) {
serviceCollection.addConfiguration(Dbconfig.class);

serviceCollection.addServices(ELDDataSourceFactory.class, Map.of(
"mysql", MySQLDataSourceFactory.class,
"sqlite", SQLiteDataSource.class
"mysql", MySQLDataSource.class,
"sqlite", SQLiteDataSource.class,
"custom", CustomDataSource.class
));

serviceCollection.bindService(SQLService.class, SQLDataSourceManager.class);
Expand All @@ -40,7 +42,6 @@ protected void bindServices(ServiceCollection serviceCollection) {
protected void preAddonInstall(ManagerProvider managerProvider, AddonManager moduleInstaller) {
File prop = new File(getDataFolder(), "hibernate.properties");
if (!prop.exists()) saveResource("hibernate.properties", true);
//Dbconfig dbconfig = managerProvider.getConfigStorage().getConfigAs(Dbconfig.class);
ELDSQLInstallation eldsqlInstallation = new ELDSQLInstallation();
moduleInstaller.customInstallation(SQLInstallation.class, eldsqlInstallation);
moduleInstaller.installModule(new JpaRepositoryModule(eldsqlInstallation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import chu77.eldependenci.sql.ELDSQLInstallation;
import chu77.eldependenci.sql.manager.datasource.EntityManagerProvider;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;

import javax.persistence.EntityManager;
import javax.sql.DataSource;
import java.util.Map;
import java.util.Set;

Expand All @@ -27,19 +29,23 @@ protected void configure() {
bind(new TypeLiteral<Set<Class<?>>>(){}).annotatedWith(Names.named("jpa-entities")).toInstance(eldsqlInstallation.getEntitySet());
bind(new TypeLiteral<Map<Class<?>, Class<?>[]>>(){}).annotatedWith(Names.named("jpa-custom-implements")).toInstance(eldsqlInstallation.getCustomImplements());
bind(RepoImplementManager.class).in(Scopes.SINGLETON);
bind(ELDSQLInstallation.CustomSource.class).toInstance(eldsqlInstallation.getCustomSource());

/* unused
/*
JpaTransactionInterceptor transactionInterceptor = new JpaTransactionInterceptor();
requestInjection(transactionInterceptor);
bindInterceptor(Matchers.annotatedWith(Transactional.class), Matchers.any(), transactionInterceptor);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), transactionInterceptor);
*/

/*
/* unused
RepositoryTypeListener repositoryTypeListener = new RepositoryTypeListener();
requestInjection(repositoryTypeListener);
bindListener(Matchers.any(), repositoryTypeListener);
*/
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package chu77.eldependenci.sql.manager.datasource;

import chu77.eldependenci.sql.ELDSQLInstallation;
import chu77.eldependenci.sql.config.Dbconfig;
import org.hibernate.dialect.Dialect;

import javax.inject.Inject;
import javax.sql.DataSource;

public final class CustomDataSource extends ELDSessionFactoryInterpreter{

private DataSource dataSource;

@Inject
private ELDSQLInstallation.CustomSource customSource;

@Override
public DataSource getDataSource() {
if (dataSource == null){
throw new IllegalStateException("Custom DataSource is not set");
}
return dataSource;
}

@Override
public void initialize(Dbconfig dbconfig) {
if (customSource.notInstalled()){
throw new IllegalStateException("using custom as data source but no custom data source was injected.");
}
this.dataSource = customSource.dataSource;
this.loadEntityRegistration(this.dataSource, customSource.dialect);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import javax.sql.DataSource;

public final class MySQLDataSourceFactory extends ELDSessionFactoryInterpreter {
public final class MySQLDataSource extends ELDSessionFactoryInterpreter {

private DataSource dataSource;

Expand Down
2 changes: 1 addition & 1 deletion eldependenci-sql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>eldependenci-sql-module</artifactId>
<groupId>org.eldependenci</groupId>
<version>0.0.5</version>
<version>0.0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package chu77.eldependenci.sql;

import org.hibernate.dialect.Dialect;
import org.springframework.data.jpa.repository.JpaRepository;

import javax.sql.DataSource;

/**
* SQL 安裝器
*/
Expand All @@ -20,4 +23,11 @@ public interface SQLInstallation {
*/
void bindJpaRepository(Class<? extends JpaRepository<?,?>> repository, Class<?>... customImplements);

/**
* 設置自定義的 DataSource (數據源)
* @param dataSource 自定義的 DataSource
* @param dialect 數據源的類型
*/
void injectDataSource(DataSource dataSource, Class<? extends Dialect> dialect);

}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>org.eldependenci</groupId>
<artifactId>eldependenci-sql-module</artifactId>
<packaging>pom</packaging>
<version>0.0.5</version>
<version>0.0.6</version>
<modules>
<module>eldependenci-sql</module>
<module>eldependenci-sql-plugin</module>
Expand Down Expand Up @@ -79,7 +79,7 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit 53036b8

Please sign in to comment.