Skip to content

JAVA-2263: Add optional schema validation#1300

Merged
tomekl007 merged 69 commits into
4.xfrom
java2263_rebase
Jan 27, 2020
Merged

JAVA-2263: Add optional schema validation#1300
tomekl007 merged 69 commits into
4.xfrom
java2263_rebase

Conversation

@tomekl007
Copy link
Copy Markdown
Contributor

@tomekl007 tomekl007 commented Jul 17, 2019

todo:

  • for the case where keyspace == null, try session.getKeyspace()
  • enabling schema validation through an annotation is a bit too static. It would probably be more flexible with a runtime parameter:
new InventoryMapperBuilder(session).setSchemaValidation(true).build()
  • trying to match a table and then falling back to a UDT is a good default. But maybe we could also have an optional annotation to provide hints to the mapper (keeping the name generic because other hints might be useful in the future):
@Entity
@SchemaHint(targetElement = TABLE)
public class Product { ... }
  • we could also validate the partition key and clustering columns
  • propagate isSchemaValidationEnabled in InventoryMapperBuilder to prevent backward compatibility problems
  • similarly, I think we have enough information to validate the types: we know the Java type from EntityDefinition, and the CQL type at runtime from the schema metadata. So we could call codecRegistry.codecFor at runtime, and fail if it returns no codec.
  • we recently introduced an EntityHelperBase parent class. There's probably opportunities to move some code there instead of generating it, for example methods such as:
    void validateColumnExists(TableMetadata table, String columnName, GenericType<?> javaType)
  • 👍 for reporting all missing columns instead of failing on the first one. We could extend this to all the entity helpers of a given DAO, this way we validate the DAO's complete schema in one go.
  • docs

@tomekl007 tomekl007 added this to the 4.2.0 milestone Jul 17, 2019
@tomekl007 tomekl007 added the mapper4 Driver 4 object mapper (sub-tasks of JAVA-2078) label Jul 17, 2019
@tomekl007 tomekl007 changed the title Java2263 rebase JAVA-2263: Add optional schema validation Jul 17, 2019
@tomekl007
Copy link
Copy Markdown
Contributor Author

comments in closed branch: #1245

@adutra adutra modified the milestones: 4.2.0, 4.3.0 Sep 23, 2019
@tomekl007 tomekl007 requested a review from olim7t December 16, 2019 14:12
Copy link
Copy Markdown
Contributor

@olim7t olim7t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrmm I thought I only replied directly to existing comments, but Github is forcing me to create another review... Hope nothing was lost in the process.

@olim7t olim7t modified the milestones: 4.4.0, 4.5.0 Jan 15, 2020
…with detailed message, and keyspace not present second
@tomekl007 tomekl007 requested a review from olim7t January 17, 2020 09:48
tomekl007 and others added 6 commits January 17, 2020 10:53
…va2263_rebase

# Conflicts:
#	changelog/README.md
#	manual/mapper/mapper/README.md
this.keyspaceId defaults to the entity's default keyspace if the context
doesn't specify any (see EntityHelperBase constructor). This is what we
want here.
This made the validation code fail when run against DSE. getColumns()
can be accessed on the parent interface.
@olim7t
Copy link
Copy Markdown
Contributor

olim7t commented Jan 24, 2020

I had a few more trivial remarks, I pushed the changes directly because I don't think they are controversial.
LGTM.

@tomekl007 tomekl007 merged commit 48bac34 into 4.x Jan 27, 2020
@adutra adutra deleted the java2263_rebase branch July 23, 2020 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mapper4 Driver 4 object mapper (sub-tasks of JAVA-2078)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants