Skip to content

Commit

Permalink
Allow app to define customised ebean IdGenerator #22
Browse files Browse the repository at this point in the history
  • Loading branch information
greenlaw110 committed Mar 23, 2020
1 parent 3c7b06f commit 1f6501a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# act-ebean-java7 CHANGE LOG

1.8.1
* Allow app to define customised ebean IdGenerator #22

1.8.0
* update to act-1.8.29
* update EbeanDao - add `processLikeValue` method
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/act/db/ebean/EbeanService.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ protected void dataSourceProvided(DataSource dataSource, DataSourceConfig dsConf
ebeanConfig = new EbeanConfigAdaptor().adaptFrom(this.config, dsConfig, this);
ebeanConfig.setDataSource(dataSource);
}
IdGeneratorRegister rg = Act.getInstance(IdGeneratorRegister.class);
rg.registerTo(ebeanConfig);
app().eventBus().trigger(new EbeanConfigLoaded(ebeanConfig));
if (readonly) {
ebeanConfig.setDdlGenerate(false);
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/act/db/ebean/IdGeneratorRegister.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package act.db.ebean;

/*-
* #%L
* ACT Ebean
* %%
* Copyright (C) 2015 - 2020 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 com.avaje.ebean.config.IdGenerator;
import com.avaje.ebean.config.ServerConfig;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;

@Singleton
public class IdGeneratorRegister {

@Inject
private List<IdGenerator> idGenerators = new ArrayList<>();

void registerTo(ServerConfig config) {
for (IdGenerator generator : idGenerators) {
config.add(generator);
}
}

}
2 changes: 1 addition & 1 deletion src/main/resources/act.scan.list
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
act.db.ebean.EbeanModule
act.db.jpa.EntityFinder
act.db.ebean.IdGeneratorRegister

0 comments on commit 1f6501a

Please sign in to comment.