MyBatis Generator (MBG)

repository·master·Indexed 26 days ago

https://github.com/mybatis/generator

A code generation tool for the MyBatis SQL mapping framework that automates the creation of SQL Map XML files, Java model objects (POJOs), Java client classes, and Kotlin code by introspecting database schemas via JDBC DatabaseMetaData.

Tokens
2.8K
Snippets
6
Records
17
Agent score
90%

What's inside MyBatis Generator

  1. Overview of MyBatis Generator (MBG)

    master

    MyBatis Generator (MBG) is a code generation tool for the MyBatis SQL mapping framework. It automates the creation of several components by introspecting database tables via JDBC DatabaseMetaData:

    • SQL Map XML files: Mapping files for MyBatis.
    • Java model objects (POJOs): Java classes that correspond to your database tables.
    • Java client classes: (Optional) Client classes that utilize the generated model objects.
    • Kotlin code: MBG also supports generating Kotlin code for MyBatis.
  2. Find Eclipse platform features using OSGi console

    master

    To identify which features bundle specific plugins in a target runtime, use the OSGi console with a provlquery.

    1. Open an OSGi Console from the console view.
    2. Find the console number:
      ss p2.console
    3. Start the console using the number found:
      start <<consoleNumber>>
    4. Run a provlquery to find the feature containing your required dependency. For example, to find which feature bundles org.apache.commons.commons-logging in the 2024-09 release:
      provlquery http://download.eclipse.org/releases/2024-09 "select(parent | parent.properties['org.eclipse.equinox.p2.type.group'] == true && parent.requirements.exists(rc | everything.exists(iu | iu.id == 'org.apache.commons.commons-logging' && iu ~= rc)))" true
    5. Use the resulting feature IDs to add them directly to your target platform definition file.
    ss p2.console
    start <<consoleNumber>>
    provlquery http://download.eclipse.org/releases/2024-09 "select(parent | parent.properties['org.eclipse.equinox.p2.type.group'] == true && parent.requirements.exists(rc | everything.exists(iu | iu.id == 'org.apache.commons.commons-logging' && iu ~= rc)))" true
  3. Configure dependencies for MyBatis Generator

    master

    To use MyBatis Generator, ensure your environment meets the following requirements:

    1. JRE: Java 8 or above is required.
    2. JDBC Driver: You must provide a JDBC driver that implements the DatabaseMetaData interface. Specifically, the driver must correctly implement the getColumns and getPrimaryKeys methods to allow MBG to introspect your database schema.
  4. Build the project using Maven

    master

    Use the Maven wrapper (./mvnw) to build the project. Use the following commands depending on your goal:

    • Verify the build: Run integration tests to ensure the build is functional.
    • Create a release version: Build the project and create a new version suitable for publishing.
  5. Update Java Execution Environment for Eclipse plugins

    master

    If Eclipse warns that the plugin execution environment is lower than a plugin dependency (e.g., targeting environment 2021-06 which requires JDK 11), perform the following updates:

    1. Update MANIFEST.MF: Update the execution environment in the MANIFEST.MF files for:
      • org.mybatis.generator.core
      • org.mybatis.generator.eclipse.ui
      • org.mybatis.generator.eclipse.ui.tests
    2. Update Project Definitions: Update .classpath and org.eclipse.jdt.core.prefs (you can use the quick fix helper in the MANIFEST.MF file).
    3. Update Parent POM: Update the source and compile versions in the parent POM and the toolchain definition to match the new environment.
  6. Release the Eclipse Feature

    master

    The Eclipse feature uses Tycho Maven plugins and follows a different release process than the core product.

    Steps:

    1. Setup GPG (Unix/Mac): export GPG_TTY=$(tty)
    2. Prepare Update Site Repo: Clone mybatis-generator-update-site, create a new branch for the release (e.g., mybatis-generator-2.0.0).
    3. Prepare Core Repo: Clone the main generator repo and checkout the specific release tag.
    4. Build Feature: Navigate to the eclipse directory and run the build with the release-composite profile.
    5. Sync Site: Copy the generated site from org.mybatis.generator.eclipse.site/target/p2-composite-repo into your update site repository clone.
    6. Finalize: Commit/push changes, update the Eclipse Marketplace, and upload the zipped site from org.mybatis.generator.eclipse.site/target/p2-composite-repo/zipped to the GitHub release page.
    # Build the feature
    cd eclipse
    ./mvnw clean verify -Prelease-composite
    
    # Copy the generated site
    cd org.mybatis.generator.eclipse.site/target/p2-composite-repo
    cp -R . ~/git/GitHub/jeffgbutler/mybatis-generator-update-site
  7. Release the Core Product and Maven Plugin

    master

    The core product and Maven plugin are released using standard Maven release support.

    Prerequisites for Unix/Mac users: Set up GPG to use the terminal for password prompts:

    export GPG_TTY=$(tty)

    Release Steps:

    1. Clone the main repository via SSH and checkout the master branch.
    2. Navigate to the core directory.
    3. Execute the Maven release preparation and performance commands.
    4. Verify the deployment at Sonatype Central (Profile -> View Deployments) and publish it manually if required.
    cd core
    ./mvnw release:prepare
    ./mvnw release:perform
  8. Configure Maven toolchains for building

    master

    Before building with Maven, you must set up a toolchain by adding a toolchains.xml file to your ~/.m2 directory. This ensures the correct JDK is used during the build process.

    <?xml version="1.0" encoding="UTF8"?>
    <toolchains>
      <toolchain>
        <type>jdk</type>
        <provides>
          <version>17</version>
          <vendor>temurin</vendor>
        </provides>
        <configuration>
          <jdkHome>/Users/xxx/.sdkman/candidates/java/17.0.16-tem</jdkHome>
        </configuration>
      </toolchain>
    </toolchains>
  9. Update Eclipse dependencies for MyBatis Generator

    master

    To update dependencies for the Eclipse plugins, follow these steps to ensure compatibility across the target platform:

    1. Select an Eclipse version: Choose a target Eclipse version. You can find p2 Repository sites for various releases at the Eclipse SimRel wiki.
    2. Update Tycho Build Extension: Ensure the version in .mvn/extensions.xml matches the Tycho version specified in the parent POM.
    3. Update Plugin Dependencies: After updating the target platform, update the dependencies in the MANIFEST.MF files for these projects:
      • org.mybatis.generator.core
      • org.mybatis.generator.eclipse.ui
      • org.mybatis.generator.eclipse.ui.tests
    4. Update Runtime Dependencies:
      • Upgrade runtime dependencies in [MyBatisGenerator.target](./MyBatisGenerator.target) to match the core project versions.
      • If you update a version, you must update the MANIFEST.MF file in the related project and the version of the generated feature in the target definition file.
    5. Update Test Dependencies: For dependencies like AssertJ or JUnit 6 that are only needed during the build phase, reference them directly from Maven Central in [MyBatisGenerator.target](./MyBatisGenerator.target).