Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary length constraints from VARCHAR(N) columns #579

Merged
merged 15 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/org/dependencytrack/model/Analysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ public class Analysis implements Serializable {
private Vulnerability vulnerability;

@Persistent(defaultFetchGroup = "true")
@Column(name = "STATE", jdbcType = "VARCHAR", allowsNull = "false")
@Column(name = "STATE", allowsNull = "false")
@NotNull
private AnalysisState analysisState;

@Persistent(defaultFetchGroup = "true")
@Column(name = "JUSTIFICATION", jdbcType = "VARCHAR", allowsNull = "true")
@Column(name = "JUSTIFICATION", allowsNull = "true")
@NotNull
private AnalysisJustification analysisJustification;

@Persistent(defaultFetchGroup = "true")
@Column(name = "RESPONSE", jdbcType = "VARCHAR", allowsNull = "true")
@Column(name = "RESPONSE", allowsNull = "true")
sahibamittal marked this conversation as resolved.
Show resolved Hide resolved
@NotNull
private AnalysisResponse analysisResponse;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class AnalysisComment implements Serializable {
private String comment;

@Persistent(defaultFetchGroup = "true")
@Column(name = "COMMENTER")
@Column(name = "COMMENTER", jdbcType = "CLOB")
@JsonDeserialize(using = TrimmedStringDeserializer.class)
private String commenter;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/dependencytrack/model/Bom.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ public String getFormatLongName() {
private Date imported;

@Persistent
@Column(name = "BOM_FORMAT")
@Column(name = "BOM_FORMAT", jdbcType = "CLOB")
private String bomFormat;

@Persistent
@Column(name = "SPEC_VERSION")
@Column(name = "SPEC_VERSION", jdbcType = "CLOB")
private String specVersion;

@Persistent
@Column(name = "BOM_VERSION")
private Integer bomVersion;

@Persistent
@Column(name = "SERIAL_NUMBER")
@Column(name = "SERIAL_NUMBER", jdbcType = "CLOB")
private String serialNumber;

@Persistent(defaultFetchGroup = "true")
Expand Down
43 changes: 15 additions & 28 deletions src/main/java/org/dependencytrack/model/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ public enum FetchGroup {
private String author;

@Persistent
@Column(name = "PUBLISHER", jdbcType = "VARCHAR")
@Size(max = 255)
@Column(name = "PUBLISHER", jdbcType = "CLOB")
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The publisher may only contain printable characters")
private String publisher;

Expand All @@ -128,44 +127,39 @@ public enum FetchGroup {
private OrganizationalEntity supplier;

@Persistent
@Column(name = "GROUP", jdbcType = "VARCHAR")
@Column(name = "GROUP", jdbcType = "CLOB")
@Index(name = "COMPONENT_GROUP_IDX")
@Size(max = 255)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The group may only contain printable characters")
private String group;

@Persistent
@Column(name = "NAME", jdbcType = "VARCHAR", allowsNull = "false")
@Column(name = "NAME", allowsNull = "false", jdbcType = "CLOB")
@Index(name = "COMPONENT_NAME_IDX")
@NotBlank
@Size(min = 1, max = 255)
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The name may only contain printable characters")
private String name;

@Persistent
@Column(name = "VERSION", jdbcType = "VARCHAR")
@Size(max = 255)
@Column(name = "VERSION", jdbcType = "CLOB")
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The version may only contain printable characters")
private String version;

@Persistent
@Column(name = "CLASSIFIER", jdbcType = "VARCHAR")
@Column(name = "CLASSIFIER")
sahibamittal marked this conversation as resolved.
Show resolved Hide resolved
@Index(name = "COMPONENT_CLASSIFIER_IDX")
@Extension(vendorName = "datanucleus", key = "enum-check-constraint", value = "true")
private Classifier classifier;

@Persistent
@Column(name = "FILENAME", jdbcType = "VARCHAR")
@Size(max = 255)
@Column(name = "FILENAME", jdbcType = "CLOB")
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = RegexSequence.Definition.FS_DIRECTORY_NAME, message = "The specified filename is not valid and cannot be used as a filename")
private String filename;

@Persistent
@Column(name = "EXTENSION", jdbcType = "VARCHAR")
@Size(max = 255)
@Column(name = "EXTENSION", jdbcType = "CLOB")
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = RegexSequence.Definition.FS_FILE_NAME, message = "The specified filename extension is not valid and cannot be used as a extension")
private String extension;
Expand Down Expand Up @@ -244,31 +238,28 @@ public enum FetchGroup {

@Persistent
@Index(name = "COMPONENT_CPE_IDX")
@Column(name = "CPE")
@Size(max = 255)
@Column(name = "CPE", jdbcType = "CLOB")
//Patterns obtained from https://csrc.nist.gov/schema/cpe/2.3/cpe-naming_2.3.xsd
@Pattern(regexp = "(cpe:2\\.3:[aho\\*\\-](:(((\\?*|\\*?)([a-zA-Z0-9\\-\\._]|(\\\\[\\\\\\*\\?!\"#$$%&'\\(\\)\\+,/:;<=>@\\[\\]\\^`\\{\\|}~]))+(\\?*|\\*?))|[\\*\\-])){5}(:(([a-zA-Z]{2,3}(-([a-zA-Z]{2}|[0-9]{3}))?)|[\\*\\-]))(:(((\\?*|\\*?)([a-zA-Z0-9\\-\\._]|(\\\\[\\\\\\*\\?!\"#$$%&'\\(\\)\\+,/:;<=>@\\[\\]\\^`\\{\\|}~]))+(\\?*|\\*?))|[\\*\\-])){4})|([c][pP][eE]:/[AHOaho]?(:[A-Za-z0-9\\._\\-~%]*){0,6})", message = "The CPE must conform to the CPE v2.2 or v2.3 specification defined by NIST")
private String cpe;

@Persistent(defaultFetchGroup = "true")
@Index(name = "COMPONENT_PURL_IDX")
@Column(name = "PURL", jdbcType = "VARCHAR", length = 1024)
@Size(max = 1024)
@Column(name = "PURL", jdbcType = "CLOB")
@com.github.packageurl.validator.PackageURL
@JsonDeserialize(using = TrimmedStringDeserializer.class)
private String purl;

@Persistent(defaultFetchGroup = "true")
@Index(name = "COMPONENT_PURL_COORDINATES_IDX")
@Size(max = 255)
@Column(name = "PURLCOORDINATES", jdbcType = "CLOB")
@com.github.packageurl.validator.PackageURL
@JsonDeserialize(using = TrimmedStringDeserializer.class)
private String purlCoordinates; // Field should contain only type, namespace, name, and version. Everything up to the qualifiers

@Persistent
@Column(name = "SWIDTAGID")
@Column(name = "SWIDTAGID", jdbcType = "CLOB")
@Index(name = "COMPONENT_SWID_TAGID_IDX")
@Size(max = 255)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The SWID tagId may only contain printable characters")
private String swidTagId;

Expand All @@ -278,22 +269,19 @@ public enum FetchGroup {
private Boolean internal;

@Persistent
@Column(name = "DESCRIPTION", jdbcType = "VARCHAR", length = 1024)
@Size(max = 1024)
@Column(name = "DESCRIPTION", jdbcType = "CLOB")
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The description may only contain printable characters")
private String description;

@Persistent
@Column(name = "COPYRIGHT", jdbcType = "VARCHAR", length = 1024)
@Size(max = 1024)
@Column(name = "COPYRIGHT", jdbcType = "CLOB")
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The copyright may only contain printable characters")
private String copyright;

@Persistent
@Column(name = "LICENSE", jdbcType = "VARCHAR")
@Size(max = 255)
@Column(name = "LICENSE", jdbcType = "CLOB")
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The license may only contain printable characters")
private String license;
Expand All @@ -305,8 +293,7 @@ public enum FetchGroup {
private String licenseExpression;

@Persistent
@Column(name = "LICENSE_URL", jdbcType = "VARCHAR")
@Size(max = 255)
@Column(name = "LICENSE_URL", jdbcType = "CLOB")
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = RegexSequence.Definition.URL, message = "The license URL must be a valid URL")
private String licenseUrl;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/dependencytrack/model/Cwe.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public class Cwe implements Serializable {
private int cweId;

@Persistent
@Column(name = "NAME", jdbcType = "VARCHAR", allowsNull = "false")
@Size(max = 255)
@Column(name = "NAME", allowsNull = "false", jdbcType = "CLOB")
@NotNull
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The name may only contain printable characters")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public class FindingAttribution implements Serializable {
private Vulnerability vulnerability;

@Persistent
@Column(name = "ALT_ID", allowsNull = "true")
@Column(name = "ALT_ID", allowsNull = "true", jdbcType = "CLOB")
private String alternateIdentifier;

@Persistent
@Column(name = "REFERENCE_URL", allowsNull = "true")
@Column(name = "REFERENCE_URL", allowsNull = "true", jdbcType = "CLOB")
private String referenceUrl;

@Persistent(customValueStrategy = "uuid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import javax.jdo.annotations.Unique;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;

Expand Down Expand Up @@ -75,9 +74,8 @@ public void setSha512(String sha512) {
private String sha512;

@Persistent
@Column(name = "PURL", allowsNull = "false", jdbcType = "VARCHAR", length = 1024)
@Column(name = "PURL", allowsNull = "false", jdbcType = "CLOB")
@Index(name = "PURL_IDX")
@Size(max = 1024)
@com.github.packageurl.validator.PackageURL
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Unique
Expand All @@ -97,12 +95,12 @@ public void setSha512(String sha512) {
private Date lastFetch;

@Persistent
@Column(name = "STATUS", jdbcType = "VARCHAR", length = 64)
@Column(name = "STATUS")
sahibamittal marked this conversation as resolved.
Show resolved Hide resolved
@Extension(vendorName = "datanucleus", key = "enum-check-constraint", value = "true")
private FetchStatus status;

@Persistent
@Column(name = "REPOSITORY_URL", jdbcType = "VARCHAR", length = 1024)
@Column(name = "REPOSITORY_URL", jdbcType = "CLOB")
private String repositoryUrl;


Expand Down
7 changes: 2 additions & 5 deletions src/main/java/org/dependencytrack/model/License.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -102,11 +101,10 @@ public enum FetchGroup {
* The String representation of the license name (i.e. Apache License 2.0).
*/
@Persistent(defaultFetchGroup = "true")
@Column(name = "NAME", allowsNull = "false")
@Column(name = "NAME", allowsNull = "false", jdbcType = "CLOB")
@Index(name = "LICENSE_NAME_IDX")
@JsonProperty(value = "name")
@NotBlank
@Size(min = 1, max = 255)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The name may only contain printable characters")
private String name;

Expand Down Expand Up @@ -151,12 +149,11 @@ public enum FetchGroup {
* The SPDX defined licenseId (i.e. Apache-2.0).
*/
@Persistent(defaultFetchGroup = "true")
@Column(name = "LICENSEID")
@Column(name = "LICENSEID", jdbcType = "CLOB")
@Index(name = "LICENSE_LICENSEID_IDX", unique = "true")
@JsonProperty(value = "licenseId")
@JsonAlias(value = "licenseExceptionId")
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Size(min = 1, max = 255)
@NotBlank
@Pattern(regexp = RegexSequence.Definition.STRING_IDENTIFIER, message = "The licenseId may only contain alpha, numeric, and specific symbols _-.+")
private String licenseId;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/dependencytrack/model/LicenseGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
Expand All @@ -62,10 +61,9 @@ public class LicenseGroup implements Serializable {
* The String representation of the license group name (i.e. Copyleft).
*/
@Persistent
@Column(name = "NAME", allowsNull = "false")
@Column(name = "NAME", allowsNull = "false", jdbcType = "CLOB")
@Index(name = "LICENSEGROUP_NAME_IDX")
@NotBlank
@Size(min = 1, max = 255)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The name may only contain printable characters")
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import javax.jdo.annotations.Unique;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.UUID;

Expand Down Expand Up @@ -73,22 +72,19 @@ public enum FetchGroup {
private long id;

@Persistent(defaultFetchGroup = "true")
@Column(name = "NAME", allowsNull = "false")
@Column(name = "NAME", allowsNull = "false", jdbcType = "CLOB")
@NotBlank
@Size(min = 1, max = 255)
@JsonDeserialize(using = TrimmedStringDeserializer.class)
private String name;

@Persistent(defaultFetchGroup = "true")
@Column(name = "DESCRIPTION")
@Size(min = 0, max = 1024)
@Column(name = "DESCRIPTION", jdbcType = "CLOB")
@JsonDeserialize(using = TrimmedStringDeserializer.class)
private String description;

@Persistent(defaultFetchGroup = "true")
@Column(name = "PUBLISHER_CLASS", length = 1024, allowsNull = "false")
@Column(name = "PUBLISHER_CLASS", allowsNull = "false", jdbcType = "CLOB")
@NotBlank
@Size(min = 1, max = 1024)
@JsonDeserialize(using = TrimmedStringDeserializer.class)
private String publisherClass;

Expand All @@ -98,9 +94,8 @@ public enum FetchGroup {
private String template;

@Persistent(defaultFetchGroup = "true")
@Column(name = "TEMPLATE_MIME_TYPE", allowsNull = "false")
@Column(name = "TEMPLATE_MIME_TYPE", allowsNull = "false", jdbcType = "CLOB")
@NotBlank
@Size(min = 1, max = 255)
@JsonDeserialize(using = TrimmedStringDeserializer.class)
private String templateMimeType;

Expand Down
13 changes: 5 additions & 8 deletions src/main/java/org/dependencytrack/model/NotificationRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -74,9 +73,8 @@ public class NotificationRule implements Serializable {
* The String representation of the name of the notification.
*/
@Persistent
@Column(name = "NAME", allowsNull = "false")
@Column(name = "NAME", allowsNull = "false", jdbcType = "CLOB")
@NotBlank
@Size(min = 1, max = 255)
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The name may only contain printable characters")
private String name;
Expand All @@ -102,12 +100,12 @@ public class NotificationRule implements Serializable {
private boolean logSuccessfulPublish;

@Persistent(defaultFetchGroup = "true")
@Column(name = "SCOPE", jdbcType = "VARCHAR", allowsNull = "false")
@Column(name = "SCOPE", allowsNull = "false")
sahibamittal marked this conversation as resolved.
Show resolved Hide resolved
@NotNull
private NotificationScope scope;

@Persistent(defaultFetchGroup = "true")
@Column(name = "NOTIFICATION_LEVEL", jdbcType = "VARCHAR")
@Column(name = "NOTIFICATION_LEVEL")
sahibamittal marked this conversation as resolved.
Show resolved Hide resolved
private NotificationLevel notificationLevel;

@Persistent(table = "NOTIFICATIONRULE_PROJECTS", defaultFetchGroup = "true")
Expand All @@ -123,12 +121,11 @@ public class NotificationRule implements Serializable {
private List<Team> teams;

@Persistent
@Column(name = "NOTIFY_ON", length = 1024)
@Column(name = "NOTIFY_ON", jdbcType = "CLOB")
private String notifyOn;

@Persistent
@Column(name = "MESSAGE", length = 1024)
@Size(max = 1024)
@Column(name = "MESSAGE", jdbcType = "CLOB")
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = RegexSequence.Definition.PRINTABLE_CHARS, message = "The message may only contain printable characters")
private String message;
Expand Down
Loading
Loading