Skip to content

JAVA-933: Consider allowing users to override default codecs.#469

Closed
adutra wants to merge 7 commits into
2.2from
java933
Closed

JAVA-933: Consider allowing users to override default codecs.#469
adutra wants to merge 7 commits into
2.2from
java933

Conversation

@adutra
Copy link
Copy Markdown
Contributor

@adutra adutra commented Oct 6, 2015

Overview of changes:

  • The overriding of a single codec takes place in CodecRegistry.register() : if the exact same CQL-Java mapping already exists, the existing codec is replaced by the new one (note the additional log warning).
  • The on the fly overriding of collection codecs is more complex: there is now a new CodecFactory class that can be subclassed for this purpose.
  • Behavior in case of overlapping codecs didn't change: it is still possible to register more than one codec for the same CQL type.

Note: the CodecFactory class allow users to override the on-the-fly instantiation mechanism, but we could live without it. If the user knows which exact list types he needs to handle, the following code:

CodecFactory factory = new DefaultCodecFactory() {
    protected <T> TypeCodec<List<T>> newListCodec(TypeCodec<T> eltCodec) {
        return new MyListCodec<T>(eltCodec);
    }
};
CodecRegistry registry = new CodecRegistry(factory);

Could easily be replaced with:

CodecRegistry registry = new CodecRegistry();
registry.register(new MyListCodec(IntCodec.instance));
registry.register(new MyListCodec(VarcharCodec.instance));
// etc. register all list types required by the application

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is basically created out of the maybeCreateCodec methods in CodecRegistry.

@adutra
Copy link
Copy Markdown
Contributor Author

adutra commented Oct 8, 2015

Closing as the corresponding ticket has been closed as Won't Fix.

@adutra adutra closed this Oct 8, 2015
@adutra adutra deleted the java933 branch March 23, 2016 10:43
Sfurti-yb pushed a commit to yugabyte/cassandra-java-driver that referenced this pull request Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant