kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 13df164b0d2d5c435f3d6d93ef73e760aaf34f4a58f0ce201513e40c0334749d |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-01-28 12:24 +01:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-01-28 12:54 +01:00 |
| Parents | 0aa90c5ece06 |
2 files changed
modified driver-core/src/main/java/com/datastax/driver/core/DataType.java +32 −1
| @@ -496,7 +496,7 @@ | ||
| 496 | 496 | * @param typeClassName the server-side fully qualified class name for the type. |
| 497 | 497 | * @return the custom type for {@code typeClassName}. |
| 498 | 498 | */ |
| 499 | - public static DataType custom(String typeClassName) { | |
| 499 | + public static DataType.CustomType custom(String typeClassName) { | |
| 500 | 500 | if (typeClassName == null) |
| 501 | 501 | throw new NullPointerException(); |
| 502 | 502 | return new DataType.CustomType(Name.CUSTOM, typeClassName); |
| @@ -600,6 +600,10 @@ | ||
| 600 | 600 | return toString(); |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | + /** | |
| 604 | + * Instances of this class represent CQL native types, | |
| 605 | + * also known as CQL primitive types. | |
| 606 | + */ | |
| 603 | 607 | public static class NativeType extends DataType { |
| 604 | 608 | |
| 605 | 609 | private NativeType(DataType.Name name) { |
| @@ -633,6 +637,10 @@ | ||
| 633 | 637 | } |
| 634 | 638 | } |
| 635 | 639 | |
| 640 | + /** | |
| 641 | + * Instances of this class represent collection types, that is, | |
| 642 | + * lists, sets or maps. | |
| 643 | + */ | |
| 636 | 644 | public static class CollectionType extends DataType { |
| 637 | 645 | |
| 638 | 646 | private final List<DataType> typeArguments; |
| @@ -691,6 +699,18 @@ | ||
| 691 | 699 | } |
| 692 | 700 | } |
| 693 | 701 | |
| 702 | + /** | |
| 703 | + * A "custom" type is a type that cannot be expressed as a CQL type. | |
| 704 | + * <p/> | |
| 705 | + * Each custom type is merely identified by the fully qualified | |
| 706 | + * {@link #getCustomTypeClassName() class name} | |
| 707 | + * that represents this type server-side. | |
| 708 | + * <p/> | |
| 709 | + * The driver provides a minimal support for such types through | |
| 710 | + * instances of this class. | |
| 711 | + * <p/> | |
| 712 | + * A codec for custom types can be obtained via {@link TypeCodec#custom(CustomType)}. | |
| 713 | + */ | |
| 694 | 714 | public static class CustomType extends DataType { |
| 695 | 715 | |
| 696 | 716 | private final String customClassName; |
| @@ -705,6 +725,17 @@ | ||
| 705 | 725 | return false; |
| 706 | 726 | } |
| 707 | 727 | |
| 728 | + /** | |
| 729 | + * Returns the fully qualified name | |
| 730 | + * of the subtype of | |
| 731 | + * {@code org.apache.cassandra.db.marshal.AbstractType} | |
| 732 | + * that represents this type server-side. | |
| 733 | + * | |
| 734 | + * @return the fully qualified name | |
| 735 | + * of the subtype of | |
| 736 | + * {@code org.apache.cassandra.db.marshal.AbstractType} | |
| 737 | + * that represents this type server-side. | |
| 738 | + */ | |
| 708 | 739 | public String getCustomTypeClassName() { |
| 709 | 740 | return customClassName; |
| 710 | 741 | } |
modified driver-core/src/main/java/com/datastax/driver/core/TypeCodec.java +12 −2
| @@ -378,9 +378,19 @@ | ||
| 378 | 378 | |
| 379 | 379 | /** |
| 380 | 380 | * Return a newly-created codec for the given CQL custom type. |
| 381 | - * The returned codec maps the custom type into the Java type {@link ByteBuffer}. | |
| 382 | - * This method provides a (very lightweight) support for Cassandra | |
| 381 | + * <p/> | |
| 382 | + * The returned codec maps the custom type into the Java type {@link ByteBuffer}, | |
| 383 | + * thus providing a (very lightweight) support for Cassandra | |
| 383 | 384 | * types that do not have a CQL equivalent. |
| 385 | + * <p/> | |
| 386 | + * Note that the returned codec assumes that CQL literals for the given custom | |
| 387 | + * type are expressed in binary form as well, e.g. {@code 0xcafebabe}. If this is | |
| 388 | + * not the case, <em>the returned codec might be unable to {@link #parse(String) parse} | |
| 389 | + * and {@link #format(Object) format} literals for this type</em>. | |
| 390 | + * This is notoriously true for types inheriting from | |
| 391 | + * {@code org.apache.cassandra.db.marshal.AbstractCompositeType}, whose CQL literals | |
| 392 | + * are actually expressed as quoted strings. | |
| 393 | + * <p/> | |
| 384 | 394 | * This method does not cache returned instances and returns a newly-allocated object |
| 385 | 395 | * at each invocation. |
| 386 | 396 | * |