You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2015/11/27 14:30:53 UTC
ignite git commit: IGNITE-2018 Refactored examples to use common
model classes.
Repository: ignite
Updated Branches:
refs/heads/ignite-1.5 3080f61ae -> e519c2f5b
IGNITE-2018 Refactored examples to use common model classes.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e519c2f5
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e519c2f5
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e519c2f5
Branch: refs/heads/ignite-1.5
Commit: e519c2f5b1e05f886c861eb2bd05aec7cffa5bbc
Parents: 3080f61
Author: AKuznetsov <ak...@gridgain.com>
Authored: Fri Nov 27 20:30:46 2015 +0700
Committer: AKuznetsov <ak...@gridgain.com>
Committed: Fri Nov 27 20:30:46 2015 +0700
----------------------------------------------------------------------
.../hibernate/CacheHibernatePersonStore.java | 4 +-
.../hibernate/CacheHibernateStoreExample.java | 2 +-
.../datagrid/store/hibernate/Person.hbm.xml | 2 +-
.../apache/ignite/examples/binary/Address.java | 72 ---------
.../apache/ignite/examples/binary/Employee.java | 93 -----------
.../ignite/examples/binary/EmployeeKey.java | 93 -----------
.../ignite/examples/binary/Organization.java | 93 -----------
.../examples/binary/OrganizationType.java | 32 ----
...ComputeClientBinaryTaskExecutionExample.java | 4 +-
.../CacheClientBinaryPutGetExample.java | 6 +-
.../datagrid/CacheClientBinaryQueryExample.java | 22 +--
.../examples/datagrid/CacheQueryExample.java | 161 ++++---------------
.../ignite/examples/datagrid/store/Person.java | 154 ------------------
.../store/auto/CacheAutoStoreExample.java | 4 +-
.../auto/CacheAutoStoreLoadDataExample.java | 4 +-
.../datagrid/store/auto/CacheConfig.java | 6 +-
.../store/dummy/CacheDummyPersonStore.java | 12 +-
.../store/dummy/CacheDummyStoreExample.java | 4 +-
.../store/jdbc/CacheJdbcPersonStore.java | 18 +--
.../store/jdbc/CacheJdbcStoreExample.java | 4 +-
.../store/spring/CacheSpringPersonStore.java | 10 +-
.../store/spring/CacheSpringStoreExample.java | 4 +-
.../ignite/examples/model/Organization.java | 55 +++++++
.../apache/ignite/examples/model/Person.java | 120 ++++++++++++++
.../ignite/examples/model/binary/Address.java | 72 +++++++++
.../ignite/examples/model/binary/Employee.java | 93 +++++++++++
.../examples/model/binary/EmployeeKey.java | 93 +++++++++++
.../examples/model/binary/Organization.java | 93 +++++++++++
.../examples/model/binary/OrganizationType.java | 32 ++++
.../examples/ScalarCacheQueryExample.scala | 66 ++------
30 files changed, 651 insertions(+), 777 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java
index d040b88..ade5d18 100644
--- a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java
+++ b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernatePersonStore.java
@@ -24,7 +24,7 @@ import javax.cache.integration.CacheWriterException;
import org.apache.ignite.cache.store.CacheStore;
import org.apache.ignite.cache.store.CacheStoreAdapter;
import org.apache.ignite.cache.store.CacheStoreSession;
-import org.apache.ignite.examples.datagrid.store.Person;
+import org.apache.ignite.examples.model.Person;
import org.apache.ignite.lang.IgniteBiInClosure;
import org.apache.ignite.resources.CacheStoreSessionResource;
import org.hibernate.HibernateException;
@@ -107,7 +107,7 @@ public class CacheHibernatePersonStore extends CacheStoreAdapter<Long, Person> {
for (Object obj : list) {
Person person = (Person)obj;
- clo.apply(person.getId(), person);
+ clo.apply(person.id, person);
cnt++;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernateStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernateStoreExample.java b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernateStoreExample.java
index f993d81..71c4f68 100644
--- a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernateStoreExample.java
+++ b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/CacheHibernateStoreExample.java
@@ -29,7 +29,7 @@ import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreSessionListene
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.examples.ExampleNodeStartup;
import org.apache.ignite.examples.ExamplesUtils;
-import org.apache.ignite.examples.datagrid.store.Person;
+import org.apache.ignite.examples.model.Person;
import org.apache.ignite.transactions.Transaction;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/Person.hbm.xml
----------------------------------------------------------------------
diff --git a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/Person.hbm.xml b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/Person.hbm.xml
index 035ab98..1314b71 100644
--- a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/Person.hbm.xml
+++ b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/store/hibernate/Person.hbm.xml
@@ -23,7 +23,7 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field">
- <class name="org.apache.ignite.examples.datagrid.store.Person" table="PERSONS">
+ <class name="org.apache.ignite.examples.model.Person" table="PERSONS">
<!-- ID. -->
<id name="id"/>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/binary/Address.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/Address.java b/examples/src/main/java/org/apache/ignite/examples/binary/Address.java
deleted file mode 100644
index 76d8774..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/binary/Address.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.binary;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.binary.BinaryReader;
-import org.apache.ignite.binary.BinaryWriter;
-
-/**
- * Employee address.
- * <p>
- * This class implements {@link org.apache.ignite.binary.Binarylizable} only for example purposes,
- * in order to show how to customize serialization and deserialization of
- * binary objects.
- */
-public class Address implements Binarylizable {
- /** Street. */
- private String street;
-
- /** ZIP code. */
- private int zip;
-
- /**
- * Required for binary deserialization.
- */
- public Address() {
- // No-op.
- }
-
- /**
- * @param street Street.
- * @param zip ZIP code.
- */
- public Address(String street, int zip) {
- this.street = street;
- this.zip = zip;
- }
-
- /** {@inheritDoc} */
- @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
- writer.writeString("street", street);
- writer.writeInt("zip", zip);
- }
-
- /** {@inheritDoc} */
- @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
- street = reader.readString("street");
- zip = reader.readInt("zip");
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "Address [street=" + street +
- ", zip=" + zip + ']';
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/binary/Employee.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/Employee.java b/examples/src/main/java/org/apache/ignite/examples/binary/Employee.java
deleted file mode 100644
index 744b44f..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/binary/Employee.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.binary;
-
-import java.util.Collection;
-
-/**
- * This class represents employee object.
- */
-public class Employee {
- /** Name. */
- private String name;
-
- /** Salary. */
- private long salary;
-
- /** Address. */
- private Address address;
-
- /** Departments. */
- private Collection<String> departments;
-
- /**
- * Required for binary deserialization.
- */
- public Employee() {
- // No-op.
- }
-
- /**
- * @param name Name.
- * @param salary Salary.
- * @param address Address.
- * @param departments Departments.
- */
- public Employee(String name, long salary, Address address, Collection<String> departments) {
- this.name = name;
- this.salary = salary;
- this.address = address;
- this.departments = departments;
- }
-
- /**
- * @return Name.
- */
- public String name() {
- return name;
- }
-
- /**
- * @return Salary.
- */
- public long salary() {
- return salary;
- }
-
- /**
- * @return Address.
- */
- public Address address() {
- return address;
- }
-
- /**
- * @return Departments.
- */
- public Collection<String> departments() {
- return departments;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "Employee [name=" + name +
- ", salary=" + salary +
- ", address=" + address +
- ", departments=" + departments + ']';
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java b/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java
deleted file mode 100644
index 7614f2c..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.binary;
-
-import org.apache.ignite.cache.affinity.AffinityKeyMapped;
-
-/**
- * This class represents key for employee object.
- * <p>
- * Used in query example to collocate employees
- * with their organizations.
- */
-public class EmployeeKey {
- /** ID. */
- private int id;
-
- /** Organization ID. */
- @AffinityKeyMapped
- private int organizationId;
-
- /**
- * Required for binary deserialization.
- */
- public EmployeeKey() {
- // No-op.
- }
-
- /**
- * @param id ID.
- * @param organizationId Organization ID.
- */
- public EmployeeKey(int id, int organizationId) {
- this.id = id;
- this.organizationId = organizationId;
- }
-
- /**
- * @return ID.
- */
- public int id() {
- return id;
- }
-
- /**
- * @return Organization ID.
- */
- public int organizationId() {
- return organizationId;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- EmployeeKey key = (EmployeeKey)o;
-
- return id == key.id && organizationId == key.organizationId;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- int res = id;
-
- res = 31 * res + organizationId;
-
- return res;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "EmployeeKey [id=" + id +
- ", organizationId=" + organizationId + ']';
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/binary/Organization.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/Organization.java b/examples/src/main/java/org/apache/ignite/examples/binary/Organization.java
deleted file mode 100644
index b42bb27..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/binary/Organization.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.binary;
-
-import java.sql.Timestamp;
-
-/**
- * This class represents organization object.
- */
-public class Organization {
- /** Name. */
- private String name;
-
- /** Address. */
- private Address address;
-
- /** Type. */
- private OrganizationType type;
-
- /** Last update time. */
- private Timestamp lastUpdated;
-
- /**
- * Required for binary deserialization.
- */
- public Organization() {
- // No-op.
- }
-
- /**
- * @param name Name.
- * @param address Address.
- * @param type Type.
- * @param lastUpdated Last update time.
- */
- public Organization(String name, Address address, OrganizationType type, Timestamp lastUpdated) {
- this.name = name;
- this.address = address;
- this.type = type;
- this.lastUpdated = lastUpdated;
- }
-
- /**
- * @return Name.
- */
- public String name() {
- return name;
- }
-
- /**
- * @return Address.
- */
- public Address address() {
- return address;
- }
-
- /**
- * @return Type.
- */
- public OrganizationType type() {
- return type;
- }
-
- /**
- * @return Last update time.
- */
- public Timestamp lastUpdated() {
- return lastUpdated;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "Organization [name=" + name +
- ", address=" + address +
- ", type=" + type +
- ", lastUpdated=" + lastUpdated + ']';
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/binary/OrganizationType.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/OrganizationType.java b/examples/src/main/java/org/apache/ignite/examples/binary/OrganizationType.java
deleted file mode 100644
index 6548210..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/binary/OrganizationType.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.binary;
-
-/**
- * Organization type enum.
- */
-public enum OrganizationType {
- /** Non-profit organization. */
- NON_PROFIT,
-
- /** Private organization. */
- PRIVATE,
-
- /** Government organization. */
- GOVERNMENT
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientBinaryTaskExecutionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientBinaryTaskExecutionExample.java b/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientBinaryTaskExecutionExample.java
index ba1c968..49f254a 100644
--- a/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientBinaryTaskExecutionExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientBinaryTaskExecutionExample.java
@@ -22,8 +22,8 @@ import java.util.Arrays;
import java.util.Collection;
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
-import org.apache.ignite.examples.binary.Address;
-import org.apache.ignite.examples.binary.Employee;
+import org.apache.ignite.examples.model.binary.Address;
+import org.apache.ignite.examples.model.binary.Employee;
import org.apache.ignite.binary.BinaryObject;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryPutGetExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryPutGetExample.java b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryPutGetExample.java
index e49c16a..c416501 100644
--- a/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryPutGetExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryPutGetExample.java
@@ -28,9 +28,9 @@ import org.apache.ignite.Ignition;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.binary.Address;
-import org.apache.ignite.examples.binary.Organization;
-import org.apache.ignite.examples.binary.OrganizationType;
+import org.apache.ignite.examples.model.binary.Address;
+import org.apache.ignite.examples.model.binary.Organization;
+import org.apache.ignite.examples.model.binary.OrganizationType;
import org.apache.ignite.binary.BinaryObject;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java
index ed01eb9..34452e4 100644
--- a/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java
@@ -34,11 +34,11 @@ import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.cache.query.TextQuery;
import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.binary.Address;
-import org.apache.ignite.examples.binary.Employee;
-import org.apache.ignite.examples.binary.EmployeeKey;
-import org.apache.ignite.examples.binary.Organization;
-import org.apache.ignite.examples.binary.OrganizationType;
+import org.apache.ignite.examples.model.binary.Address;
+import org.apache.ignite.examples.model.binary.Employee;
+import org.apache.ignite.examples.model.binary.EmployeeKey;
+import org.apache.ignite.examples.model.binary.Organization;
+import org.apache.ignite.examples.model.binary.OrganizationType;
import org.apache.ignite.binary.BinaryObject;
/**
@@ -204,14 +204,14 @@ public class CacheClientBinaryQueryExample {
* @param cache Ignite cache.
*/
private static void sqlJoinQuery(IgniteCache<BinaryObject, BinaryObject> cache) {
- SqlQuery<BinaryObject, BinaryObject> query = new SqlQuery<>(Employee.class,
+ SqlQuery<BinaryObject, BinaryObject> qry = new SqlQuery<>(Employee.class,
"from Employee, \"" + ORGANIZATION_CACHE_NAME + "\".Organization as org " +
"where Employee.organizationId = org._key and org.name = ?");
String organizationName = "GridGain";
QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> employees =
- cache.query(query.setArgs(organizationName));
+ cache.query(qry.setArgs(organizationName));
System.out.println();
System.out.println(">>> Employees working for " + organizationName + ':');
@@ -226,9 +226,9 @@ public class CacheClientBinaryQueryExample {
* @param cache Ignite cache.
*/
private static void sqlFieldsQuery(IgniteCache<BinaryObject, BinaryObject> cache) {
- SqlFieldsQuery query = new SqlFieldsQuery("select name, salary from Employee");
+ SqlFieldsQuery qry = new SqlFieldsQuery("select name, salary from Employee");
- QueryCursor<List<?>> employees = cache.query(query);
+ QueryCursor<List<?>> employees = cache.query(qry);
System.out.println();
System.out.println(">>> Employee names and their salaries:");
@@ -243,9 +243,9 @@ public class CacheClientBinaryQueryExample {
* @param cache Ignite cache.
*/
private static void textQuery(IgniteCache<BinaryObject, BinaryObject> cache) {
- TextQuery<BinaryObject, BinaryObject> query = new TextQuery<>(Employee.class, "TX");
+ TextQuery<BinaryObject, BinaryObject> qry = new TextQuery<>(Employee.class, "TX");
- QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> employees = cache.query(query);
+ QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> employees = cache.query(qry);
System.out.println();
System.out.println(">>> Employees living in Texas:");
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
index 8fba3f6..a593562 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
@@ -17,9 +17,7 @@
package org.apache.ignite.examples.datagrid;
-import java.io.Serializable;
import java.util.List;
-import java.util.UUID;
import javax.cache.Cache;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
@@ -31,10 +29,10 @@ import org.apache.ignite.cache.query.ScanQuery;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.cache.query.TextQuery;
-import org.apache.ignite.cache.query.annotations.QuerySqlField;
-import org.apache.ignite.cache.query.annotations.QueryTextField;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.examples.ExampleNodeStartup;
+import org.apache.ignite.examples.model.Organization;
+import org.apache.ignite.examples.model.Person;
import org.apache.ignite.lang.IgniteBiPredicate;
/**
@@ -80,19 +78,19 @@ public class CacheQueryExample {
System.out.println();
System.out.println(">>> Cache query example started.");
- CacheConfiguration<UUID, Organization> orgCacheCfg = new CacheConfiguration<>(ORG_CACHE);
+ CacheConfiguration<Long, Organization> orgCacheCfg = new CacheConfiguration<>(ORG_CACHE);
orgCacheCfg.setCacheMode(CacheMode.PARTITIONED); // Default.
- orgCacheCfg.setIndexedTypes(UUID.class, Organization.class);
+ orgCacheCfg.setIndexedTypes(Long.class, Organization.class);
- CacheConfiguration<AffinityKey<UUID>, Person> personCacheCfg = new CacheConfiguration<>(PERSON_CACHE);
+ CacheConfiguration<AffinityKey<Long>, Person> personCacheCfg = new CacheConfiguration<>(PERSON_CACHE);
personCacheCfg.setCacheMode(CacheMode.PARTITIONED); // Default.
personCacheCfg.setIndexedTypes(AffinityKey.class, Person.class);
try (
- IgniteCache<UUID, Organization> orgCache = ignite.getOrCreateCache(orgCacheCfg);
- IgniteCache<AffinityKey<UUID>, Person> personCache = ignite.getOrCreateCache(personCacheCfg)
+ IgniteCache<Long, Organization> orgCache = ignite.getOrCreateCache(orgCacheCfg);
+ IgniteCache<AffinityKey<Long>, Person> personCache = ignite.getOrCreateCache(personCacheCfg)
) {
// Populate cache.
initialize();
@@ -128,11 +126,11 @@ public class CacheQueryExample {
* Example for scan query based on a predicate.
*/
private static void scanQuery() {
- IgniteCache<AffinityKey<UUID>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
+ IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
- ScanQuery<AffinityKey<UUID>, Person> scan = new ScanQuery<>(
- new IgniteBiPredicate<AffinityKey<UUID>, Person>() {
- @Override public boolean apply(AffinityKey<UUID> key, Person person) {
+ ScanQuery<AffinityKey<Long>, Person> scan = new ScanQuery<>(
+ new IgniteBiPredicate<AffinityKey<Long>, Person>() {
+ @Override public boolean apply(AffinityKey<Long> key, Person person) {
return person.salary <= 1000;
}
}
@@ -146,18 +144,18 @@ public class CacheQueryExample {
* Example for SQL queries based on salary ranges.
*/
private static void sqlQuery() {
- IgniteCache<AffinityKey<UUID>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
+ IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
// SQL clause which selects salaries based on range.
String sql = "salary > ? and salary <= ?";
// Execute queries for salary ranges.
print("People with salaries between 0 and 1000 (queried with SQL query): ",
- cache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, sql).
+ cache.query(new SqlQuery<AffinityKey<Long>, Person>(Person.class, sql).
setArgs(0, 1000)).getAll());
print("People with salaries between 1000 and 2000 (queried with SQL query): ",
- cache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, sql).
+ cache.query(new SqlQuery<AffinityKey<Long>, Person>(Person.class, sql).
setArgs(1000, 2000)).getAll());
}
@@ -165,7 +163,7 @@ public class CacheQueryExample {
* Example for SQL queries based on all employees working for a specific organization.
*/
private static void sqlQueryWithJoin() {
- IgniteCache<AffinityKey<UUID>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
+ IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
// SQL clause query which joins on 2 types to select people for a specific organization.
String joinSql =
@@ -175,11 +173,11 @@ public class CacheQueryExample {
// Execute queries for find employees for different organizations.
print("Following people are 'ApacheIgnite' employees: ",
- cache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, joinSql).
+ cache.query(new SqlQuery<AffinityKey<Long>, Person>(Person.class, joinSql).
setArgs("ApacheIgnite")).getAll());
print("Following people are 'Other' employees: ",
- cache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, joinSql).
+ cache.query(new SqlQuery<AffinityKey<Long>, Person>(Person.class, joinSql).
setArgs("Other")).getAll());
}
@@ -187,15 +185,15 @@ public class CacheQueryExample {
* Example for TEXT queries using LUCENE-based indexing of people's resumes.
*/
private static void textQuery() {
- IgniteCache<AffinityKey<UUID>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
+ IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
// Query for all people with "Master Degree" in their resumes.
- QueryCursor<Cache.Entry<AffinityKey<UUID>, Person>> masters =
- cache.query(new TextQuery<AffinityKey<UUID>, Person>(Person.class, "Master"));
+ QueryCursor<Cache.Entry<AffinityKey<Long>, Person>> masters =
+ cache.query(new TextQuery<AffinityKey<Long>, Person>(Person.class, "Master"));
// Query for all people with "Bachelor Degree" in their resumes.
- QueryCursor<Cache.Entry<AffinityKey<UUID>, Person>> bachelors =
- cache.query(new TextQuery<AffinityKey<UUID>, Person>(Person.class, "Bachelor"));
+ QueryCursor<Cache.Entry<AffinityKey<Long>, Person>> bachelors =
+ cache.query(new TextQuery<AffinityKey<Long>, Person>(Person.class, "Bachelor"));
print("Following people have 'Master Degree' in their resumes: ", masters.getAll());
print("Following people have 'Bachelor Degree' in their resumes: ", bachelors.getAll());
@@ -205,7 +203,7 @@ public class CacheQueryExample {
* Example for SQL queries to calculate average salary for a specific organization.
*/
private static void sqlQueryWithAggregation() {
- IgniteCache<AffinityKey<UUID>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
+ IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
// Calculate average of salary of all persons in ApacheIgnite.
// Note that we also join on Organization cache as well.
@@ -226,7 +224,7 @@ public class CacheQueryExample {
* fields instead of whole key-value pairs.
*/
private static void sqlFieldsQuery() {
- IgniteCache<AffinityKey<UUID>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
+ IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
// Execute query to get names of all employees.
QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery(
@@ -244,7 +242,7 @@ public class CacheQueryExample {
* fields instead of whole key-value pairs.
*/
private static void sqlFieldsQueryWithJoin() {
- IgniteCache<AffinityKey<UUID>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
+ IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
// Execute query to get names of all employees.
String sql =
@@ -265,7 +263,7 @@ public class CacheQueryExample {
* Populate cache with test data.
*/
private static void initialize() {
- IgniteCache<UUID, Organization> orgCache = Ignition.ignite().cache(ORG_CACHE);
+ IgniteCache<Long, Organization> orgCache = Ignition.ignite().cache(ORG_CACHE);
// Organizations.
Organization org1 = new Organization("ApacheIgnite");
@@ -274,7 +272,7 @@ public class CacheQueryExample {
orgCache.put(org1.id, org1);
orgCache.put(org2.id, org2);
- IgniteCache<AffinityKey<UUID>, Person> personCache = Ignition.ignite().cache(PERSON_CACHE);
+ IgniteCache<AffinityKey<Long>, Person> personCache = Ignition.ignite().cache(PERSON_CACHE);
// People.
Person p1 = new Person(org1, "John", "Doe", 2000, "John Doe has Master Degree.");
@@ -320,109 +318,4 @@ public class CacheQueryExample {
for (Object next : col)
System.out.println(">>> " + next);
}
-
- /**
- * Person class.
- */
- private static class Person implements Serializable {
- /** Person ID (indexed). */
- @QuerySqlField(index = true)
- private UUID id;
-
- /** Organization ID (indexed). */
- @QuerySqlField(index = true)
- private UUID orgId;
-
- /** First name (not-indexed). */
- @QuerySqlField
- private String firstName;
-
- /** Last name (not indexed). */
- @QuerySqlField
- private String lastName;
-
- /** Resume text (create LUCENE-based TEXT index for this field). */
- @QueryTextField
- private String resume;
-
- /** Salary (indexed). */
- @QuerySqlField(index = true)
- private double salary;
-
- /** Custom cache key to guarantee that person is always collocated with its organization. */
- private transient AffinityKey<UUID> key;
-
- /**
- * Constructs person record.
- *
- * @param org Organization.
- * @param firstName First name.
- * @param lastName Last name.
- * @param salary Salary.
- * @param resume Resume text.
- */
- Person(Organization org, String firstName, String lastName, double salary, String resume) {
- // Generate unique ID for this person.
- id = UUID.randomUUID();
-
- orgId = org.id;
-
- this.firstName = firstName;
- this.lastName = lastName;
- this.resume = resume;
- this.salary = salary;
- }
-
- /**
- * Gets cache affinity key. Since in some examples person needs to be collocated with organization, we create
- * custom affinity key to guarantee this collocation.
- *
- * @return Custom affinity key to guarantee that person is always collocated with organization.
- */
- public AffinityKey<UUID> key() {
- if (key == null)
- key = new AffinityKey<>(id, orgId);
-
- return key;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "Person [firstName=" + firstName +
- ", lastName=" + lastName +
- ", id=" + id +
- ", orgId=" + orgId +
- ", resume=" + resume +
- ", salary=" + salary + ']';
- }
- }
-
- /**
- * Organization class.
- */
- private static class Organization implements Serializable {
- /** Organization ID (indexed). */
- @QuerySqlField(index = true)
- private UUID id;
-
- /** Organization name (indexed). */
- @QuerySqlField(index = true)
- private String name;
-
- /**
- * Create organization.
- *
- * @param name Organization name.
- */
- Organization(String name) {
- id = UUID.randomUUID();
-
- this.name = name;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "Organization [id=" + id + ", name=" + name + ']';
- }
- }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/datagrid/store/Person.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/Person.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/Person.java
deleted file mode 100644
index b54010f..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/Person.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.examples.datagrid.store;
-
-import java.io.Serializable;
-
-/**
- * Person definition.
- *
- * Code generated by Apache Ignite Schema Import utility: 02/24/2015.
- */
-public class Person implements Serializable {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** Value for id. */
- private long id;
-
- /** Value for first name. */
- private String firstName;
-
- /** Value for last name. */
- private String lastName;
-
- /**
- * Empty constructor.
- */
- public Person() {
- // No-op.
- }
-
- /**
- * Full constructor.
- */
- public Person(
- long id,
- String firstName,
- String lastName
- ) {
- this.id = id;
- this.firstName = firstName;
- this.lastName = lastName;
- }
-
- /**
- * Gets id.
- *
- * @return Value for id.
- */
- public long getId() {
- return id;
- }
-
- /**
- * Sets id.
- *
- * @param id New value for id.
- */
- public void setId(long id) {
- this.id = id;
- }
-
- /**
- * Gets first name.
- *
- * @return Value for first name.
- */
- public String getFirstName() {
- return firstName;
- }
-
- /**
- * Sets first name.
- *
- * @param firstName New value for first name.
- */
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- /**
- * Gets last name.
- *
- * @return Value for last name.
- */
- public String getLastName() {
- return lastName;
- }
-
- /**
- * Sets last name.
- *
- * @param lastName New value for last name.
- */
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (!(o instanceof Person))
- return false;
-
- Person that = (Person)o;
-
- if (id != that.id)
- return false;
-
- if (firstName != null ? !firstName.equals(that.firstName) : that.firstName != null)
- return false;
-
- if (lastName != null ? !lastName.equals(that.lastName) : that.lastName != null)
- return false;
-
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- int res = (int)(id ^ (id >>> 32));
-
- res = 31 * res + (firstName != null ? firstName.hashCode() : 0);
-
- res = 31 * res + (lastName != null ? lastName.hashCode() : 0);
-
- return res;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "Person [id=" + id +
- ", firstName=" + firstName +
- ", lastName=" + lastName +
- "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
index f8cd4dd..37a31d7 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreExample.java
@@ -24,7 +24,7 @@ import org.apache.ignite.IgniteException;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore;
import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.examples.datagrid.store.Person;
+import org.apache.ignite.examples.model.Person;
import org.apache.ignite.transactions.Transaction;
/**
@@ -85,4 +85,4 @@ public class CacheAutoStoreExample {
}
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
index f0f9feb..63a8c6f 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheAutoStoreLoadDataExample.java
@@ -25,7 +25,7 @@ import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.examples.ExampleNodeStartup;
import org.apache.ignite.examples.ExamplesUtils;
-import org.apache.ignite.examples.datagrid.store.Person;
+import org.apache.ignite.examples.model.Person;
/**
* Demonstrates how to load data from database.
@@ -82,4 +82,4 @@ public class CacheAutoStoreLoadDataExample {
}
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
index 1eb7cd2..3b38aeb 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/auto/CacheConfig.java
@@ -26,7 +26,7 @@ import org.apache.ignite.cache.CacheTypeMetadata;
import org.apache.ignite.cache.store.CacheStore;
import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore;
import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.datagrid.store.Person;
+import org.apache.ignite.examples.model.Person;
import org.h2.jdbcx.JdbcConnectionPool;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
@@ -59,7 +59,7 @@ public class CacheConfig {
meta.setDatabaseTable("PERSON");
meta.setKeyType("java.lang.Long");
- meta.setValueType("org.apache.ignite.examples.datagrid.store.Person");
+ meta.setValueType("org.apache.ignite.examples.model.Person");
meta.setKeyFields(Collections.singletonList(new CacheTypeFieldMetadata("ID", Types.BIGINT, "id", Long.class)));
@@ -78,4 +78,4 @@ public class CacheConfig {
return cfg;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
index f85e92b..6c0fecb 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyPersonStore.java
@@ -22,7 +22,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.ignite.Ignite;
import org.apache.ignite.cache.store.CacheStoreAdapter;
import org.apache.ignite.cache.store.CacheStoreSession;
-import org.apache.ignite.examples.datagrid.store.Person;
+import org.apache.ignite.examples.model.Person;
import org.apache.ignite.lang.IgniteBiInClosure;
import org.apache.ignite.resources.CacheNameResource;
import org.apache.ignite.resources.CacheStoreSessionResource;
@@ -85,7 +85,7 @@ public class CacheDummyPersonStore extends CacheStoreAdapter<Long, Person> {
System.out.println(">>> Store loadCache for entry count: " + cnt);
- for (int i = 0; i < cnt; i++) {
+ for (long i = 0; i < cnt; i++) {
// Generate dummy person on the fly.
Person p = new Person(i, "first-" + i, "last-" + 1);
@@ -93,13 +93,13 @@ public class CacheDummyPersonStore extends CacheStoreAdapter<Long, Person> {
// but we check if local node is primary or backup anyway just to demonstrate that we can.
// Ideally, partition ID of a key would be stored in the database and only keys
// for partitions that belong on this node would be loaded from database.
- if (ignite.affinity(cacheName).isPrimaryOrBackup(ignite.cluster().localNode(), p.getId())) {
+ if (ignite.affinity(cacheName).isPrimaryOrBackup(ignite.cluster().localNode(), p.id)) {
// Update dummy database.
// In real life data would be loaded from database.
- dummyDB.put(p.getId(), p);
+ dummyDB.put(p.id, p);
// Pass data to cache.
- clo.apply(p.getId(), p);
+ clo.apply(p.id, p);
}
}
}
@@ -110,4 +110,4 @@ public class CacheDummyPersonStore extends CacheStoreAdapter<Long, Person> {
@Nullable private Transaction transaction() {
return ses != null ? ses.transaction() : null;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyStoreExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyStoreExample.java
index 20e6b8f..a631df3 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyStoreExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/dummy/CacheDummyStoreExample.java
@@ -26,7 +26,7 @@ import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.examples.ExampleNodeStartup;
import org.apache.ignite.examples.ExamplesUtils;
-import org.apache.ignite.examples.datagrid.store.Person;
+import org.apache.ignite.examples.model.Person;
import org.apache.ignite.transactions.Transaction;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
@@ -130,4 +130,4 @@ public class CacheDummyStoreExample {
System.out.println("Read value after commit: " + cache.get(id));
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
index e0ea13a..6ba181e 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcPersonStore.java
@@ -29,7 +29,7 @@ import org.apache.ignite.IgniteException;
import org.apache.ignite.cache.store.CacheStore;
import org.apache.ignite.cache.store.CacheStoreAdapter;
import org.apache.ignite.cache.store.CacheStoreSession;
-import org.apache.ignite.examples.datagrid.store.Person;
+import org.apache.ignite.examples.model.Person;
import org.apache.ignite.lang.IgniteBiInClosure;
import org.apache.ignite.resources.CacheStoreSessionResource;
import org.h2.jdbcx.JdbcConnectionPool;
@@ -107,9 +107,9 @@ public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person> {
// Some databases would allow these to be done in one 'upsert' operation.
try (PreparedStatement st = conn.prepareStatement(
"update PERSONS set firstName = ?, lastName = ? where id = ?")) {
- st.setString(1, val.getFirstName());
- st.setString(2, val.getLastName());
- st.setLong(3, val.getId());
+ st.setString(1, val.firstName);
+ st.setString(2, val.lastName);
+ st.setLong(3, val.id);
updated = st.executeUpdate();
}
@@ -118,9 +118,9 @@ public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person> {
if (updated == 0) {
try (PreparedStatement st = conn.prepareStatement(
"insert into PERSONS (id, firstName, lastName) values (?, ?, ?)")) {
- st.setLong(1, val.getId());
- st.setString(2, val.getFirstName());
- st.setString(3, val.getLastName());
+ st.setLong(1, val.id);
+ st.setString(2, val.firstName);
+ st.setString(3, val.lastName);
st.executeUpdate();
}
@@ -166,7 +166,7 @@ public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person> {
while (rs.next()) {
Person person = new Person(rs.getLong(1), rs.getString(2), rs.getString(3));
- clo.apply(person.getId(), person);
+ clo.apply(person.id, person);
cnt++;
}
@@ -177,4 +177,4 @@ public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person> {
throw new CacheLoaderException("Failed to load values from cache store.", e);
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java
index 9d3014f..55ad5df 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java
@@ -29,7 +29,7 @@ import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.examples.ExampleNodeStartup;
import org.apache.ignite.examples.ExamplesUtils;
-import org.apache.ignite.examples.datagrid.store.Person;
+import org.apache.ignite.examples.model.Person;
import org.apache.ignite.transactions.Transaction;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
@@ -144,4 +144,4 @@ public class CacheJdbcStoreExample {
System.out.println("Read value after commit: " + cache.get(id));
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringPersonStore.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringPersonStore.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringPersonStore.java
index 7a0ea33..0029890 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringPersonStore.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringPersonStore.java
@@ -26,7 +26,7 @@ import javax.sql.DataSource;
import org.apache.ignite.IgniteException;
import org.apache.ignite.cache.store.CacheStore;
import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.examples.datagrid.store.Person;
+import org.apache.ignite.examples.model.Person;
import org.apache.ignite.lang.IgniteBiInClosure;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -92,11 +92,11 @@ public class CacheSpringPersonStore extends CacheStoreAdapter<Long, Person> {
System.out.println(">>> Store write [key=" + key + ", val=" + val + ']');
int updated = jdbcTemplate.update("update PERSONS set firstName = ?, lastName = ? where id = ?",
- val.getFirstName(), val.getLastName(), val.getId());
+ val.firstName, val.lastName, val.id);
if (updated == 0) {
jdbcTemplate.update("insert into PERSONS (id, firstName, lastName) values (?, ?, ?)",
- val.getId(), val.getFirstName(), val.getLastName());
+ val.id, val.firstName, val.lastName);
}
}
@@ -120,7 +120,7 @@ public class CacheSpringPersonStore extends CacheStoreAdapter<Long, Person> {
@Override public void processRow(ResultSet rs) throws SQLException {
Person person = new Person(rs.getLong(1), rs.getString(2), rs.getString(3));
- clo.apply(person.getId(), person);
+ clo.apply(person.id, person);
cnt.incrementAndGet();
}
@@ -128,4 +128,4 @@ public class CacheSpringPersonStore extends CacheStoreAdapter<Long, Person> {
System.out.println(">>> Loaded " + cnt + " values into cache.");
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringStoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringStoreExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringStoreExample.java
index 16437da..273ea1c 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringStoreExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/store/spring/CacheSpringStoreExample.java
@@ -29,7 +29,7 @@ import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.examples.ExampleNodeStartup;
import org.apache.ignite.examples.ExamplesUtils;
-import org.apache.ignite.examples.datagrid.store.Person;
+import org.apache.ignite.examples.model.Person;
import org.apache.ignite.transactions.Transaction;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
@@ -144,4 +144,4 @@ public class CacheSpringStoreExample {
System.out.println("Read value after commit: " + cache.get(id));
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/model/Organization.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/model/Organization.java b/examples/src/main/java/org/apache/ignite/examples/model/Organization.java
new file mode 100644
index 0000000..3881719
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/model/Organization.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.model;
+
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+
+import java.io.Serializable;
+import java.util.Random;
+
+/**
+ * Organization class.
+ */
+public class Organization implements Serializable {
+ /** */
+ private static final Random RND = new Random();
+
+ /** Organization ID (indexed). */
+ @QuerySqlField(index = true)
+ public Long id;
+
+ /** Organization name (indexed). */
+ @QuerySqlField(index = true)
+ public String name;
+
+ /**
+ * Create organization.
+ *
+ * @param name Organization name.
+ */
+ public Organization(String name) {
+ id = RND.nextLong();
+
+ this.name = name;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Organization [id=" + id + ", name=" + name + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/model/Person.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/model/Person.java b/examples/src/main/java/org/apache/ignite/examples/model/Person.java
new file mode 100644
index 0000000..616cf6a
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/model/Person.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.model;
+
+import org.apache.ignite.cache.affinity.AffinityKey;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.cache.query.annotations.QueryTextField;
+
+import java.io.Serializable;
+import java.util.Random;
+
+/**
+ * Person class.
+ */
+public class Person implements Serializable {
+ /** */
+ private static final Random RND = new Random();
+
+ /** Person ID (indexed). */
+ @QuerySqlField(index = true)
+ public Long id;
+
+ /** Organization ID (indexed). */
+ @QuerySqlField(index = true)
+ public Long orgId;
+
+ /** First name (not-indexed). */
+ @QuerySqlField
+ public String firstName;
+
+ /** Last name (not indexed). */
+ @QuerySqlField
+ public String lastName;
+
+ /** Resume text (create LUCENE-based TEXT index for this field). */
+ @QueryTextField
+ public String resume;
+
+ /** Salary (indexed). */
+ @QuerySqlField(index = true)
+ public double salary;
+
+ /** Custom cache key to guarantee that person is always collocated with its organization. */
+ private transient AffinityKey<Long> key;
+
+ /**
+ * Constructs person record.
+ *
+ * @param org Organization.
+ * @param firstName First name.
+ * @param lastName Last name.
+ * @param salary Salary.
+ * @param resume Resume text.
+ */
+ public Person(Organization org, String firstName, String lastName, double salary, String resume) {
+ // Generate unique ID for this person.
+ id = RND.nextLong();
+
+ orgId = org.id;
+
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.resume = resume;
+ this.salary = salary;
+ }
+
+ /**
+ * Constructs person record.
+ *
+ * @param id Person ID.
+ * @param firstName First name.
+ * @param lastName Last name.
+ */
+ public Person(Long id, String firstName, String lastName) {
+ this.id = id;
+
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ /**
+ * Gets cache affinity key. Since in some examples person needs to be collocated with organization, we create
+ * custom affinity key to guarantee this collocation.
+ *
+ * @return Custom affinity key to guarantee that person is always collocated with organization.
+ */
+ public AffinityKey<Long> key() {
+ if (key == null)
+ key = new AffinityKey<>(id, orgId);
+
+ return key;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override public String toString() {
+ return "Person [firstName=" + firstName +
+ ", lastName=" + lastName +
+ ", id=" + id +
+ ", orgId=" + orgId +
+ ", resume=" + resume +
+ ", salary=" + salary + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/model/binary/Address.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/model/binary/Address.java b/examples/src/main/java/org/apache/ignite/examples/model/binary/Address.java
new file mode 100644
index 0000000..2d17cb8
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/model/binary/Address.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.model.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+
+/**
+ * Employee address.
+ * <p>
+ * This class implements {@link org.apache.ignite.binary.Binarylizable} only for example purposes,
+ * in order to show how to customize serialization and deserialization of
+ * binary objects.
+ */
+public class Address implements Binarylizable {
+ /** Street. */
+ private String street;
+
+ /** ZIP code. */
+ private int zip;
+
+ /**
+ * Required for binary deserialization.
+ */
+ public Address() {
+ // No-op.
+ }
+
+ /**
+ * @param street Street.
+ * @param zip ZIP code.
+ */
+ public Address(String street, int zip) {
+ this.street = street;
+ this.zip = zip;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+ writer.writeString("street", street);
+ writer.writeInt("zip", zip);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+ street = reader.readString("street");
+ zip = reader.readInt("zip");
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Address [street=" + street +
+ ", zip=" + zip + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/model/binary/Employee.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/model/binary/Employee.java b/examples/src/main/java/org/apache/ignite/examples/model/binary/Employee.java
new file mode 100644
index 0000000..ad82065
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/model/binary/Employee.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.model.binary;
+
+import java.util.Collection;
+
+/**
+ * This class represents employee object.
+ */
+public class Employee {
+ /** Name. */
+ private String name;
+
+ /** Salary. */
+ private long salary;
+
+ /** Address. */
+ private Address addr;
+
+ /** Departments. */
+ private Collection<String> departments;
+
+ /**
+ * Required for binary deserialization.
+ */
+ public Employee() {
+ // No-op.
+ }
+
+ /**
+ * @param name Name.
+ * @param salary Salary.
+ * @param addr Address.
+ * @param departments Departments.
+ */
+ public Employee(String name, long salary, Address addr, Collection<String> departments) {
+ this.name = name;
+ this.salary = salary;
+ this.addr = addr;
+ this.departments = departments;
+ }
+
+ /**
+ * @return Name.
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * @return Salary.
+ */
+ public long salary() {
+ return salary;
+ }
+
+ /**
+ * @return Address.
+ */
+ public Address address() {
+ return addr;
+ }
+
+ /**
+ * @return Departments.
+ */
+ public Collection<String> departments() {
+ return departments;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Employee [name=" + name +
+ ", salary=" + salary +
+ ", address=" + addr +
+ ", departments=" + departments + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/model/binary/EmployeeKey.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/model/binary/EmployeeKey.java b/examples/src/main/java/org/apache/ignite/examples/model/binary/EmployeeKey.java
new file mode 100644
index 0000000..20367ac
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/model/binary/EmployeeKey.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.model.binary;
+
+import org.apache.ignite.cache.affinity.AffinityKeyMapped;
+
+/**
+ * This class represents key for employee object.
+ * <p>
+ * Used in query example to collocate employees
+ * with their organizations.
+ */
+public class EmployeeKey {
+ /** ID. */
+ private int id;
+
+ /** Organization ID. */
+ @AffinityKeyMapped
+ private int organizationId;
+
+ /**
+ * Required for binary deserialization.
+ */
+ public EmployeeKey() {
+ // No-op.
+ }
+
+ /**
+ * @param id ID.
+ * @param organizationId Organization ID.
+ */
+ public EmployeeKey(int id, int organizationId) {
+ this.id = id;
+ this.organizationId = organizationId;
+ }
+
+ /**
+ * @return ID.
+ */
+ public int id() {
+ return id;
+ }
+
+ /**
+ * @return Organization ID.
+ */
+ public int organizationId() {
+ return organizationId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ EmployeeKey key = (EmployeeKey)o;
+
+ return id == key.id && organizationId == key.organizationId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ int res = id;
+
+ res = 31 * res + organizationId;
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "EmployeeKey [id=" + id +
+ ", organizationId=" + organizationId + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/model/binary/Organization.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/model/binary/Organization.java b/examples/src/main/java/org/apache/ignite/examples/model/binary/Organization.java
new file mode 100644
index 0000000..6b7aca4
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/model/binary/Organization.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.model.binary;
+
+import java.sql.Timestamp;
+
+/**
+ * This class represents organization object.
+ */
+public class Organization {
+ /** Name. */
+ private String name;
+
+ /** Address. */
+ private Address addr;
+
+ /** Type. */
+ private OrganizationType type;
+
+ /** Last update time. */
+ private Timestamp lastUpdated;
+
+ /**
+ * Required for binary deserialization.
+ */
+ public Organization() {
+ // No-op.
+ }
+
+ /**
+ * @param name Name.
+ * @param addr Address.
+ * @param type Type.
+ * @param lastUpdated Last update time.
+ */
+ public Organization(String name, Address addr, OrganizationType type, Timestamp lastUpdated) {
+ this.name = name;
+ this.addr = addr;
+ this.type = type;
+ this.lastUpdated = lastUpdated;
+ }
+
+ /**
+ * @return Name.
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * @return Address.
+ */
+ public Address address() {
+ return addr;
+ }
+
+ /**
+ * @return Type.
+ */
+ public OrganizationType type() {
+ return type;
+ }
+
+ /**
+ * @return Last update time.
+ */
+ public Timestamp lastUpdated() {
+ return lastUpdated;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Organization [name=" + name +
+ ", address=" + addr +
+ ", type=" + type +
+ ", lastUpdated=" + lastUpdated + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/java/org/apache/ignite/examples/model/binary/OrganizationType.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/model/binary/OrganizationType.java b/examples/src/main/java/org/apache/ignite/examples/model/binary/OrganizationType.java
new file mode 100644
index 0000000..69804c0
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/model/binary/OrganizationType.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.model.binary;
+
+/**
+ * Organization type enum.
+ */
+public enum OrganizationType {
+ /** Non-profit organization. */
+ NON_PROFIT,
+
+ /** Private organization. */
+ PRIVATE,
+
+ /** Government organization. */
+ GOVERNMENT
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e519c2f5/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCacheQueryExample.scala
----------------------------------------------------------------------
diff --git a/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCacheQueryExample.scala b/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCacheQueryExample.scala
index 1a42947..6d6c8c3 100644
--- a/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCacheQueryExample.scala
+++ b/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCacheQueryExample.scala
@@ -17,11 +17,13 @@
package org.apache.ignite.scalar.examples
+import java.lang.{Long => JLong}
import java.util._
import org.apache.ignite.cache.CacheMode._
import org.apache.ignite.cache.affinity.AffinityKey
import org.apache.ignite.configuration.CacheConfiguration
+import org.apache.ignite.examples.model.{Person, Organization}
import org.apache.ignite.scalar.scalar
import org.apache.ignite.scalar.scalar._
import org.apache.ignite.{Ignite, IgniteCache}
@@ -48,7 +50,7 @@ object ScalarCacheQueryExample {
*/
def main(args: Array[String]) {
scalar(CONFIG) {
- val cache = createCache$(NAME, indexedTypes = Seq(classOf[UUID], classOf[Organization],
+ val cache = createCache$(NAME, indexedTypes = Seq(classOf[JLong], classOf[Organization],
classOf[AffinityKey[_]], classOf[Person]))
try {
@@ -70,12 +72,12 @@ object ScalarCacheQueryExample {
initialize()
// Cache instance shortcut.
- val cache = mkCache[AffinityKey[UUID], Person]
+ val cache = mkCache[AffinityKey[JLong], Person]
// Using distributed queries for partitioned cache and local queries for replicated cache.
// Since in replicated caches data is available on all nodes, including local one,
// it is enough to just query the local node.
- val prj = if (cache.getConfiguration(classOf[CacheConfiguration[AffinityKey[UUID], Person]]).getCacheMode == PARTITIONED)
+ val prj = if (cache.getConfiguration(classOf[CacheConfiguration[AffinityKey[JLong], Person]]).getCacheMode == PARTITIONED)
ignite.cluster().forRemotes()
else
ignite.cluster().forLocal()
@@ -104,23 +106,23 @@ object ScalarCacheQueryExample {
cache$(NAME).get.clear()
// Organization cache projection.
- val orgCache = mkCache[UUID, Organization]
+ val orgCache = mkCache[JLong, Organization]
// Organizations.
- val org1 = Organization("Ignite")
- val org2 = Organization("Other")
+ val org1 = new Organization("Ignite")
+ val org2 = new Organization("Other")
orgCache += (org1.id -> org1)
orgCache += (org2.id -> org2)
// Person cache projection.
- val prnCache = mkCache[AffinityKey[UUID], Person]
+ val prnCache = mkCache[AffinityKey[JLong], Person]
// People.
- val p1 = Person(org1, "John", "Doe", 2000, "John Doe has Master Degree.")
- val p2 = Person(org1, "Jane", "Doe", 1000, "Jane Doe has Bachelor Degree.")
- val p3 = Person(org2, "John", "Smith", 1500, "John Smith has Bachelor Degree.")
- val p4 = Person(org2, "Jane", "Smith", 2500, "Jane Smith has Master Degree.")
+ val p1 = new Person(org1, "John", "Doe", 2000, "John Doe has Master Degree.")
+ val p2 = new Person(org1, "Jane", "Doe", 1000, "Jane Doe has Bachelor Degree.")
+ val p3 = new Person(org2, "John", "Smith", 1500, "John Smith has Bachelor Degree.")
+ val p4 = new Person(org2, "Jane", "Smith", 2500, "Jane Smith has Master Degree.")
// Note that in this example we use custom affinity key for Person objects
// to ensure that all persons are collocated with their organizations.
@@ -148,45 +150,3 @@ object ScalarCacheQueryExample {
}
}
}
-
-/**
- * Organization class.
- */
-private case class Organization(
- @ScalarCacheQuerySqlField
- name: String
-) {
- /** Organization ID. */
- @ScalarCacheQuerySqlField
- val id = UUID.randomUUID
-}
-
-/**
- * Person class.
- */
-private case class Person(
- org: Organization,
- firstName: String,
- lastName: String,
- @ScalarCacheQuerySqlField
- salary: Double,
- @ScalarCacheQueryTextField
- resume: String
-) {
- /** Person ID. */
- val id = UUID.randomUUID
-
- /** Organization ID. */
- @ScalarCacheQuerySqlField
- val orgId = org.id
-
- /** Affinity key for this person. */
- val key = new AffinityKey[UUID](id, org.id)
-
- /**
- * `toString` implementation.
- */
- override def toString: String = {
- firstName + " " + lastName + " [salary: " + salary + ", resume: " + resume + "]"
- }
-}