diff --git a/docs/modules/how-it-works/pages/how-it-works.adoc b/docs/modules/how-it-works/pages/how-it-works.adoc index 13eb7c60d..1f959647b 100644 --- a/docs/modules/how-it-works/pages/how-it-works.adoc +++ b/docs/modules/how-it-works/pages/how-it-works.adoc @@ -74,11 +74,12 @@ long nrOfFilmsStartingWithA = jpaStreamer.stream(Film.class) .filter(Film$.title.startsWith("A")) "<1> .count(); ---- -#<1> As `title` is of type `StringField` we get access to operators such as `startsWith` that returns a `Predicate` that evaluates to `true` or `false`. +<1> As `title` is of type `StringField` we get access to operators such as `startsWith` that returns a `Predicate` that evaluates to `true` or `false`. You can read more about the use of fields and predicates xref:predicates:predicates.adoc[here]. NOTE: The metamodel is stored in the projects target-folder and does not need to be checked-in with your source code, nor needs testing. +NOTE: The package where generated entities are placed, as well as the name of the generated entities can be configured. Learn more xref:jpa-streamer:quick-start:quick-start.adoc#_code_generator_settings[here]. == The Stream renderer Most JPA providers, by default, has the ability to provide the query result as a `Stream`. That makes it possible to e.g. select all rows of a table and then use Stream operators to narrow the results. Although, that process requires every object of the table to be materialized by the JVM, which is not desired as it impedes the performance. diff --git a/docs/modules/quick-start/pages/quick-start.adoc b/docs/modules/quick-start/pages/quick-start.adoc index e12b7e4bc..2bf632d64 100644 --- a/docs/modules/quick-start/pages/quick-start.adoc +++ b/docs/modules/quick-start/pages/quick-start.adoc @@ -168,12 +168,51 @@ Film {filmId=5, title='AFRICAN EGG', ... NOTE: To release any resources potentially held by JPAstreamer, simply close the streamer using the command `jpaStreamer.close()`; -== Next Steps -Now that you have access to JPAstreamer it's time to put the expressiveness of Java Streams to work. If you are not yet familiar with the `Stream` API, you may find our guide on xref:stream-fundamentals:stream_basics.adoc[Stream Fundamentals] helpful. - -Otherwise, feel free to check out the xref:fetching-data:stream-examples.adoc[collection of examples] of JPAStreamer usage. - [source, java] ---- jpaStreamer.close(); ---- + +[#_code_generator_settings] +== Code Generator Settings +You can configure where the annotation processor generates entities and how they are named using the link:https://maven.apache.org/plugins/maven-compiler-plugin/[Maven Compiler Plugin]. This section describes how that is done. + +=== Package name +By default, all generated classes will be placed under `target/generated-sources/annotations` in a package that matches that of the original entity. Thus, a `com.foo.Film.class` entity will yield a `target/generated-sources/annotations/com/foo/Film$.class`. + +You can change the package name for all entities by setting the compiler argument `jpaStreamerPackage`. + +NOTE: If your entities have package private fields, they may not be accessible to the generated Entities. Therefore, take caution when deciding to place the generated entities in a separate package. + +=== Generated entity name +As shown in examples throughout the user guide, generated entities are by default given the name of the original entity with an extra `$` at the end. Meaning an entity `Foo.class` will yield a `Foo$.class`. You can change the naming convention by setting the compiler argument `jpaStreamerPrefix` and `jpaStreamerSuffix`. The prefix will be added at the start of the original entity name and the suffix will be appended at the end. + +NOTE: The default suffix `$` applies if no custom values are provided via the compiler arguments. If just one of `jpaStreamerPrefix` and `jpaStreamerSuffix` is set, the other will automatically default to an empty string. For example, just setting the prefix to `A` will result in entities with the name `AFoo.class`. Take note that the naming pattern must adhere to link:https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html[Java's naming conventions]. + +Here is a complete example configuration of the plugin that sets both the package name, prefix, and suffix. + +[source,xml] +---- + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + + -AjpaStreamerPackage=com.speedment.jpastreamer.test <1> + -AjpaStreamerPrefix=A <2> + -AjpaStreamerSuffix=B <3> + + + +---- +<1> Package name is set to `com.speedment.jpastreamer.test` +<2> Entity prefix is set to A (start) +<3> Entity suffix is set to B (ending) + +In the above example, all generated entities will be placed in `/target/generated-sources/annotations/com.speedment.jpastreamer.test`. An original entity with the name `Film` will yeild a generated entity called `AFilmB`. + +== Next Steps +Now that you have access to JPAstreamer it's time to put the expressiveness of Java Streams to work. If you are not yet familiar with the `Stream` API, you may find our guide on xref:stream-fundamentals:stream_basics.adoc[Stream Fundamentals] helpful. + +Otherwise, feel free to check out the xref:fetching-data:stream-examples.adoc[collection of examples] of JPAStreamer usage. diff --git a/docs/site.yml b/docs/site.yml index 0320de27d..de5b04cf0 100644 --- a/docs/site.yml +++ b/docs/site.yml @@ -20,7 +20,7 @@ content: # only generate from git tags (and not branches) branches: [] start_path: docs - tags: [0.1*, 1.0*, '!1.0.3', 1.1*] + tags: [0.1*, 1.0*, '!1.0.3', 1.1*, '!1.1.1'] ui: bundle: url: ui-bundle.zip diff --git a/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/StandardFieldGeneratorProcessor.java b/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/StandardFieldGeneratorProcessor.java index a48cd563b..6a15bc0ab 100644 --- a/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/StandardFieldGeneratorProcessor.java +++ b/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/StandardFieldGeneratorProcessor.java @@ -29,6 +29,7 @@ */ @SupportedAnnotationTypes("javax.persistence.Entity") +@SupportedOptions({"jpaStreamerPackage", "jpaStreamerPrefix", "jpaStreamerSuffix"}) @SupportedSourceVersion(SourceVersion.RELEASE_8) @AutoService(Processor.class) public final class StandardFieldGeneratorProcessor extends AbstractProcessor { diff --git a/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java b/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java index c6fb79db3..049d696a9 100644 --- a/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java +++ b/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java @@ -98,10 +98,30 @@ public boolean process(Set annotations, RoundEnvironment .filter(ae -> ae.getKind() == ElementKind.CLASS) .forEach(ae -> { try { - String qualifiedGenEntityName = ae.asType().toString() + "$"; + final String entityName = ae.asType().toString(); + final String shortEntityName = shortName(entityName); + + final String prefix = processingEnv.getOptions().getOrDefault("jpaStreamerPrefix", ""); + final String suffix = processingEnv.getOptions().getOrDefault("jpaStreamerSuffix", ""); + + final String genEntityName = (!prefix.equals("") || !suffix.equals("")) ? + prefix + shortEntityName + suffix : shortEntityName + "$"; + + String annotatedElementPackageName = ""; + final PackageElement packageElement = processingEnvironment.getElementUtils().getPackageOf(ae); + if (packageElement.isUnnamed()) { + messager.printMessage(Diagnostic.Kind.WARNING, "Class " + entityName + " has an unnamed package."); + annotatedElementPackageName = ""; + } else { + annotatedElementPackageName = packageElement.getQualifiedName().toString(); + } + + String packageName = processingEnv.getOptions().getOrDefault("jpaStreamerPackage", annotatedElementPackageName); + + String qualifiedGenEntityName = packageName + "." + genEntityName; JavaFileObject builderFile = processingEnv.getFiler().createSourceFile(qualifiedGenEntityName); Writer writer = builderFile.openWriter(); - generateFields(ae, writer); + generateFields(ae, entityName, genEntityName, packageName, writer); writer.close(); } catch (IOException e) { e.printStackTrace(); @@ -111,10 +131,7 @@ public boolean process(Set annotations, RoundEnvironment return true; } - void generateFields(final Element annotatedElement, final Writer writer) throws IOException { - - final String entityName = shortName(annotatedElement.asType().toString()); - final String genEntityName = entityName + "$"; + void generateFields(final Element annotatedElement, final String entityName, final String genEntityName, final String packageName, final Writer writer) throws IOException { final Map getters = annotatedElement.getEnclosedElements().stream() .filter(ee -> ee.getKind() == ElementKind.METHOD) @@ -131,7 +148,7 @@ void generateFields(final Element annotatedElement, final Writer writer) throws .map(n -> n.substring(2)) .map(Formatting::lcfirst) .collect(toSet()); - + // Retrieve all declared non-final instance fields of the annotated class Map enclosedFields = annotatedElement.getEnclosedElements().stream() .filter(ee -> ee.getKind().isField() @@ -140,25 +157,9 @@ void generateFields(final Element annotatedElement, final Writer writer) throws .collect( toMap( Function.identity(), - ee -> findGetter(ee, getters, isGetters, entityName, lombokGetterAvailable(annotatedElement, ee))) + ee -> findGetter(ee, getters, isGetters, shortName(entityName), lombokGetterAvailable(annotatedElement, ee))) ); -/* if (annotatedElement.getSimpleName().toString().contains("User")) { - messager.printMessage(Diagnostic.Kind.NOTE, " "+ isGetters.size()); - messager.printMessage(Diagnostic.Kind.NOTE, " "+ isGetters.iterator().next()); - messager.printMessage(Diagnostic.Kind.NOTE, enclosedFields.toString()); - throw new UnsupportedEncodingException(isGetters.toString()); - }*/ - - final PackageElement packageElement = processingEnvironment.getElementUtils().getPackageOf(annotatedElement); - String packageName; - if (packageElement.isUnnamed()) { - messager.printMessage(Diagnostic.Kind.WARNING, "Class " + entityName + " has an unnamed package."); - packageName = ""; - } else { - packageName = packageElement.getQualifiedName().toString(); - } - final File file = generatedEntity(enclosedFields, entityName, genEntityName, packageName); writer.write(generator.on(file).orElseThrow(NoSuchElementException::new)); } @@ -179,7 +180,7 @@ private String findGetter(final Element field, final String standardJavaName = javaNameFromExternal(fieldName); final String standardGetterName = getterPrefix + standardJavaName; - + if (getters.get(standardGetterName) != null || isGetters.contains(standardGetterName)) { // We got lucky because the user elected to conform // to the standard JavaBean notation. @@ -210,23 +211,25 @@ private String findGetter(final Element field, } - private File generatedEntity(Map enclosedFields, String entityName, String genEntityName, String packageName) { + private File generatedEntity(final Map enclosedFields, final String entityName, final String genEntityName, final String packageName) { final File file = packageName.isEmpty() ? File.of(genEntityName + ".java") : File.of(packageName + "/" + genEntityName + ".java"); + final String shortEntityName = shortName(entityName); + final Class clazz = Class.of(genEntityName) .public_() .final_() .set(Javadoc.of( - "The generated base for entity {@link " + entityName + "} representing entities of the" - + " {@code " + lcfirst(entityName) + "}-table in the database." + + "The generated base for entity {@link " + shortEntityName + "} representing entities of the" + + " {@code " + lcfirst(shortEntityName) + "}-table in the database." + nl() + "

This file has been automatically generated by JPAStreamer." ).author("JPAStreamer")); enclosedFields .forEach((field, getter) -> { - addFieldToClass(field, getter, clazz, entityName); + addFieldToClass(field, getter, clazz, shortEntityName); // Name magic... if (getter.contains(IllegalJavaBeanException.class.getSimpleName())) { file.add(Import.of(IllegalJavaBeanException.class)); @@ -235,6 +238,8 @@ private File generatedEntity(Map enclosedFields, Stri file.add(clazz); file.call(new AutoImports(generator.getDependencyMgr())).call(new AlignTabs<>()); + file.imports(SimpleType.create(entityName)); + return file; } @@ -328,11 +333,11 @@ private Type fieldType(Element field) { } private String trimAnnotations(Element field) { - final String fieldType = field.asType().toString(); + final String fieldType = field.asType().toString(); final int index = fieldType.lastIndexOf(' '); - return index < 0 ? fieldType : fieldType.substring(index + 1); + return index < 0 ? fieldType : fieldType.substring(index + 1); } - + private Type primitiveFieldType(Type fieldType, Type entityType) { Type primitiveFieldType; switch (fieldType.getTypeName()) { diff --git a/fieldgenerator/fieldgenerator-test-package/pom.xml b/fieldgenerator/fieldgenerator-test-package/pom.xml new file mode 100644 index 000000000..be1ca206f --- /dev/null +++ b/fieldgenerator/fieldgenerator-test-package/pom.xml @@ -0,0 +1,129 @@ + + + + + fieldgenerator + com.speedment.jpastreamer + 1.1.3-SNAPSHOT + + 4.0.0 + + fieldgenerator-test-package + + + jpastreamer.fieldgenerator.test.renaming + true + + + FieldGenerator - Test Package Renaming + + Standard field generator tests with package renaming + + + + + + javax.persistence + javax.persistence-api + + + + com.speedment.jpastreamer + fieldgenerator-standard + + + + com.speedment.jpastreamer + field + + + + org.projectlombok + lombok + 1.18.24 + provided + + + + javax.validation + validation-api + 2.0.0.Final + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + + -AjpaStreamerPackage=com.speedment.jpastreamer.fieldgenerator.test.renaming.inner + -AjpaStreamerSuffix=B + + + + + + maven-deploy-plugin + + true + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + generate-sources + + add-source + + + + target/generated-sources/annotations + + + + + + + + + + + + release + + + + maven-javadoc-plugin + + false + + + + + + + + diff --git a/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Actor.java b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Actor.java new file mode 100644 index 000000000..0cc92f192 --- /dev/null +++ b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Actor.java @@ -0,0 +1,51 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2022, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.fieldgenerator.renaming; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.Getter; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Data +@Table(name = "actor", schema = "sakila") +public class Actor { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "actor_id", nullable = false, updatable = false, columnDefinition = "smallint(5)") + private Integer actorId; + + @Column(name = "first_name", nullable = false, columnDefinition = "varchar(45)") + private String firstName; + + @Column(name = "last_name", nullable = false, columnDefinition = "varchar(45)") + private String lastName; + + @Getter(value = AccessLevel.PRIVATE) + @ManyToMany(mappedBy = "actors") + private List films = new ArrayList<>(); + + @Override + public String toString() { + return "Actor{" + + "actorId=" + actorId + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + '}'; + } +} diff --git a/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Film.java b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Film.java new file mode 100644 index 000000000..34ea68706 --- /dev/null +++ b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Film.java @@ -0,0 +1,297 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2022, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.fieldgenerator.renaming; + +import javax.persistence.*; +import java.sql.Time; +import java.time.LocalDateTime; +import java.util.*; + +@Entity +@Table(name = "film", schema = "sakila") +public class Film { + + // Reproduce #58 + private static final Map, List> A = new HashMap<>(); + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "film_id", nullable = false, unique = true, updatable = false, columnDefinition = "smallint(5)") + // Make this field package private just for good measure... + int filmId; + + @Column(name = "title", nullable = false, columnDefinition = "varchar(255)") + private String title; + + @Column(name = "description", nullable = false, columnDefinition = "text") + private String description; + + @Column(name = "audienceScore", nullable = true, columnDefinition = "decimal(4,2)") + private Double audienceScore; + + @Lob + @Column(name = "cover", nullable = true) + private byte[] cover; + + @Lob + @Column(name = "long_description", nullable = true) + private String long_description; + + /** + * DATE AND TIME + */ + @Column(name = "release_date", nullable = false, columnDefinition = "DATE") + @Temporal(TemporalType.DATE) + private java.util.Date releaseDate; + + @Column(name = "release_timestamp", nullable = false, columnDefinition = "TIMESTAMP") + @Temporal(TemporalType.TIMESTAMP) + private Calendar releaseTimestamp; + + @Column(name = "release_time", nullable = false, columnDefinition = "TIME") + private Time releaseTime; + + @ManyToOne + @JoinColumn(name = "language_id") + private Language language; + + @ManyToOne + @JoinColumn(name = "original_language_id") + private Language originalLanguage; + + @Column(name = "complex_column") + private Map>, Integer>, Long> complexColumn; + + @Column(name = "rental_duration", columnDefinition = "smallint(5)") + private Integer rentalDuration; + + @Column(name = "rental_rate", columnDefinition = "decimal(4,2)") + private Float rentalRate; + + @Column(name = "length", columnDefinition = "smallint(5)") + private Integer length; + + @Column(name = "replacement_cost", columnDefinition = "decimal(5,2)") + private Float replacementCost; + + @Column(name = "rating", columnDefinition = "enum('G','PG','PG-13','R','NC-17')") + private String rating; + + @Column(name = "special_features", columnDefinition = "set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes')") + private Set specialFeatures; // Should be Set + + @Column(name = "last_update", nullable = false, columnDefinition = "timestamp") + private LocalDateTime lastUpdate; + + + public Integer getFilmId() { + return filmId; + } + + public void setFilmId(Integer filmId) { + this.filmId = filmId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +/* + public Year getReleaseYear() { + return releaseYear; + } + + public void setReleaseYear(Year releaseYear) { + this.releaseYear = releaseYear; + }*/ + + + public Language getLanguage() { + return language; + } + + public void setLanguage(Language language) { + this.language = language; + } + + public Language getOriginalLanguage() { + return originalLanguage; + } + + public void setOriginalLanguage(Language originalLanguage) { + this.originalLanguage = originalLanguage; + } + + public void setRentalDuration(Integer rentalDuration) { + this.rentalDuration = rentalDuration; + } + + public Integer getRentalDuration() { + return rentalDuration; + } + + public Float getRentalRate() { + return rentalRate; + } + + public void setRentalRate(Float rentalRate) { + this.rentalRate = rentalRate; + } + + public Integer getLength() { + return length; + } + + public void setLength(Integer length) { + this.length = length; + } + + public Float getReplacementCost() { + return replacementCost; + } + + public void setReplacementCost(Float replacementCost) { + this.replacementCost = replacementCost; + } + + public Set getSpecialFeatures() { + return specialFeatures; + } + + public void setSpecialFeatures(Set specialFeatures) { + this.specialFeatures = specialFeatures; + } + + + public LocalDateTime getLastUpdate() { + return lastUpdate; + } + + public void setLastUpdate(LocalDateTime lastUpdate) { + this.lastUpdate = lastUpdate; + } + + public Double getAudienceScore() { + return audienceScore; + } + + public void setAudienceScore(Double audienceScore) { + this.audienceScore = audienceScore; + } + + public Map>, Integer>, Long> getComplexColumn() { + return complexColumn; + } + + public void setComplexColumn(Map>, Integer>, Long> complexColumn) { + this.complexColumn = complexColumn; + } + + public byte[] getCover() { + return cover; + } + + public void setCover(byte[] cover) { + this.cover = cover; + } + + // This getter is using another format + // where underscores are removed and + // camelized + public String getLongDescription() { + return long_description; + } + + public void setLongDescription(String long_description) { + this.long_description = long_description; + } + + @Override + public String toString() { + return "Film{" + + "filmId=" + filmId + + ", title='" + title + '\'' + + ", description='" + description + '\'' + + ", audienceScore=" + audienceScore + + ", cover=" + Arrays.toString(cover) + + ", long_description='" + long_description + '\'' + + ", releaseDate=" + releaseDate + + ", releaseTimestamp=" + releaseTimestamp + + ", releaseTime=" + releaseTime + + ", language=" + language + + ", originalLanguage=" + originalLanguage + + ", complexColumn=" + complexColumn + + ", rentalDuration=" + rentalDuration + + ", rentalRate=" + rentalRate + + ", length=" + length + + ", replacementCost=" + replacementCost + + ", rating='" + rating + '\'' + + ", specialFeatures=" + specialFeatures + + ", lastUpdate=" + lastUpdate + + '}'; + } + + public java.util.Date getReleaseDate() { + return releaseDate; + } + + public void setReleaseDate(java.util.Date releaseDate) { + this.releaseDate = releaseDate; + } + + public Calendar getReleaseTimestamp() { + return releaseTimestamp; + } + + public void setReleaseTimestamp(Calendar releaseTimestamp) { + this.releaseTimestamp = releaseTimestamp; + } + + public Time getReleaseTime() { + return releaseTime; + } + + public void setReleaseTime(Time releaseTime) { + this.releaseTime = releaseTime; + } + + public String getRating() { + return rating; + } + + public int getSomeOtherPropertyThatIsNotAField() { + return 0; + } + + public void setRating(String rating) { + this.rating = rating; + } + + // This method could be added via an annotation + // processor if the field is private. + String long_descriptionHelper() { + return long_description; + } + +} diff --git a/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Language.java b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Language.java new file mode 100644 index 000000000..e178155c1 --- /dev/null +++ b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Language.java @@ -0,0 +1,67 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2022, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.fieldgenerator.renaming; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Set; + +@Entity +@Table(name = "language", schema = "sakila") +public class Language implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "language_id", nullable = false, updatable = false, columnDefinition = "tinyint(3)") + private Integer languageId; + + @Column(name = "name", nullable = false, columnDefinition = "char(20)") + private String name; + + @OneToMany(mappedBy = "language") + private Set films; + + @ManyToMany + public Integer getLanguageId() { + return languageId; + } + + public void setLanguageId(Integer language_id) { + this.languageId = language_id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set getFilms() { + return films; + } + + public void setFilms(Set films) { + this.films = films; + } + + @Override + public String toString() { + return "Language{" + + "languageId=" + languageId + + ", name='" + name + '\'' + + '}'; + } + +} diff --git a/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Main.java b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Main.java new file mode 100644 index 000000000..bbed38bc0 --- /dev/null +++ b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/Main.java @@ -0,0 +1,42 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2022, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.fieldgenerator.renaming; + +import com.speedment.jpastreamer.fieldgenerator.test.renaming.inner.FilmB; + +import java.util.stream.Stream; + +public class Main { + + public static void main(String[] args) { + final Film olle = new Film(); + olle.setFilmId(1); + olle.setTitle("Moderns Dimunitiva Son Vid Namn Olle"); + olle.setDescription("Olle går i skogen och träffar en björn som äter upp alla hans surt förvärvade blåbär. Olle kräver sedan oväntat av sin mamma att få återse den fyrbenta tjuven."); + olle.setLength(120); + + final Film spindel = new Film(); + spindel.setFilmId(2); + spindel.setTitle("Den Disorienterade Spindeln"); + spindel.setDescription("Spindeln klättrar upp för sin tråd men allt går åt helvete och spindeln faller ned. Han ger dock ej upp utan försöker ånyo ad infinitum!"); + spindel.setLength(110); + + // Make sure generation is actually done + Stream.of(olle, spindel) + .filter(FilmB.length.between(100, 150)) + .filter(FilmB.rating.in("G", "PG")) + .sorted(FilmB.title) + .forEachOrdered(System.out::println); + + } +} diff --git a/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/User.java b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/User.java new file mode 100644 index 000000000..110be527b --- /dev/null +++ b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/User.java @@ -0,0 +1,50 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2022, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.fieldgenerator.renaming; + +import javax.persistence.*; + +@Entity +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_id", nullable = false, unique = true, updatable = false, columnDefinition = "smallint(5)") + private int userId; + + @Column(name = "name", nullable = false, columnDefinition = "varchar(255)") + private String name; + + private boolean member; + + private boolean large; + + public int getUserId() { + return userId; + } + + public String getName() { + return name; + } + + // Use "get" rather than "is" + public boolean getMember() { + return member; + } + + // Use "is" rather than "get" + public boolean isLarge() { + return large; + } + +} diff --git a/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/User2.java b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/User2.java new file mode 100644 index 000000000..a572e5a2c --- /dev/null +++ b/fieldgenerator/fieldgenerator-test-package/src/main/java/com/speedment/jpastreamer/fieldgenerator/renaming/User2.java @@ -0,0 +1,48 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2022, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.fieldgenerator.renaming; + +import javax.persistence.*; +import javax.validation.constraints.NotEmpty; + +import java.io.Serializable; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +@Entity +@Table(name="user") +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor + +public class User2 implements Serializable{ + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_shared") + @SequenceGenerator(name = "seq_shared", sequenceName = "seq_shared",allocationSize = 1) + Long id; + + @NotEmpty + private String username; + + @NotEmpty + private String password; + + // Should generate isEnabled + private boolean enabled; + + // Should generate getActive + private Boolean active; +} diff --git a/fieldgenerator/fieldgenerator-test-package/src/main/java9/module-info.java b/fieldgenerator/fieldgenerator-test-package/src/main/java9/module-info.java new file mode 100644 index 000000000..37db7ad76 --- /dev/null +++ b/fieldgenerator/fieldgenerator-test-package/src/main/java9/module-info.java @@ -0,0 +1,22 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2022, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +module jpastreamer.fieldgenerator.test.renaming { + + requires jpastreamer.fieldgenerator.standard; + requires java.persistence; + requires transitive java.sql; + requires transitive jpastreamer.field; + + exports com.speedment.jpastreamer.fieldgenerator.test.renaming.inner; + +} diff --git a/fieldgenerator/pom.xml b/fieldgenerator/pom.xml index 79ed104fe..dc9c1de97 100644 --- a/fieldgenerator/pom.xml +++ b/fieldgenerator/pom.xml @@ -51,6 +51,7 @@ fieldgenerator-standard fieldgenerator-component fieldgenerator-test + fieldgenerator-test-package