Giter VIP home page Giter VIP logo

spring-data-generator's Introduction

Spring Data Generator Build Status Maven Central

Spring Data Generator for JPA repositories and managers.

Features

  • Generate in Runtime
  • Generate by Plugin
  • Generate repositories for JPA Entities
  • Generate managers for JPA Entities
  • EntityScan wrapped annotation
  • Overwrite option
  • Support JpaSpecificationExcecutor<?>
  • Support @EmbeddedId annotation
  • @Id or @EmbeddedId primitive support
  • Package structure support
  • Additional extends support

Dependencies

  • Java 8
  • Spring data JPA

Generate in Runtime

Download the jar through Maven:

<dependency>
  <groupId>com.cmeza</groupId>
  <artifactId>spring-data-generator</artifactId>
  <version>1.1.8</version>
</dependency>

The simple Spring Data JPA configuration with Java-Config looks like this:

@SDGenerator(
        entityPackage = "com.acme.model",
        repositoryPackage = "com.acme.repositories",
        managerPackage = "com.acme.managers",
        repositoryPostfix = "Repository",
        managerPostfix = "Manager",
        onlyAnnotations = false,
        debug = false,
        overwrite = false,
        additionalExtends = {
                QuerydslPredicateExecutor.class
        }
)
@SpringBootApplication
public class AppConfig {
    
    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class, args);
    }
    
}
Attribute Required Default Description
entityPackage No [] Entity scan package
repositoryPackage No "" Package where the repositories will be generated
managerPackage No "" Package where the managers will be generated
repositoryPostfix No "Repository" Postfix for repositories. example: AccountRepository
managerPostfix No "Manager" Postfix for managers. example: AccountManager
onlyAnnotations No false Scan only classes annotated with @SDGenerate or @SDNoGenerate
debug No false Enable debug log
overwrite No false Overwrite existing files
additionalExtends No [] Extension of additional interfaces

Generate by Plugin

Download the jar through Maven:

<build>
	<plugins>
		<plugin>
			<groupId>com.cmeza</groupId>
			<artifactId>spring-data-generator</artifactId>
			<version>1.1.8</version>
			<configuration>
				<entity-package>
				    <param>com.acme.model</param>
				</entity-package>
				<repository-package>com.acme.repository</repository-package>
				<repository-postfix>Repository</repository-postfix>
				<manager-package>com.acme.managers</manager-package>
				<manager-postfix>Manager</manager-postfix>
				<only-annotations>false</only-annotations>
				<overwrite>false</overwrite>
				<additional-extends>
                    <param>org.springframework.data.querydsl.QuerydslPredicateExecutor</param>
                </additional-extends>
			</configuration>
		</plugin>
	</plugins>
</build>
Attribute Required Default Description
entity-package Yes [] Entity scan package
repository-package Yes "" Package where the repositories will be generated
manager-package Yes "" Package where the managers will be generated
repository-postfix No "Repository" Postfix for repositories. example: AccountRepository
manager-postfix No "Manager" Postfix for managers. example: AccountManager
onlyAnnotations No false Scan only classes annotated with @SDGenerate or @SDNoGenerate
overwrite No false Overwrite existing files
additional-extends No [] Extension of additional interfaces

Generate repositories (terminal)

$ mvn spring-data-generator:repositories

Generate managers (terminal)

$ mvn spring-data-generator:managers

Example

Sample entity in com.acme.model

@Entity
//@SDGenerate   ->  Optional: Include to classes scan
//@SDNoGenerate   ->  Optional: Exclude to classes scan
public class Account {

    @Id
    @GeneratedValue
    private Long id;
    private String firstname;
    private String lastname;
       
    // Getters and setters
    // (Firstname, Lastname)-constructor and noargs-constructor
    // equals / hashcode
}

Generate a repository interface example in com.acme.repositories:

@Repository
public interface AccountRepository extends JpaRepository<Account, Long>, JpaSpecificationExecutor<Account> {
}

Generate a manager class example in com.acme.managers:

@Component
public class AccountManager {
    
    private AccountRepository accountRepository;
    
    @Autowired
    public AccountManager(AccountRepository accountRepository) {
        this.accountRepository = accountRepository;
    }   
}

Notes

  • The overwrite option delete the existing file to regenerate
  • The generation of repositories and managers inherits the entity package. Example:

alt tag

License

MIT

spring-data-generator's People

Contributors

cesdperez avatar cmeza20 avatar luc-chevaux avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.