-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow inject SqlDbService and DataSource #23; update to act-1.8.25
- Loading branch information
1 parent
10ab52c
commit d3ec812
Showing
7 changed files
with
204 additions
and
3 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
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,90 @@ | ||
package act.db.sql.inject; | ||
|
||
/*- | ||
* #%L | ||
* ACT SQL Common Module | ||
* %% | ||
* Copyright (C) 2015 - 2019 ActFramework | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
import act.Act; | ||
import act.app.App; | ||
import act.db.DB; | ||
import act.db.sql.DataSourceProvider; | ||
import act.db.sql.SqlDbService; | ||
import org.osgl.inject.Genie; | ||
import org.osgl.inject.NamedProvider; | ||
|
||
import javax.inject.Provider; | ||
import javax.sql.DataSource; | ||
|
||
public class SqlDbProviders { | ||
|
||
private static Provider<SqlDbService> SQL_DB_SVC_PROVIDER = new Provider<SqlDbService>() { | ||
@Override | ||
public SqlDbService get() { | ||
return NAMED_SQL_DB_SVC_PROVIDER.get(DB.DEFAULT); | ||
} | ||
}; | ||
|
||
private static NamedProvider<SqlDbService> NAMED_SQL_DB_SVC_PROVIDER = new NamedProvider<SqlDbService>() { | ||
@Override | ||
public SqlDbService get(String name) { | ||
return Act.app().dbServiceManager().dbService(name); | ||
} | ||
}; | ||
|
||
private static Provider<DataSource> DATA_SRC_PROVIDER = new Provider<DataSource>() { | ||
@Override | ||
public DataSource get() { | ||
return NAMED_DATA_SRC_PROVIDER.get(DB.DEFAULT); | ||
} | ||
}; | ||
|
||
private static NamedProvider<DataSource> NAMED_DATA_SRC_PROVIDER = new NamedProvider<DataSource>() { | ||
@Override | ||
public DataSource get(String name) { | ||
SqlDbService sqlDbService = NAMED_SQL_DB_SVC_PROVIDER.get(name); | ||
return sqlDbService.dataSource(); | ||
} | ||
}; | ||
|
||
private static Provider<DataSourceProvider> DATA_SRC_PROVIDER_PROVIDER = new Provider<DataSourceProvider>() { | ||
@Override | ||
public DataSourceProvider get() { | ||
return NAMED_DATA_SRC_PROVIDER_PROVIDER.get(DB.DEFAULT); | ||
} | ||
}; | ||
|
||
private static NamedProvider<DataSourceProvider> NAMED_DATA_SRC_PROVIDER_PROVIDER = new NamedProvider<DataSourceProvider>() { | ||
@Override | ||
public DataSourceProvider get(String name) { | ||
SqlDbService sqlDbService = NAMED_SQL_DB_SVC_PROVIDER.get(name); | ||
return sqlDbService.dataSourceProvider(); | ||
} | ||
}; | ||
|
||
public static void classInit(App app) { | ||
Genie genie = app.getInstance(Genie.class); | ||
genie.registerProvider(SqlDbService.class, SQL_DB_SVC_PROVIDER); | ||
genie.registerNamedProvider(SqlDbService.class, NAMED_SQL_DB_SVC_PROVIDER); | ||
genie.registerProvider(DataSource.class, DATA_SRC_PROVIDER); | ||
genie.registerNamedProvider(DataSource.class, NAMED_DATA_SRC_PROVIDER); | ||
genie.registerProvider(DataSourceProvider.class, DATA_SRC_PROVIDER_PROVIDER); | ||
genie.registerNamedProvider(DataSourceProvider.class, NAMED_DATA_SRC_PROVIDER_PROVIDER); | ||
} | ||
|
||
} |
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,90 @@ | ||
package sql_common; | ||
|
||
import act.controller.annotation.UrlContext; | ||
import act.db.beetlsql.BeetlSqlService; | ||
import act.db.eclipselink.EclipseLinkService; | ||
import act.db.hibernate.HibernateService; | ||
import act.db.jpa.JPAService; | ||
import act.db.sql.SqlDbService; | ||
import org.osgl.mvc.annotation.GetAction; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.sql.DataSource; | ||
|
||
@UrlContext("23") | ||
public class Gh23 { | ||
|
||
@Inject | ||
@Named("el") | ||
private JPAService elService; | ||
|
||
@Inject | ||
@Named("hi") | ||
private JPAService hiService; | ||
|
||
@Inject | ||
@Named("be") | ||
private SqlDbService beService; | ||
|
||
@Inject | ||
@Named("el") | ||
private DataSource elDs; | ||
|
||
@Inject | ||
@Named("hi") | ||
private DataSource hiDs; | ||
|
||
@Inject | ||
@Named("be") | ||
private DataSource beDs; | ||
|
||
@GetAction("~elService~") | ||
public boolean testElService() { | ||
if (null == elService) { | ||
return false; | ||
} | ||
return elService instanceof EclipseLinkService; | ||
} | ||
|
||
@GetAction("~hiService~") | ||
public boolean testHiService() { | ||
if (null == hiService) { | ||
return false; | ||
} | ||
return hiService instanceof HibernateService; | ||
} | ||
|
||
@GetAction("~beService~") | ||
public boolean testBeService() { | ||
if (null == beService) { | ||
return false; | ||
} | ||
return beService instanceof BeetlSqlService; | ||
} | ||
|
||
@GetAction("~elDataSource~") | ||
public boolean elDataSource() { | ||
if (null == elDs) { | ||
return false; | ||
} | ||
return elDs == elService.dataSource(); | ||
} | ||
|
||
@GetAction("~hiDataSource~") | ||
public boolean hiDataSource() { | ||
if (null == hiDs) { | ||
return false; | ||
} | ||
return hiDs == hiService.dataSource(); | ||
} | ||
|
||
@GetAction("~beDataSource~") | ||
public boolean beDataSource() { | ||
if (null == beDs) { | ||
return false; | ||
} | ||
return beDs == beService.dataSource(); | ||
} | ||
|
||
} |
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,10 @@ | ||
db.instances=el,hi,be | ||
|
||
db.el.url=jdbc:h2:./test-el | ||
db.el.impl=act.db.eclipselink.EclipseLinkPlugin | ||
|
||
db.hi.url=jdbc:h2:./test-hi | ||
db.hi.impl=act.db.hibernate.HibernatePlugin | ||
|
||
db.be.url=jdbc:h2:./test-el | ||
db.be.impl=act.db.beetlsql.BeetlSqlPlugin |