
0.7.8-RELEASE big change and migration steps
💁 If you never touch the ApiHug domain entity management, then this migration will never bother you. but better keep rolling release with us! :-)
0.7.8-RELEASE Add features:
Repository @Derived maintain way to Trait separated location, make code clean;lite as default model for the stub side, make it more swift;
Target:
Take an exist repository: com.novel.book.wire.domain.book.repository.BookAuthorRepository in your module book-app as example:
Exist logic: in book-app\src\main\stub\com\novel\book\wire\domain\book\repository\BookAuthorRepository:
@Repository
@SuppressWarnings("Duplicates")
public interface BookAuthorRepository
extends HopeJdbc<BookAuthor>,
BookJdbcSupport,
BookAuthorDSL,
ListCrudRepository<BookAuthor, Long> {
@Derived
@Query
Optional<BookAuthor> findByName(final String name);
//Other method
}
⚠️⚠️⚠️ You need to backup your @Derived method before run the stub command;
As now the stub dir code is pure generated, that meaning it can be totally removed in next round stub command.
Run the stub command of your module after upgrade the SDK version in the gradle\libs.versions.toml:
[versions]
# libraries
apihug = "0.7.8-RELEASE"
Command line, check your project’s README.md:
./gradlew.bat book-app:clean stub build -x test -x stubTest
After run successfully you will got a new sourceSet: book-app\src\main\trait;
💁♀️ you may need Reload Gradle Project from Gradle tool window, otherwise the book-app\src\main\trait may not be recognized as sourceSet
@Derived to the _BookAuthorRepository(trait dir) & BookAuthorRepository(stub dir)(only first time migration need this, to keep the old class compilable);stub command again.Since now all the @Derived Repository methods, will be maintained separated at book-app\src\main\trait
stub job will merger them back to the runtime BookAuthorRepository classBookAuthorRepository during development(template code vs derived code), keep it pure and straightforward.trait for SQL logic;This way migration need more manually job, but much clearly;
book-app\src\main\traitt.com.novel.book.wire.domain.book.repository that is prefix with t. of original com.novel.book.wire.domain.book.repositoryinterface class _BookAuthorRepository that is prefix with _ of original BookAuthorRepositoryextends BookAuthorRepository@Derived method of BookAuthorRepository to _BookAuthorRepositorystub commandThis is a easier way for countable repository like less than 30 etc;
Real Project dir structure:
+---java
| \---com
| \---novel
| \---book
+---stub
| \---com
| \---novel
| \---book
| \---wire
| \---domain
| +---account
| | +---dsl
| | \---repository
| +---book
| | +---dsl
| | \---repository
| \---job
| +---dsl
| \---repository
\---trait
\---t
\---com
\---novel
\---book
\---wire
\---domain
+---account
| \---repository
+---book
| \---repository
\---job
\---repository
since SDK 0.8.5-RELEASE, introduce more way to handle those easier;
so after define a Entity in your proto and run stub command you will got a trait empty Repository:
/**
* NEVER try to use this class directly, keep it as an interface(default, no public), all body of
* this interface will be merger to {@link JobEntityRepository} after {@code stub };
*
* <p>NEVER try to Overwrite parent {@link JobEntityRepository } or {@link
* org.springframework.data.repository.ListCrudRepository} 's default method!!
*
* @see JobEntityRepository
* @see com.novel.book.wire.domain.job.JobEntity
*/
interface _JobEntityRepository extends JobEntityRepository {
/** Please put your customized SQL here, any SQL other place will be dropped after merger! */
interface _DerivedSQL {}
}
Then you can write a customized DAO api:
@Overwrite
default void myDaoApi(){
}
remember to add @Overwrite to this method, then the IDEA will remind you to Pull method 'myDaoApi' to 'JobEntityRepository'
Do as the IDEA suggest you, then this method will be pull to parent interface, this will avoid one round of stub command;
next time after kick off the stub command, you still get the exactly same code/logic.
You can consider the _BookAuthorRepository as Companion class of the BookAuthorRepository;
Only the ApiHug tool chain handle all those complexities for you!
Image the Companion objects in Scala;
IF YOU meet any problem during upgrade, please contact us:
