Blog

Wednesday 21 November 2012

itcrowd-domain-findbugs 1.0.0

We're tired for manual checking javax.validation annotations against entity's persistent properties. For all of you who feel the same we bring itcrowd-domain-findbugs.

What is so painful? Let's look at the example.
@Table(name = "SizeTestingEntity")
@Entity
public class SizeTestingEntity {
// ------------------------------ FIELDS ------------------------------

    @Size
    @Column(length = 34)
    private String invalidD;

    @Size
    @Column
    private String invalidE;

    @Size(max = 34)
    @Column(length = 34)
    private String validA;

    @Column(nullable = false)
    private String missingNotNull;

    @NotNull
    @ManyToOne(optional = false)
    @JoinTable(name = "BLA", joinColumns = @JoinColumn(name = "ManyToOneEntity"), inverseJoinColumns = @JoinColumn(name = "joinTableD"))
    private Group joinTableD;

} 
If we have @Column for attribute of type String it's good to specify @Size.
@Column with attribute "nullable=false" should be accompanied with  @NotNull or @NotEmpty annotation.
Other thing we have to keep synchronized is value of "optional" attribute of @ManyToOne against @NotNull.

There is also many other checks. Maintaining this manually is a nightmare, so we've written plugin for findbugs that does this automatically.
Right now there are following checks:
  • ForeignKeyInconsistency
  • NotNullInconsistency
  • NotEmptyInconsistency
  • SizeInconsistency
  • TableInconsistency
  • ManyToOneInconsistency
We plan to add more checks in future.

Setup

All you have to do is to configure findbugs to be aware of our plugin. Here is sample configuration of findbugs-maven-plugin:
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>2.5.2</version>
                <configuration>
                    <plugins>
                        <plugin>
                            <groupId>pl.itcrowd.findbugs.domain</groupId>
                            <artifactId>itcrowd-findbugs-domain</artifactId>
                            <version>1.0.0</version>
                        </plugin>
                    </plugins>
                    <visitors>ForeignKeyInconsistency,NotNullInconsistency,NotEmptyInconsistency,SizeInconsistency,TableInconsistency,ManyToOneInconsistency
                    </visitors>
                </configuration>
            </plugin>
Of course you have to add our artifactory to your maven settings.xml:
            <repositories>
                <repository>
                    <id>itcrowd.pl</id>
                    <url>http://artifactory.itcrowd.pl/repo</url>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>itcrowd.pl</id>
                    <url>http://artifactory.itcrowd.pl/repo</url>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
Downloads are available at our Artifactory : itcrowd-findbugs-domain-1.0.0.jar.
Sources are hosted at https://github.com/it-crowd/itcrowd-findbugs-domain

1 comment:

  1. Still, take the extra time to certain that|be sure that|ensure that} the bonuses and promotions are best suited for you. Every cell casino will offer you a great new participant promotion, however it is still important to consider about|to contemplate} whether it is the proper deal for you. For instance, a sign-up bonus that gives a huge number of free spins on slots is still nice, however 바카라사이트 not best suited to a participant who prefers blackjack.

    ReplyDelete