Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Benjamin Evrard
    @bevrard
    Thanks for your feedback :) speedment is a great tool! (do you plan to add post and put for rest?)
    Per-Åke Minborg
    @minborg
    It is on the to-do list
    Mark Schrijver
    @ractoc
    I'm trying to get the StringToEnumTypeMapper to work. I have a table with an item_type column. This is a string column, which I want to map to an enum in my Java code.
    To do this, I setup the StringToEnumTypeMapper in my pom where I generate the json and the code:
    <plugin>
    <groupId>com.speedment</groupId>
    <artifactId>speedment-maven-plugin</artifactId>
    <version>${speedment.version}</version>
    <dependencies>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>${mysql.version}</version>
    </dependency>
    </dependencies>
    <configuration>
    <dbmsPassword>**</dbmsPassword>
    <configFile>${project.basedir}/src/main/resources/json/speedment.json</configFile>
    <packageLocation>target/generated-sources/java</packageLocation>
    </configuration>
    <executions>
    <execution>
    <id>Add ItemType typeMapper</id>
    <phase>generate-sources</phase>
    <goals>
    <goal>edit</goal>
    </goals>
    <configuration>
    <set>typeMapper:com.speedment.plugins.enums.StringToEnumTypeMapper</set>
    <what>column</what>
    <where>name:item_type</where>
    </configuration>
    </execution>
    <execution>
    <id>Add ItemType enumConstants</id>
    <phase>generate-sources</phase>
    <goals>
    <goal>edit</goal>
    </goals>
    <configuration>
    <set>enumConstants:BOARDGAMES</set>
    <what>column</what>
    <where>name:item_type</where>
    </configuration>
    </execution>
    <execution>
    <id>Generate code for Mysql</id>
    <phase>generate-sources</phase>
    <goals>
    <goal>generate</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    When I run this code, I keep getting the error:
    com.speedment.generator.translator.exception.SpeedmentTranslatorException: Could not find appropriate database type for column 'ColumnImpl {"databaseType": "java.lang.String", "nullable": true, "name": "item_type", "id": "item_type", "ordinalPosition": 4, "typeMapper": "com.speedment.plugins.enums.StringToEnumTypeMapper", "enumConstants": "BOARDGAMES"}'.
    I have the dependency containing the StringToEnumTypeMapper in my dependencies:
    <dependency>
    <groupId>com.speedment</groupId>
    <artifactId>runtime</artifactId>
    <version>${speedment.version}</version>
    <type>pom</type>
    </dependency>
    <dependency>
    <groupId>com.speedment.plugins</groupId>
    <artifactId>enum-generator</artifactId>
    <version>${speedment.version}</version>
    </dependency>
    I keep thinking I'm missing something here, I just can't figure out what that is
    Mark Schrijver
    @ractoc
    ah, nvm. Found it. I forgot to set the component on the speedment plugin:
                    <components>
                        <component>com.speedment.plugins.enums.EnumGeneratorBundle</component>
                    </components>
    Per-Åke Minborg
    @minborg
    Great!
    Mark Schrijver
    @ractoc
    yeah, the application is coming along nicely this way
    I'm amining for a minimal code backend, so I'm using a combo of Lombock with mapstruct
    results in remarkably clean and readable code
    Per-Åke Minborg
    @minborg
    Interesting indeed
    Mark Schrijver
    @ractoc
    lombock removes almost alle constructors, getters, setters and builders
    mapstruct takes care of all bean mappers
    all you need to do is make sure the getters and setters in both beans are the same, and mapstruct does the rest
    Per-Åke Minborg
    @minborg
    Very interesting with MapStruct !
    Mark Schrijver
    @ractoc
    yeah, I hate boilerplate so anything I can do to get rid of that... Which is one of the main reasons I switched to speedment
    all the boilerplate is generated
    Per-Åke Minborg
    @minborg
    MapStruct could provide a bridge between Speedment and many other frameworks.
    Mark Schrijver
    @ractoc
    Yeah
    I use it to bridge between my Sring boot rest interface Model objects and my speedment generted db objects
    works like a charm, all I need to do is: ItemMapper.INSTANCE.modelToDb(item)
    Per-Åke Minborg
    @minborg
    Cool. I think it would make sense to write an article about it
    or someTable.stream().map(ItemMapper.INSTANCE::mopdelToDb)….
    Mark Schrijver
    @ractoc
    public List<ItemModel> getItemList() {
    return itemService.getItemList().map(ItemMapper.INSTANCE::dbToModel).collect(Collectors.toList());
    }
    this is my method for retreiving the full list of items
    Per-Åke Minborg
    @minborg
    :-)
    Mark Schrijver
    @ractoc
    and all I did was write a simple interface
    Per-Åke Minborg
    @minborg
    Really great.
    Mark Schrijver
    @ractoc

    @Mapper
    public interface ItemMapper {
    ItemMapper INSTANCE = Mappers.getMapper(ItemMapper.class);

    ItemImpl modelToDb(ItemModel model);
    
    ItemModel dbToModel(Item item);
    
    @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
    default <T> T unwrapOptional(Optional<T> optional) {
        return optional.orElse(null);
    }

    }

    I'll see if I can write something over the next few days
    Per-Åke Minborg
    @minborg
    That would really be awesome!
    I could push the article through my channels
    Mark Schrijver
    @ractoc
    that would be great
    Mark Schrijver
    @ractoc
    now to find some inspiration...
    Mark Schrijver
    @ractoc
    first things first though, fixing my current wordpress install so I can actually put up the new tutorial
    lucky for my I didn't have that much content in there yet...
    although I will need to either fix all the code samples in one, or just drop that one completely
    Mark Schrijver
    @ractoc
    ok, done for now
    first setup is there. I will put the Speedment, Spring boot, Lombock, MapStruct tutorial series in there as well
    see if I can get something like an actual tutorial blog going there...
    Per-Åke Minborg
    @minborg
    sounds promising
    Mark Schrijver
    @ractoc
    should be able to start on my speedment tutorial series tonight
    just published the latest part in the unit test tutorial series
    Per-Åke Minborg
    @minborg
    :-0 Nice!