# gg-9470-rename
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/e04165bb Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/e04165bb Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/e04165bb Branch: refs/heads/master Commit: e04165bbe46a93474acd1d132bfb4d2afe7012e8 Parents: 3dcb522 Author: sboikov <sboi...@gridgain.com> Authored: Thu Dec 4 22:39:57 2014 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Thu Dec 4 22:40:11 2014 +0300 ---------------------------------------------------------------------- .../client/GridClientPortableArgumentTask.java | 2 +- .../gridgain/client/GridClientTestPortable.java | 2 +- .../GridClientTestPortableAffinityKeyTask.java | 2 +- .../clients/src/test/resources/spring-cache.xml | 4 +- .../src/test/resources/spring-server-node.xml | 10 +- .../test/resources/spring-server-ssl-node.xml | 4 +- .../java/org/apache/ignite/IgnitePortables.java | 32 +-- .../configuration/IgniteConfiguration.java | 2 +- .../ignite/portables/GridPortableBuilder.java | 129 +++++++++ .../portables/GridPortableConfiguration.java | 181 +++++++++++++ .../ignite/portables/GridPortableException.java | 49 ++++ .../ignite/portables/GridPortableIdMapper.java | 47 ++++ .../GridPortableInvalidClassException.java | 50 ++++ .../portables/GridPortableMarshalAware.java | 40 +++ .../ignite/portables/GridPortableMetadata.java | 53 ++++ .../ignite/portables/GridPortableObject.java | 166 ++++++++++++ .../ignite/portables/GridPortableRawReader.java | 214 +++++++++++++++ .../ignite/portables/GridPortableRawWriter.java | 197 ++++++++++++++ .../ignite/portables/GridPortableReader.java | 263 +++++++++++++++++++ .../portables/GridPortableSerializer.java | 39 +++ .../GridPortableTypeConfiguration.java | 187 +++++++++++++ .../ignite/portables/GridPortableWriter.java | 242 +++++++++++++++++ .../org/apache/ignite/portables/package.html | 15 ++ .../gridgain/client/GridClientCacheFlag.java | 4 +- .../client/GridClientConfiguration.java | 2 +- .../grid/cache/GridCacheConfiguration.java | 3 +- .../grid/cache/GridCacheProjection.java | 3 +- .../grid/cache/store/GridCacheStore.java | 5 +- .../grid/dotnet/GridDotNetConfiguration.java | 2 +- .../dotnet/GridDotNetPortableConfiguration.java | 2 +- .../GridDotNetPortableTypeConfiguration.java | 2 +- .../gridgain/grid/kernal/GridPortablesImpl.java | 2 +- .../managers/indexing/GridIndexingManager.java | 2 +- .../affinity/GridAffinityAssignmentCache.java | 2 +- .../processors/cache/GridCacheAdapter.java | 2 +- .../processors/cache/GridCacheContext.java | 4 +- .../GridCacheDefaultAffinityKeyMapper.java | 2 +- .../cache/GridCacheProjectionImpl.java | 2 +- .../cache/GridCacheTxLocalAdapter.java | 2 +- .../cache/affinity/GridCacheAffinityImpl.java | 2 +- .../dht/GridPartitionedGetFuture.java | 2 +- .../dht/atomic/GridDhtAtomicCache.java | 2 +- .../dht/colocated/GridDhtColocatedCache.java | 2 +- .../distributed/near/GridNearGetFuture.java | 2 +- .../portable/GridPortableProcessor.java | 3 +- .../portable/os/GridOsPortableProcessor.java | 2 +- .../message/GridClientAbstractMessage.java | 3 +- .../GridClientAuthenticationRequest.java | 2 +- .../message/GridClientCacheQueryRequest.java | 2 +- .../client/message/GridClientCacheRequest.java | 2 +- .../message/GridClientGetMetaDataRequest.java | 2 +- .../client/message/GridClientLogRequest.java | 2 +- .../message/GridClientMetaDataResponse.java | 2 +- .../rest/client/message/GridClientNodeBean.java | 2 +- .../message/GridClientNodeMetricsBean.java | 2 +- .../message/GridClientPortableMetaData.java | 2 +- .../message/GridClientPutMetaDataRequest.java | 2 +- .../rest/client/message/GridClientResponse.java | 2 +- .../client/message/GridClientTaskRequest.java | 2 +- .../message/GridClientTaskResultBean.java | 2 +- .../message/GridClientTopologyRequest.java | 2 +- .../cache/GridCacheClientQueryResult.java | 2 +- .../metadata/GridPortableMetadataHandler.java | 2 +- .../handlers/task/GridTaskCommandHandler.java | 2 +- .../VisorPortableMetadataCollectorTask.java | 2 +- .../grid/portables/GridPortableBuilder.java | 129 --------- .../portables/GridPortableConfiguration.java | 181 ------------- .../grid/portables/GridPortableException.java | 49 ---- .../grid/portables/GridPortableIdMapper.java | 47 ---- .../GridPortableInvalidClassException.java | 50 ---- .../portables/GridPortableMarshalAware.java | 40 --- .../grid/portables/GridPortableMetadata.java | 53 ---- .../grid/portables/GridPortableObject.java | 166 ------------ .../grid/portables/GridPortableRawReader.java | 214 --------------- .../grid/portables/GridPortableRawWriter.java | 197 -------------- .../grid/portables/GridPortableReader.java | 263 ------------------- .../grid/portables/GridPortableSerializer.java | 39 --- .../GridPortableTypeConfiguration.java | 187 ------------- .../grid/portables/GridPortableWriter.java | 242 ----------------- .../org/gridgain/grid/portables/package.html | 15 -- .../grid/security/GridSecurityCredentials.java | 2 +- .../java/org/gridgain/grid/util/GridUtils.java | 2 +- .../util/portable/GridPortableRawReaderEx.java | 4 +- .../util/portable/GridPortableRawWriterEx.java | 4 +- .../GridCacheOffHeapTieredAbstractSelfTest.java | 2 +- ...heOffHeapTieredEvictionAbstractSelfTest.java | 2 +- .../GridCacheSwapScanQueryAbstractSelfTest.java | 2 +- .../dataload/GridDataLoaderImplSelfTest.java | 2 +- 88 files changed, 1955 insertions(+), 1962 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/clients/src/test/java/org/gridgain/client/GridClientPortableArgumentTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/client/GridClientPortableArgumentTask.java b/modules/clients/src/test/java/org/gridgain/client/GridClientPortableArgumentTask.java index de9ed22..051c52b 100644 --- a/modules/clients/src/test/java/org/gridgain/client/GridClientPortableArgumentTask.java +++ b/modules/clients/src/test/java/org/gridgain/client/GridClientPortableArgumentTask.java @@ -9,8 +9,8 @@ package org.gridgain.client; +import org.apache.ignite.portables.*; import org.gridgain.grid.*; -import org.gridgain.grid.portables.*; import java.util.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortable.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortable.java b/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortable.java index c5f2f40..b9d948c 100644 --- a/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortable.java +++ b/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortable.java @@ -9,7 +9,7 @@ package org.gridgain.client; -import org.gridgain.grid.portables.*; +import org.apache.ignite.portables.*; import org.gridgain.grid.util.typedef.internal.*; import java.io.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortableAffinityKeyTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortableAffinityKeyTask.java b/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortableAffinityKeyTask.java index 90ed8bd..f94481d 100644 --- a/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortableAffinityKeyTask.java +++ b/modules/clients/src/test/java/org/gridgain/client/GridClientTestPortableAffinityKeyTask.java @@ -12,9 +12,9 @@ package org.gridgain.client; import org.apache.ignite.*; import org.apache.ignite.cluster.*; import org.apache.ignite.compute.*; +import org.apache.ignite.portables.*; import org.apache.ignite.resources.*; import org.gridgain.grid.*; -import org.gridgain.grid.portables.*; import org.jetbrains.annotations.*; import java.util.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/clients/src/test/resources/spring-cache.xml ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/resources/spring-cache.xml b/modules/clients/src/test/resources/spring-cache.xml index 79c10dc..ee34262 100644 --- a/modules/clients/src/test/resources/spring-cache.xml +++ b/modules/clients/src/test/resources/spring-cache.xml @@ -236,10 +236,10 @@ </property> <property name="portableConfiguration"> - <bean class="org.gridgain.grid.portables.GridPortableConfiguration"> + <bean class="org.apache.ignite.portables.GridPortableConfiguration"> <property name="typeConfigurations"> <list> - <bean class="org.gridgain.grid.portables.GridPortableTypeConfiguration"> + <bean class="org.apache.ignite.portables.GridPortableTypeConfiguration"> <property name="className" value="org.gridgain.client.GridClientTestPortable"/> </bean> </list> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/clients/src/test/resources/spring-server-node.xml ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/resources/spring-server-node.xml b/modules/clients/src/test/resources/spring-server-node.xml index c5d9e8a..2c4b58b 100644 --- a/modules/clients/src/test/resources/spring-server-node.xml +++ b/modules/clients/src/test/resources/spring-server-node.xml @@ -70,19 +70,19 @@ </property> <property name="portableConfiguration"> - <bean class="org.gridgain.grid.portables.GridPortableConfiguration"> + <bean class="org.apache.ignite.portables.GridPortableConfiguration"> <property name="typeConfigurations"> <list> - <bean class="org.gridgain.grid.portables.GridPortableTypeConfiguration"> + <bean class="org.apache.ignite.portables.GridPortableTypeConfiguration"> <property name="className" value="org.gridgain.client.GridClientTestPortable"/> </bean> - <bean class="org.gridgain.grid.portables.GridPortableTypeConfiguration"> + <bean class="org.apache.ignite.portables.GridPortableTypeConfiguration"> <property name="className" value="org.gridgain.client.model.GridPortablePerson"/> </bean> - <bean class="org.gridgain.grid.portables.GridPortableTypeConfiguration"> + <bean class="org.apache.ignite.portables.GridPortableTypeConfiguration"> <property name="className" value="org.gridgain.client.model.GridImplicitPortablePerson"/> </bean> - <bean class="org.gridgain.grid.portables.GridPortableTypeConfiguration"> + <bean class="org.apache.ignite.portables.GridPortableTypeConfiguration"> <property name="className" value="GridNoDefPortablePerson"/> </bean> </list> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/clients/src/test/resources/spring-server-ssl-node.xml ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/resources/spring-server-ssl-node.xml b/modules/clients/src/test/resources/spring-server-ssl-node.xml index 27eb154..144bf45 100644 --- a/modules/clients/src/test/resources/spring-server-ssl-node.xml +++ b/modules/clients/src/test/resources/spring-server-ssl-node.xml @@ -318,10 +318,10 @@ <property name="systemExecutorServiceShutdown" value="true"/> <property name="portableConfiguration"> - <bean class="org.gridgain.grid.portables.GridPortableConfiguration"> + <bean class="org.apache.ignite.portables.GridPortableConfiguration"> <property name="typeConfigurations"> <list> - <bean class="org.gridgain.grid.portables.GridPortableTypeConfiguration"> + <bean class="org.apache.ignite.portables.GridPortableTypeConfiguration"> <property name="className" value="org.gridgain.client.GridClientTestPortable"/> </bean> </list> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java b/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java index 7e8a069..547daba 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java +++ b/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java @@ -9,9 +9,9 @@ package org.apache.ignite; +import org.apache.ignite.portables.*; import org.gridgain.grid.cache.*; import org.gridgain.grid.cache.query.*; -import org.gridgain.grid.portables.*; import org.jetbrains.annotations.*; import java.sql.*; @@ -28,7 +28,7 @@ import java.util.Date; * <li>Automatically convert collections and maps between Java, .NET, and C++.</li> * <li> * Optionally avoid deserialization of objects on the server side - * (objects are stored in {@link org.gridgain.grid.portables.GridPortableObject} format). + * (objects are stored in {@link org.apache.ignite.portables.GridPortableObject} format). * </li> * <li>Avoid need to have concrete class definitions on the server side.</li> * <li>Dynamically change structure of the classes without having to restart the cluster.</li> @@ -74,7 +74,7 @@ import java.util.Date; * GridCacheProjection<Integer.class, GridPortableObject.class> prj = cache.keepPortable(); * </pre> * <h1 class="header">Automatic Portable Types</h1> - * Note that only portable classes are converted to {@link org.gridgain.grid.portables.GridPortableObject} format. Following + * Note that only portable classes are converted to {@link org.apache.ignite.portables.GridPortableObject} format. Following * classes are never converted (e.g., {@link #toPortable(Object)} method will return original * object, and instances of these classes will be stored in cache without changes): * <ul> @@ -98,7 +98,7 @@ import java.util.Date; * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary} * in C#, etc. * <h1 class="header">Building Portable Objects</h1> - * GridGain comes with {@link org.gridgain.grid.portables.GridPortableBuilder} which allows to build portable objects dynamically: + * GridGain comes with {@link org.apache.ignite.portables.GridPortableBuilder} which allows to build portable objects dynamically: * <pre name=code class=java> * GridPortableBuilder builder = GridGain.grid().portables().builder(); * @@ -138,7 +138,7 @@ import java.util.Date; * As the structure of a portable object changes, the new fields become available for SQL queries * automatically. * <h1 class="header">Configuration</h1> - * To make any object portable, you have to specify it in {@link org.gridgain.grid.portables.GridPortableConfiguration} + * To make any object portable, you have to specify it in {@link org.apache.ignite.portables.GridPortableConfiguration} * at startup. The only requirement GridGain imposes is that your object has an empty * constructor. Note, that since server side does not have to know the class definition, * you only need to list portable objects in configuration on the client side. However, if you @@ -174,7 +174,7 @@ import java.util.Date; * * gridCfg.setPortableConfiguration(portCfg); * </pre> - * You can also specify class name for a portable object via {@link org.gridgain.grid.portables.GridPortableTypeConfiguration}. + * You can also specify class name for a portable object via {@link org.apache.ignite.portables.GridPortableTypeConfiguration}. * Do it in case if you need to override other configuration properties on per-type level, like * ID-mapper, or serializer. * <h1 class="header">Custom Affinity Keys</h1> @@ -200,9 +200,9 @@ import java.util.Date; * </property> * </pre> * <h1 class="header">Serialization</h1> - * Once portable object is specified in {@link org.gridgain.grid.portables.GridPortableConfiguration}, GridGain will + * Once portable object is specified in {@link org.apache.ignite.portables.GridPortableConfiguration}, GridGain will * be able to serialize and deserialize it. However, you can provide your own custom - * serialization logic by optionally implementing {@link org.gridgain.grid.portables.GridPortableMarshalAware} interface, like so: + * serialization logic by optionally implementing {@link org.apache.ignite.portables.GridPortableMarshalAware} interface, like so: * <pre name=code class=java> * public class Address implements GridPortableMarshalAware { * private String street; @@ -223,8 +223,8 @@ import java.util.Date; * } * </pre> * Alternatively, if you cannot change class definitions, you can provide custom serialization - * logic in {@link org.gridgain.grid.portables.GridPortableSerializer} either globally in {@link org.gridgain.grid.portables.GridPortableConfiguration} or - * for a specific type via {@link org.gridgain.grid.portables.GridPortableTypeConfiguration} instance. + * logic in {@link org.apache.ignite.portables.GridPortableSerializer} either globally in {@link org.apache.ignite.portables.GridPortableConfiguration} or + * for a specific type via {@link org.apache.ignite.portables.GridPortableTypeConfiguration} instance. * <p> * Similar to java serialization you can use {@code writeReplace()} and {@code readResolve()} methods. * <ul> @@ -241,10 +241,10 @@ import java.util.Date; * <h1 class="header">Custom ID Mappers</h1> * GridGain implementation uses name hash codes to generate IDs for class names or field names * internally. However, in cases when you want to provide your own ID mapping schema, - * you can provide your own {@link org.gridgain.grid.portables.GridPortableIdMapper} implementation. + * you can provide your own {@link org.apache.ignite.portables.GridPortableIdMapper} implementation. * <p> - * ID-mapper may be provided either globally in {@link org.gridgain.grid.portables.GridPortableConfiguration}, - * or for a specific type via {@link org.gridgain.grid.portables.GridPortableTypeConfiguration} instance. + * ID-mapper may be provided either globally in {@link org.apache.ignite.portables.GridPortableConfiguration}, + * or for a specific type via {@link org.apache.ignite.portables.GridPortableTypeConfiguration} instance. * <h1 class="header">Query Indexing</h1> * Portable objects can be indexed for querying by specifying index fields in * {@link GridCacheQueryTypeMetadata} inside of specific {@link GridCacheConfiguration} instance, @@ -287,13 +287,13 @@ public interface IgnitePortables { public int typeId(String typeName); /** - * Converts provided object to instance of {@link org.gridgain.grid.portables.GridPortableObject}. + * Converts provided object to instance of {@link org.apache.ignite.portables.GridPortableObject}. * <p> - * Note that object's type needs to be configured in {@link org.gridgain.grid.portables.GridPortableConfiguration}. + * Note that object's type needs to be configured in {@link org.apache.ignite.portables.GridPortableConfiguration}. * * @param obj Object to convert. * @return Converted object. - * @throws org.gridgain.grid.portables.GridPortableException In case of error. + * @throws org.apache.ignite.portables.GridPortableException In case of error. */ public <T> T toPortable(@Nullable Object obj) throws GridPortableException; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index 85516d1..c8a7a52 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -16,6 +16,7 @@ import org.apache.ignite.lifecycle.*; import org.apache.ignite.managed.*; import org.apache.ignite.marshaller.*; import org.apache.ignite.plugin.*; +import org.apache.ignite.portables.*; import org.gridgain.client.ssl.*; import org.gridgain.grid.*; import org.gridgain.grid.cache.*; @@ -25,7 +26,6 @@ import org.gridgain.grid.dr.hub.sender.*; import org.gridgain.grid.ggfs.*; import org.gridgain.grid.hadoop.*; import org.gridgain.grid.kernal.managers.eventstorage.*; -import org.gridgain.grid.portables.*; import org.gridgain.grid.security.*; import org.gridgain.grid.segmentation.*; import org.gridgain.grid.spi.authentication.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableBuilder.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableBuilder.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableBuilder.java new file mode 100644 index 0000000..a400047 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableBuilder.java @@ -0,0 +1,129 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +import org.jetbrains.annotations.*; + +/** + * Portable object builder. Provides ability to build portable objects dynamically + * without having class definitions. + * <p> + * Here is an example of how a portable object can be built dynamically: + * <pre name=code class=java> + * GridPortableBuilder builder = GridGain.grid().portables().builder("org.project.MyObject"); + * + * builder.setField("fieldA", "A"); + * builder.setField("fieldB", "B"); + * + * GridPortableObject portableObj = builder.build(); + * </pre> + * + * <p> + * Also builder can be initialized by existing portable object. This allows changing some fields without affecting + * other fields. + * <pre name=code class=java> + * GridPortableBuilder builder = GridGain.grid().portables().builder(person); + * + * builder.setField("name", "John"); + * + * person = builder.build(); + * </pre> + * </p> + * + * If you need to modify nested portable object you can get builder for nested object using + * {@link #getField(String)}, changes made on nested builder will affect parent object, + * for example: + * + * <pre name=code class=java> + * GridPortableBuilder personBuilder = grid.portables().createBuilder(personPortableObj); + * GridPortableBuilder addressBuilder = personBuilder.setField("address"); + * + * addressBuilder.setField("city", "New York"); + * + * personPortableObj = personBuilder.build(); + * + * // Should be "New York". + * String city = personPortableObj.getField("address").getField("city"); + * </pre> + * + * @see org.apache.ignite.IgnitePortables#builder(int) + * @see org.apache.ignite.IgnitePortables#builder(String) + * @see org.apache.ignite.IgnitePortables#builder(GridPortableObject) + */ +public interface GridPortableBuilder { + /** + * Returns value assigned to the specified field. + * If the value is a portable object instance of {@code GridPortableBuilder} will be returned, + * which can be modified. + * <p> + * Collections and maps returned from this method are modifiable. + * + * @param name Field name. + * @return Filed value. + */ + public <T> T getField(String name); + + /** + * Sets field value. + * + * @param name Field name. + * @param val Field value (cannot be {@code null}). + * @see GridPortableObject#metaData() + */ + public GridPortableBuilder setField(String name, Object val); + + /** + * Sets field value with value type specification. + * <p> + * Field type is needed for proper metadata update. + * + * @param name Field name. + * @param val Field value. + * @param type Field type. + * @see GridPortableObject#metaData() + */ + public <T> GridPortableBuilder setField(String name, @Nullable T val, Class<? super T> type); + + /** + * Sets field value. + * <p> + * This method should be used if field is portable object. + * + * @param name Field name. + * @param builder Builder for object field. + */ + public GridPortableBuilder setField(String name, @Nullable GridPortableBuilder builder); + + /** + * Removes field from this builder. + * + * @param fieldName Field name. + * @return {@code this} instance for chaining. + */ + public GridPortableBuilder removeField(String fieldName); + + /** + * Sets hash code for resulting portable object returned by {@link #build()} method. + * <p> + * If not set {@code 0} is used. + * + * @param hashCode Hash code. + * @return {@code this} instance for chaining. + */ + public GridPortableBuilder hashCode(int hashCode); + + /** + * Builds portable object. + * + * @return Portable object. + * @throws GridPortableException In case of error. + */ + public GridPortableObject build() throws GridPortableException; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableConfiguration.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableConfiguration.java new file mode 100644 index 0000000..c1cfa0d --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableConfiguration.java @@ -0,0 +1,181 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +import org.gridgain.grid.util.typedef.internal.*; + +import java.sql.Timestamp; +import java.util.*; + +/** + * Defines configuration for GridGain portable functionality. All configuration + * properties defined here can be overridden on per-type level in + * {@link GridPortableTypeConfiguration}. Type configurations are provided via + * {@link #getTypeConfigurations()} method. + */ +public class GridPortableConfiguration { + /** Class names. */ + private Collection<String> clsNames; + + /** ID mapper. */ + private GridPortableIdMapper idMapper; + + /** Serializer. */ + private GridPortableSerializer serializer; + + /** Types. */ + private Collection<GridPortableTypeConfiguration> typeCfgs; + + /** Use timestamp flag. */ + private boolean useTs = true; + + /** Meta data enabled flag. */ + private boolean metaDataEnabled = true; + + /** Keep deserialized flag. */ + private boolean keepDeserialized = true; + + /** + * Gets class names. + * + * @return Class names. + */ + public Collection<String> getClassNames() { + return clsNames; + } + + /** + * Sets class names. + * + * @param clsNames Class names. + */ + public void setClassNames(Collection<String> clsNames) { + this.clsNames = clsNames; + } + + /** + * Gets ID mapper. + * + * @return ID mapper. + */ + public GridPortableIdMapper getIdMapper() { + return idMapper; + } + + /** + * Sets ID mapper. + * + * @param idMapper ID mapper. + */ + public void setIdMapper(GridPortableIdMapper idMapper) { + this.idMapper = idMapper; + } + + /** + * Gets serializer. + * + * @return Serializer. + */ + public GridPortableSerializer getSerializer() { + return serializer; + } + + /** + * Sets serializer. + * + * @param serializer Serializer. + */ + public void setSerializer(GridPortableSerializer serializer) { + this.serializer = serializer; + } + + /** + * Gets types configuration. + * + * @return Types configuration. + */ + public Collection<GridPortableTypeConfiguration> getTypeConfigurations() { + return typeCfgs; + } + + /** + * Sets type configurations. + * + * @param typeCfgs Type configurations. + */ + public void setTypeConfigurations(Collection<GridPortableTypeConfiguration> typeCfgs) { + this.typeCfgs = typeCfgs; + } + + /** + * If {@code true} then date values converted to {@link Timestamp} on deserialization. + * <p> + * Default value is {@code true}. + * + * @return Flag indicating whether date values converted to {@link Timestamp} during unmarshalling. + */ + public boolean isUseTimestamp() { + return useTs; + } + + /** + * @param useTs Flag indicating whether date values converted to {@link Timestamp} during unmarshalling. + */ + public void setUseTimestamp(boolean useTs) { + this.useTs = useTs; + } + + /** + * If {@code true}, meta data will be collected or all types. If you need to override this behaviour for + * some specific type, use {@link GridPortableTypeConfiguration#setMetaDataEnabled(Boolean)} method. + * <p> + * Default value if {@code true}. + * + * @return Whether meta data is collected. + */ + public boolean isMetaDataEnabled() { + return metaDataEnabled; + } + + /** + * @param metaDataEnabled Whether meta data is collected. + */ + public void setMetaDataEnabled(boolean metaDataEnabled) { + this.metaDataEnabled = metaDataEnabled; + } + + /** + * If {@code true}, {@link GridPortableObject} will cache deserialized instance after + * {@link GridPortableObject#deserialize()} is called. All consequent calls of this + * method on the same instance of {@link GridPortableObject} will return that cached + * value without actually deserializing portable object. If you need to override this + * behaviour for some specific type, use {@link GridPortableTypeConfiguration#setKeepDeserialized(Boolean)} + * method. + * <p> + * Default value if {@code true}. + * + * @return Whether deserialized value is kept. + */ + public boolean isKeepDeserialized() { + return keepDeserialized; + } + + /** + * @param keepDeserialized Whether deserialized value is kept. + */ + public void setKeepDeserialized(boolean keepDeserialized) { + this.keepDeserialized = keepDeserialized; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridPortableConfiguration.class, this); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableException.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableException.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableException.java new file mode 100644 index 0000000..2a5e430 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableException.java @@ -0,0 +1,49 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +import org.gridgain.grid.*; +import org.jetbrains.annotations.*; + +/** + * Exception indicating portable object serialization error. + */ +public class GridPortableException extends GridRuntimeException { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Creates portable exception with error message. + * + * @param msg Error message. + */ + public GridPortableException(String msg) { + super(msg); + } + + /** + * Creates portable exception with {@link Throwable} as a cause. + * + * @param cause Cause. + */ + public GridPortableException(Throwable cause) { + super(cause); + } + + /** + * Creates portable exception with error message and {@link Throwable} as a cause. + * + * @param msg Error message. + * @param cause Cause. + */ + public GridPortableException(String msg, @Nullable Throwable cause) { + super(msg, cause); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableIdMapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableIdMapper.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableIdMapper.java new file mode 100644 index 0000000..b5cff6f --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableIdMapper.java @@ -0,0 +1,47 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +/** + * Type and field ID mapper for portable objects. GridGain never writes full + * strings for field or type names. Instead, for performance reasons, GridGain + * writes integer hash codes for type and field names. It has been tested that + * hash code conflicts for the type names or the field names + * within the same type are virtually non-existent and, to gain performance, it is safe + * to work with hash codes. For the cases when hash codes for different types or fields + * actually do collide {@code GridPortableIdMapper} allows to override the automatically + * generated hash code IDs for the type and field names. + * <p> + * Portable ID mapper can be configured for all portable objects via + * {@link GridPortableConfiguration#getIdMapper()} method, or for a specific + * portable type via {@link GridPortableTypeConfiguration#getIdMapper()} method. + */ +public interface GridPortableIdMapper { + /** + * Gets type ID for provided class name. + * <p> + * If {@code 0} is returned, hash code of class simple name will be used. + * + * @param clsName Class name. + * @return Type ID. + */ + public int typeId(String clsName); + + /** + * Gets ID for provided field. + * <p> + * If {@code 0} is returned, hash code of field name will be used. + * + * @param typeId Type ID. + * @param fieldName Field name. + * @return Field ID. + */ + public int fieldId(int typeId, String fieldName); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableInvalidClassException.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableInvalidClassException.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableInvalidClassException.java new file mode 100644 index 0000000..24fabc5 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableInvalidClassException.java @@ -0,0 +1,50 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +import org.jetbrains.annotations.*; + +/** + * Exception indicating that class needed for deserialization of portable object does not exist. + * <p> + * Thrown from {@link GridPortableObject#deserialize()} method. + */ +public class GridPortableInvalidClassException extends GridPortableException { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Creates invalid class exception with error message. + * + * @param msg Error message. + */ + public GridPortableInvalidClassException(String msg) { + super(msg); + } + + /** + * Creates invalid class exception with {@link Throwable} as a cause. + * + * @param cause Cause. + */ + public GridPortableInvalidClassException(Throwable cause) { + super(cause); + } + + /** + * Creates invalid class exception with error message and {@link Throwable} as a cause. + * + * @param msg Error message. + * @param cause Cause. + */ + public GridPortableInvalidClassException(String msg, @Nullable Throwable cause) { + super(msg, cause); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableMarshalAware.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableMarshalAware.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableMarshalAware.java new file mode 100644 index 0000000..6dde0dc --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableMarshalAware.java @@ -0,0 +1,40 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +/** + * Interface that allows to implement custom serialization + * logic for portable objects. Portable objects are not required + * to implement this interface, in which case GridGain will automatically + * serialize portable objects using reflection. + * <p> + * This interface, in a way, is analogous to {@link java.io.Externalizable} + * interface, which allows users to override default serialization logic, + * usually for performance reasons. The only difference here is that portable + * serialization is already very fast and implementing custom serialization + * logic for portables does not provide significant performance gains. + */ +public interface GridPortableMarshalAware { + /** + * Writes fields to provided writer. + * + * @param writer Portable object writer. + * @throws GridPortableException In case of error. + */ + public void writePortable(GridPortableWriter writer) throws GridPortableException; + + /** + * Reads fields from provided reader. + * + * @param reader Portable object reader. + * @throws GridPortableException In case of error. + */ + public void readPortable(GridPortableReader reader) throws GridPortableException; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableMetadata.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableMetadata.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableMetadata.java new file mode 100644 index 0000000..5ec0dea --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableMetadata.java @@ -0,0 +1,53 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +import org.jetbrains.annotations.*; + +import java.util.*; + +/** + * Portable type meta data. Metadata for portable types can be accessed from any of the + * {@link org.apache.ignite.IgnitePortables#metadata(String) GridPortables.metadata(...)} methods. + * Having metadata also allows for proper formatting of {@code GridPortableObject.toString()} method, + * even when portable objects are kept in binary format only, which may be necessary for audit reasons. + */ +public interface GridPortableMetadata { + /** + * Gets portable type name. + * + * @return Portable type name. + */ + public String typeName(); + + /** + * Gets collection of all field names for this portable type. + * + * @return Collection of all field names for this portable type. + */ + public Collection<String> fields(); + + /** + * Gets name of the field type for a given field. + * + * @param fieldName Field name. + * @return Field type name. + */ + @Nullable public String fieldTypeName(String fieldName); + + /** + * Portable objects can optionally specify custom key-affinity mapping in the + * configuration. This method returns the name of the field which should be + * used for the key-affinity mapping. + * + * @return Affinity key field name. + */ + @Nullable public String affinityKeyFieldName(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableObject.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableObject.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableObject.java new file mode 100644 index 0000000..12b6049 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableObject.java @@ -0,0 +1,166 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +import org.jetbrains.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * Wrapper for portable object in portable binary format. Once an object is defined as portable, + * GridGain will always store it in memory in the portable (i.e. binary) format. + * User can choose to work either with the portable format or with the deserialized form + * (assuming that class definitions are present in the classpath). + * <p> + * <b>NOTE:</b> user does not need to (and should not) implement this interface directly. + * <p> + * To work with the portable format directly, user should create a cache projection + * over {@code GridPortableObject} class and then retrieve individual fields as needed: + * <pre name=code class=java> + * GridCacheProjection<GridPortableObject.class, GridPortableObject.class> prj = + * cache.projection(GridPortableObject.class, GridPortableObject.class); + * + * // Convert instance of MyKey to portable format. + * // We could also use GridPortableBuilder to create + * // the key in portable format directly. + * GridPortableObject key = grid.portables().toPortable(new MyKey()); + * + * GridPortableObject val = prj.get(key); + * + * String field = val.field("myFieldName"); + * </pre> + * Alternatively, we could also choose a hybrid approach, where, for example, + * the keys are concrete deserialized objects and the values are returned in portable + * format, like so: + * <pre name=code class=java> + * GridCacheProjection<MyKey.class, GridPortableObject.class> prj = + * cache.projection(MyKey.class, GridPortableObject.class); + * + * GridPortableObject val = prj.get(new MyKey()); + * + * String field = val.field("myFieldName"); + * </pre> + * We could also have the values as concrete deserialized objects and the keys in portable format, + * but such use case is a lot less common because cache keys are usually a lot smaller than values, and + * it may be very cheap to deserialize the keys, but not the values. + * <p> + * And finally, if we have class definitions in the classpath, we may choose to work with deserialized + * typed objects at all times. In this case we do incur the deserialization cost, however, + * GridGain will only deserialize on the first access and will cache the deserialized object, + * so it does not have to be deserialized again: + * <pre name=code class=java> + * GridCacheProjection<MyKey.class, MyValue.class> prj = + * cache.projection(MyKey.class, MyValue.class); + * + * MyValue val = prj.get(new MyKey()); + * + * // Normal java getter. + * String fieldVal = val.getMyFieldName(); + * </pre> + * <h1 class="header">Working With Maps and Collections</h1> + * All maps and collections in the portable objects are serialized automatically. When working + * with different platforms, e.g. C++ or .NET, GridGain will automatically pick the most + * adequate collection or map in either language. For example, {@link ArrayList} in Java will become + * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap} + * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary} + * in C#, etc. + * <h1 class="header">Dynamic Structure Changes</h1> + * Since objects are always cached in the portable binary format, server does not need to + * be aware of the class definitions. Moreover, if class definitions are not present or not + * used on the server, then clients can continuously change the structure of the portable + * objects without having to restart the cluster. For example, if one client stores a + * certain class with fields A and B, and another client stores the same class with + * fields B and C, then the server-side portable object will have the fields A, B, and C. + * As the structure of a portable object changes, the new fields become available for SQL queries + * automatically. + * <h1 class="header">Building Portable Objects</h1> + * GridGain comes with {@link GridPortableBuilder} which allows to build portable objects dynamically: + * <pre name=code class=java> + * GridPortableBuilder builder = GridGain.grid().portables().builder("org.project.MyObject"); + * + * builder.setField("fieldA", "A"); + * builder.setField("fieldB", "B"); + * + * GridPortableObject portableObj = builder.build(); + * </pre> + * For the cases when class definition is present + * in the class path, it is also possible to populate a standard POJO and then + * convert it to portable format, like so: + * <pre name=code class=java> + * MyObject obj = new MyObject(); + * + * obj.setFieldA("A"); + * obj.setFieldB(123); + * + * GridPortableObject portableObj = GridGain.grid().portables().toPortable(obj); + * </pre> + * <h1 class="header">Portable Metadata</h1> + * Even though GridGain portable protocol only works with hash codes for type and field names + * to achieve better performance, GridGain provides metadata for all portable types which + * can be queried ar runtime via any of the {@link org.apache.ignite.IgnitePortables#metadata(Class) GridPortables.metadata(...)} + * methods. Having metadata also allows for proper formatting of {@code GridPortableObject.toString()} method, + * even when portable objects are kept in binary format only, which may be necessary for audit reasons. + */ +public interface GridPortableObject extends Serializable, Cloneable { + /** + * Gets portable object type ID. + * + * @return Type ID. + */ + public int typeId(); + + /** + * Gets meta data for this portable object. + * + * @return Meta data. + * @throws GridPortableException In case of error. + */ + @Nullable public GridPortableMetadata metaData() throws GridPortableException; + + /** + * Gets field value. + * + * @param fieldName Field name. + * @return Field value. + * @throws GridPortableException In case of any other error. + */ + @Nullable public <F> F field(String fieldName) throws GridPortableException; + + /** + * Gets fully deserialized instance of portable object. + * + * @return Fully deserialized instance of portable object. + * @throws GridPortableInvalidClassException If class doesn't exist. + * @throws GridPortableException In case of any other error. + */ + @Nullable public <T> T deserialize() throws GridPortableException; + + /** + * Creates a copy of this portable object and optionally changes field values + * if they are provided in map. If map is empty or {@code null}, clean copy + * is created. + * + * @param fields Fields to modify in copy. + * @return Copy of this portable object. + * @throws GridPortableException In case of error. + * @deprecated Use {@link GridPortableBuilder} instead. + * @see GridPortableBuilder + */ + @Deprecated + public GridPortableObject copy(@Nullable Map<String, Object> fields) throws GridPortableException; + + /** + * Copies this portable object. + * + * @return Copy of this portable object. + */ + public GridPortableObject clone() throws CloneNotSupportedException; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableRawReader.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableRawReader.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableRawReader.java new file mode 100644 index 0000000..bd45f01 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableRawReader.java @@ -0,0 +1,214 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +import org.jetbrains.annotations.*; + +import java.sql.*; +import java.util.*; +import java.util.Date; + +/** + * Raw reader for portable objects. Raw reader does not use field name hash codes, therefore, + * making the format even more compact. However, if the raw reader is used, + * dynamic structure changes to the portable objects are not supported. + */ +public interface GridPortableRawReader { + /** + * @return Byte value. + * @throws GridPortableException In case of error. + */ + public byte readByte() throws GridPortableException; + + /** + * @return Short value. + * @throws GridPortableException In case of error. + */ + public short readShort() throws GridPortableException; + + /** + * @return Integer value. + * @throws GridPortableException In case of error. + */ + public int readInt() throws GridPortableException; + + /** + * @return Long value. + * @throws GridPortableException In case of error. + */ + public long readLong() throws GridPortableException; + + /** + * @return Float value. + * @throws GridPortableException In case of error. + */ + public float readFloat() throws GridPortableException; + + /** + * @return Double value. + * @throws GridPortableException In case of error. + */ + public double readDouble() throws GridPortableException; + + /** + * @return Char value. + * @throws GridPortableException In case of error. + */ + public char readChar() throws GridPortableException; + + /** + * @return Boolean value. + * @throws GridPortableException In case of error. + */ + public boolean readBoolean() throws GridPortableException; + + /** + * @return String value. + * @throws GridPortableException In case of error. + */ + @Nullable public String readString() throws GridPortableException; + + /** + * @return UUID. + * @throws GridPortableException In case of error. + */ + @Nullable public UUID readUuid() throws GridPortableException; + + /** + * @return Date. + * @throws GridPortableException In case of error. + */ + @Nullable public Date readDate() throws GridPortableException; + + /** + * @return Timestamp. + * @throws GridPortableException In case of error. + */ + @Nullable public Timestamp readTimestamp() throws GridPortableException; + + /** + * @return Object. + * @throws GridPortableException In case of error. + */ + @Nullable public Object readObject() throws GridPortableException; + + /** + * @return Byte array. + * @throws GridPortableException In case of error. + */ + @Nullable public byte[] readByteArray() throws GridPortableException; + + /** + * @return Short array. + * @throws GridPortableException In case of error. + */ + @Nullable public short[] readShortArray() throws GridPortableException; + + /** + * @return Integer array. + * @throws GridPortableException In case of error. + */ + @Nullable public int[] readIntArray() throws GridPortableException; + + /** + * @return Long array. + * @throws GridPortableException In case of error. + */ + @Nullable public long[] readLongArray() throws GridPortableException; + + /** + * @return Float array. + * @throws GridPortableException In case of error. + */ + @Nullable public float[] readFloatArray() throws GridPortableException; + + /** + * @return Byte array. + * @throws GridPortableException In case of error. + */ + @Nullable public double[] readDoubleArray() throws GridPortableException; + + /** + * @return Char array. + * @throws GridPortableException In case of error. + */ + @Nullable public char[] readCharArray() throws GridPortableException; + + /** + * @return Boolean array. + * @throws GridPortableException In case of error. + */ + @Nullable public boolean[] readBooleanArray() throws GridPortableException; + + /** + * @return String array. + * @throws GridPortableException In case of error. + */ + @Nullable public String[] readStringArray() throws GridPortableException; + + /** + * @return UUID array. + * @throws GridPortableException In case of error. + */ + @Nullable public UUID[] readUuidArray() throws GridPortableException; + + /** + * @return Date array. + * @throws GridPortableException In case of error. + */ + @Nullable public Date[] readDateArray() throws GridPortableException; + + /** + * @return Object array. + * @throws GridPortableException In case of error. + */ + @Nullable public Object[] readObjectArray() throws GridPortableException; + + /** + * @return Collection. + * @throws GridPortableException In case of error. + */ + @Nullable public <T> Collection<T> readCollection() throws GridPortableException; + + /** + * @param colCls Collection class. + * @return Collection. + * @throws GridPortableException In case of error. + */ + @Nullable public <T> Collection<T> readCollection(Class<? extends Collection<T>> colCls) + throws GridPortableException; + + /** + * @return Map. + * @throws GridPortableException In case of error. + */ + @Nullable public <K, V> Map<K, V> readMap() throws GridPortableException; + + /** + * @param mapCls Map class. + * @return Map. + * @throws GridPortableException In case of error. + */ + @Nullable public <K, V> Map<K, V> readMap(Class<? extends Map<K, V>> mapCls) throws GridPortableException; + + /** + * @param enumCls Enum class. + * @return Value. + * @throws GridPortableException In case of error. + */ + @Nullable public <T extends Enum<?>> T readEnum(Class<T> enumCls) throws GridPortableException; + + /** + * @param enumCls Enum class. + * @return Value. + * @throws GridPortableException In case of error. + */ + @Nullable public <T extends Enum<?>> T[] readEnumArray(Class<T> enumCls) throws GridPortableException; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableRawWriter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableRawWriter.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableRawWriter.java new file mode 100644 index 0000000..8127219 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableRawWriter.java @@ -0,0 +1,197 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +import org.jetbrains.annotations.*; + +import java.sql.*; +import java.util.*; +import java.util.Date; + +/** + * Raw writer for portable object. Raw writer does not write field name hash codes, therefore, + * making the format even more compact. However, if the raw writer is used, + * dynamic structure changes to the portable objects are not supported. + */ +public interface GridPortableRawWriter { + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeByte(byte val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeShort(short val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeInt(int val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeLong(long val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeFloat(float val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeDouble(double val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeChar(char val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeBoolean(boolean val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeString(@Nullable String val) throws GridPortableException; + + /** + * @param val UUID to write. + * @throws GridPortableException In case of error. + */ + public void writeUuid(@Nullable UUID val) throws GridPortableException; + + /** + * @param val Date to write. + * @throws GridPortableException In case of error. + */ + public void writeDate(@Nullable Date val) throws GridPortableException; + + /** + * @param val Timestamp to write. + * @throws GridPortableException In case of error. + */ + public void writeTimestamp(@Nullable Timestamp val) throws GridPortableException; + + /** + * @param obj Value to write. + * @throws GridPortableException In case of error. + */ + public void writeObject(@Nullable Object obj) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeByteArray(@Nullable byte[] val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeShortArray(@Nullable short[] val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeIntArray(@Nullable int[] val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeLongArray(@Nullable long[] val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeFloatArray(@Nullable float[] val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeDoubleArray(@Nullable double[] val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeCharArray(@Nullable char[] val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeBooleanArray(@Nullable boolean[] val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeStringArray(@Nullable String[] val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeUuidArray(@Nullable UUID[] val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeDateArray(@Nullable Date[] val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public void writeObjectArray(@Nullable Object[] val) throws GridPortableException; + + /** + * @param col Collection to write. + * @throws GridPortableException In case of error. + */ + public <T> void writeCollection(@Nullable Collection<T> col) throws GridPortableException; + + /** + * @param map Map to write. + * @throws GridPortableException In case of error. + */ + public <K, V> void writeMap(@Nullable Map<K, V> map) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public <T extends Enum<?>> void writeEnum(T val) throws GridPortableException; + + /** + * @param val Value to write. + * @throws GridPortableException In case of error. + */ + public <T extends Enum<?>> void writeEnumArray(T[] val) throws GridPortableException; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableReader.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableReader.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableReader.java new file mode 100644 index 0000000..eb2338d --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableReader.java @@ -0,0 +1,263 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +import org.jetbrains.annotations.*; + +import java.sql.*; +import java.util.*; +import java.util.Date; + +/** + * Reader for portable objects used in {@link GridPortableMarshalAware} implementations. + * Useful for the cases when user wants a fine-grained control over serialization. + * <p> + * Note that GridGain never writes full strings for field or type names. Instead, + * for performance reasons, GridGain writes integer hash codes for type and field names. + * It has been tested that hash code conflicts for the type names or the field names + * within the same type are virtually non-existent and, to gain performance, it is safe + * to work with hash codes. For the cases when hash codes for different types or fields + * actually do collide, GridGain provides {@link GridPortableIdMapper} which + * allows to override the automatically generated hash code IDs for the type and field names. + */ +public interface GridPortableReader { + /** + * @param fieldName Field name. + * @return Byte value. + * @throws GridPortableException In case of error. + */ + public byte readByte(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Short value. + * @throws GridPortableException In case of error. + */ + public short readShort(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Integer value. + * @throws GridPortableException In case of error. + */ + public int readInt(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Long value. + * @throws GridPortableException In case of error. + */ + public long readLong(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @throws GridPortableException In case of error. + * @return Float value. + */ + public float readFloat(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Double value. + * @throws GridPortableException In case of error. + */ + public double readDouble(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Char value. + * @throws GridPortableException In case of error. + */ + public char readChar(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Boolean value. + * @throws GridPortableException In case of error. + */ + public boolean readBoolean(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return String value. + * @throws GridPortableException In case of error. + */ + @Nullable public String readString(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return UUID. + * @throws GridPortableException In case of error. + */ + @Nullable public UUID readUuid(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Date. + * @throws GridPortableException In case of error. + */ + @Nullable public Date readDate(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Timestamp. + * @throws GridPortableException In case of error. + */ + @Nullable public Timestamp readTimestamp(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Object. + * @throws GridPortableException In case of error. + */ + @Nullable public <T> T readObject(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Byte array. + * @throws GridPortableException In case of error. + */ + @Nullable public byte[] readByteArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Short array. + * @throws GridPortableException In case of error. + */ + @Nullable public short[] readShortArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Integer array. + * @throws GridPortableException In case of error. + */ + @Nullable public int[] readIntArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Long array. + * @throws GridPortableException In case of error. + */ + @Nullable public long[] readLongArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Float array. + * @throws GridPortableException In case of error. + */ + @Nullable public float[] readFloatArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Byte array. + * @throws GridPortableException In case of error. + */ + @Nullable public double[] readDoubleArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Char array. + * @throws GridPortableException In case of error. + */ + @Nullable public char[] readCharArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Boolean array. + * @throws GridPortableException In case of error. + */ + @Nullable public boolean[] readBooleanArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return String array. + * @throws GridPortableException In case of error. + */ + @Nullable public String[] readStringArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return UUID array. + * @throws GridPortableException In case of error. + */ + @Nullable public UUID[] readUuidArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Date array. + * @throws GridPortableException In case of error. + */ + @Nullable public Date[] readDateArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Object array. + * @throws GridPortableException In case of error. + */ + @Nullable public Object[] readObjectArray(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Collection. + * @throws GridPortableException In case of error. + */ + @Nullable public <T> Collection<T> readCollection(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @param colCls Collection class. + * @return Collection. + * @throws GridPortableException In case of error. + */ + @Nullable public <T> Collection<T> readCollection(String fieldName, Class<? extends Collection<T>> colCls) + throws GridPortableException; + + /** + * @param fieldName Field name. + * @return Map. + * @throws GridPortableException In case of error. + */ + @Nullable public <K, V> Map<K, V> readMap(String fieldName) throws GridPortableException; + + /** + * @param fieldName Field name. + * @param mapCls Map class. + * @return Map. + * @throws GridPortableException In case of error. + */ + @Nullable public <K, V> Map<K, V> readMap(String fieldName, Class<? extends Map<K, V>> mapCls) + throws GridPortableException; + + /** + * @param fieldName Field name. + * @param enumCls Enum class. + * @return Value. + * @throws GridPortableException In case of error. + */ + @Nullable public <T extends Enum<?>> T readEnum(String fieldName, Class<T> enumCls) throws GridPortableException; + + /** + * @param fieldName Field name. + * @param enumCls Enum class. + * @return Value. + * @throws GridPortableException In case of error. + */ + @Nullable public <T extends Enum<?>> T[] readEnumArray(String fieldName, Class<T> enumCls) + throws GridPortableException; + + /** + * Gets raw reader. Raw reader does not use field name hash codes, therefore, + * making the format even more compact. However, if the raw reader is used, + * dynamic structure changes to the portable objects are not supported. + * + * @return Raw reader. + */ + public GridPortableRawReader rawReader(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableSerializer.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableSerializer.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableSerializer.java new file mode 100644 index 0000000..1037b49 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableSerializer.java @@ -0,0 +1,39 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +/** + * Interface that allows to implement custom serialization logic for portable objects. + * Can be used instead of {@link GridPortableMarshalAware} in case if the class + * cannot be changed directly. + * <p> + * Portable serializer can be configured for all portable objects via + * {@link GridPortableConfiguration#getSerializer()} method, or for a specific + * portable type via {@link GridPortableTypeConfiguration#getSerializer()} method. + */ +public interface GridPortableSerializer { + /** + * Writes fields to provided writer. + * + * @param obj Empty object. + * @param writer Portable object writer. + * @throws GridPortableException In case of error. + */ + public void writePortable(Object obj, GridPortableWriter writer) throws GridPortableException; + + /** + * Reads fields from provided reader. + * + * @param obj Empty object + * @param reader Portable object reader. + * @throws GridPortableException In case of error. + */ + public void readPortable(Object obj, GridPortableReader reader) throws GridPortableException; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e04165bb/modules/core/src/main/java/org/apache/ignite/portables/GridPortableTypeConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portables/GridPortableTypeConfiguration.java b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableTypeConfiguration.java new file mode 100644 index 0000000..3a362fe --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/portables/GridPortableTypeConfiguration.java @@ -0,0 +1,187 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.portables; + +import org.gridgain.grid.util.typedef.internal.*; + +import java.sql.*; + +/** + * Defines configuration properties for a specific portable type. Providing per-type + * configuration is optional, as it is generally enough to provide global + * portable configuration in {@link GridPortableConfiguration} instance. However, + * this class allows you to change configuration properties for a specific + * portable type without affecting configuration for other portable types. + * <p> + * Per-type portable configuration can be specified in + * {@link GridPortableConfiguration#getTypeConfigurations()} method. + */ +public class GridPortableTypeConfiguration { + /** Class name. */ + private String clsName; + + /** ID mapper. */ + private GridPortableIdMapper idMapper; + + /** Serializer. */ + private GridPortableSerializer serializer; + + /** Use timestamp flag. */ + private Boolean useTs; + + /** Meta data enabled flag. */ + private Boolean metaDataEnabled; + + /** Keep deserialized flag. */ + private Boolean keepDeserialized; + + /** Affinity key field name. */ + private String affKeyFieldName; + + /** + */ + public GridPortableTypeConfiguration() { + // No-op. + } + + /** + * @param clsName Class name. + */ + public GridPortableTypeConfiguration(String clsName) { + this.clsName = clsName; + } + + /** + * Gets type name. + * + * @return Type name. + */ + public String getClassName() { + return clsName; + } + + /** + * Sets type name. + * + * @param clsName Type name. + */ + public void setClassName(String clsName) { + this.clsName = clsName; + } + + /** + * Gets ID mapper. + * + * @return ID mapper. + */ + public GridPortableIdMapper getIdMapper() { + return idMapper; + } + + /** + * Sets ID mapper. + * + * @param idMapper ID mapper. + */ + public void setIdMapper(GridPortableIdMapper idMapper) { + this.idMapper = idMapper; + } + + /** + * Gets serializer. + * + * @return Serializer. + */ + public GridPortableSerializer getSerializer() { + return serializer; + } + + /** + * Sets serializer. + * + * @param serializer Serializer. + */ + public void setSerializer(GridPortableSerializer serializer) { + this.serializer = serializer; + } + + /** + * If {@code true} then date values converted to {@link Timestamp} during unmarshalling. + * + * @return Flag indicating whether date values converted to {@link Timestamp} during unmarshalling. + */ + public Boolean isUseTimestamp() { + return useTs; + } + + /** + * @param useTs Flag indicating whether date values converted to {@link Timestamp} during unmarshalling. + */ + public void setUseTimestamp(Boolean useTs) { + this.useTs = useTs; + } + + /** + * Defines whether meta data is collected for this type. If provided, this value will override + * {@link GridPortableConfiguration#isMetaDataEnabled()} property. + * + * @return Whether meta data is collected. + */ + public Boolean isMetaDataEnabled() { + return metaDataEnabled; + } + + /** + * @param metaDataEnabled Whether meta data is collected. + */ + public void setMetaDataEnabled(Boolean metaDataEnabled) { + this.metaDataEnabled = metaDataEnabled; + } + + /** + * Defines whether {@link GridPortableObject} should cache deserialized instance. If provided, + * this value will override {@link GridPortableConfiguration#isKeepDeserialized()} property. + * + * @return Whether deserialized value is kept. + */ + public Boolean isKeepDeserialized() { + return keepDeserialized; + } + + /** + * @param keepDeserialized Whether deserialized value is kept. + */ + public void setKeepDeserialized(Boolean keepDeserialized) { + this.keepDeserialized = keepDeserialized; + } + + /** + * Gets affinity key field name. + * + * @return Affinity key field name. + */ + public String getAffinityKeyFieldName() { + return affKeyFieldName; + } + + /** + * Sets affinity key field name. + * + * @param affKeyFieldName Affinity key field name. + */ + public void setAffinityKeyFieldName(String affKeyFieldName) { + this.affKeyFieldName = affKeyFieldName; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridPortableTypeConfiguration.class, this, super.toString()); + } +}