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

ENH: Support different ColumnDefinition for different database platforms #2559

Closed
nPraml opened this issue Feb 11, 2022 · 4 comments · Fixed by #2563
Closed

ENH: Support different ColumnDefinition for different database platforms #2559

nPraml opened this issue Feb 11, 2022 · 4 comments · Fixed by #2563
Assignees
Milestone

Comments

@nPraml
Copy link
Contributor

nPraml commented Feb 11, 2022

Hi @rbygrave ,

with db2 we have the problem, we define columns as blob (without length):

Java Code:

  public class ReportResult(
  ...
  @Lob
  private File fileContent;
  ...
  )

generated init migration:

  create table report_result(
  ...
  file_content      blob,
  ...
  )

In this case we can only save a file that is not bigger as 1 MB (default size of db2 blob).
We would like to define the columnDefinition for a field more precise: different length for different platforms.

We would like to create a new annotation (e.g. DbColumn?) which uses the javax.persistence.@Column as a base and can be defined for every platform different:

  public class ReportResult(
  ...
  @Lob
  @DbColumn(columnDefinition = "blob(64M)", platform = Platfrom.DB2)
  // for all other platforms default generated type
  private File fileContent;
  ...
  )

What do you think about it?

@nPraml nPraml changed the title ColumnDefinition Different ColumnDefinition for different platforms Feb 11, 2022
@nPraml
Copy link
Contributor Author

nPraml commented Feb 15, 2022

I tried to implement the new annotation, but it would be a huge modification. The xmls of the column definitions had to be also modified (list of platform-columnDefinition pairs) and lot of code in ebean.

We designed a new proposed solution which has only small code changes in ebean but it "redefines" the usage of @Column. (It's backward compatible)

Example:

 @Column(columnDefinition = "db2;blob(64M);sqlserver,h2;varchar(227);varchar(127)")
  String description;

Using the pattern

 @Column(columnDefinition = "PLATFORM1;DEFINITION1;PLATFORM2,PLATFORM3;DEFINITON2;DEFINITON-DEFAULT")

We use semicolon as separator because it's very unlikely that it would be used for column definition.

You can check the ebean code change here: FOCONIS@3d83c6b

What do you think about this?

@rbygrave
Copy link
Member

I like it - nice approach !!

@nPraml
Copy link
Contributor Author

nPraml commented Feb 17, 2022

Thank you! I opened a PR for it: #2563

@rbygrave rbygrave linked a pull request Feb 22, 2022 that will close this issue
@rbygrave rbygrave added this to the 12.15.1 milestone Feb 22, 2022
@rbygrave rbygrave changed the title Different ColumnDefinition for different platforms ENH: Support different ColumnDefinition for different database platforms Feb 22, 2022
@rbygrave
Copy link
Member

Closing with the merged PR. Nice work !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants