Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
1,104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
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. | ||
--> | ||
|
||
<!-- | ||
Ignite configuration with all defaults and enabled p2p deployment and enabled events. | ||
--> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:util="http://www.springframework.org/schema/util" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/util | ||
http://www.springframework.org/schema/util/spring-util.xsd"> | ||
<bean abstract="true" id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> | ||
<!-- Set to true to enable distributed class loading for examples, default is false. --> | ||
<property name="peerClassLoadingEnabled" value="true"/> | ||
|
||
<!-- Enable task execution events for examples. --> | ||
<property name="includeEventTypes"> | ||
<list> | ||
<!--Task execution events--> | ||
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED"/> | ||
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED"/> | ||
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED"/> | ||
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT"/> | ||
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET"/> | ||
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED"/> | ||
|
||
<!--Cache events--> | ||
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT"/> | ||
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ"/> | ||
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED"/> | ||
</list> | ||
</property> | ||
|
||
<!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. --> | ||
<property name="discoverySpi"> | ||
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> | ||
<property name="ipFinder"> | ||
<!-- | ||
Ignite provides several options for automatic discovery that can be used | ||
instead os static IP based discovery. For information on all options refer | ||
to our documentation: http://apacheignite.readme.io/docs/cluster-config | ||
--> | ||
<!-- Uncomment static IP finder to enable static-based discovery of initial nodes. --> | ||
<!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">--> | ||
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder"> | ||
<property name="addresses"> | ||
<list> | ||
<!-- In distributed environment, replace with actual host IP address. --> | ||
<value>127.0.0.1:47500..47509</value> | ||
</list> | ||
</property> | ||
</bean> | ||
</property> | ||
</bean> | ||
</property> | ||
</bean> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
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. | ||
--> | ||
|
||
<!-- | ||
Ignite Spring configuration file to startup Ignite cache. | ||
This file demonstrates how to configure cache using Spring. Provided cache | ||
will be created on node startup. | ||
Use this configuration file when running Spring Data examples. | ||
When starting a standalone node, you need to execute the following command: | ||
{IGNITE_HOME}/bin/ignite.{bat|sh} modules/spring-data-2.2/examples/config/example-spring-data.xml | ||
When starting Ignite from Java IDE, pass path to this file to Ignition: | ||
Ignition.start("modules/spring-data-2.2/examples/config/example-spring-data.xml"); | ||
--> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans.xsd"> | ||
<!-- Imports default Ignite configuration --> | ||
<import resource="example-default.xml"/> | ||
|
||
<bean parent="ignite.cfg"> | ||
<property name="igniteInstanceName" value="springDataNode" /> | ||
|
||
<property name="cacheConfiguration"> | ||
<list> | ||
<bean class="org.apache.ignite.configuration.CacheConfiguration"> | ||
<!-- | ||
Apache Ignite uses an IgniteRepository extension which inherits from Spring Data's CrudRepository. | ||
The SQL grid is also enabled to aceess Spring Data repository. The @RepositoryConfig annotation | ||
maps the PersonRepository to an Ignite's cache named "PersonCache". | ||
--> | ||
<property name="name" value="PersonCache"/> | ||
<property name="indexedTypes"> | ||
<list> | ||
<value>java.lang.Long</value> | ||
<value>org.apache.ignite.springdata22.examples.model.Person</value> | ||
</list> | ||
</property> | ||
</bean> | ||
</list> | ||
</property> | ||
</bean> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.springdata22.examples; | ||
|
||
import org.apache.ignite.Ignition; | ||
import org.apache.ignite.client.IgniteClient; | ||
import org.apache.ignite.configuration.ClientConfiguration; | ||
import org.apache.ignite.springdata22.repository.config.EnableIgniteRepositories; | ||
import org.apache.ignite.springdata22.repository.config.RepositoryConfig; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import static org.apache.ignite.configuration.ClientConnectorConfiguration.DFLT_PORT; | ||
|
||
/** | ||
* Example of Spring application configuration that represents beans required to configure Spring Data repository access | ||
* to an Ignite cluster through the thin client. | ||
* | ||
* Note that both Ignite thin client and Ignite node approaches of Ignite cluster access configuration uses the same API. | ||
* Ignite Spring Data integration automatically recognizes the type of provided bean and use the appropriate | ||
* cluster connection. | ||
* | ||
* @see SpringApplicationConfiguration | ||
*/ | ||
@Configuration | ||
@EnableIgniteRepositories | ||
public class IgniteClientSpringApplicationConfiguration { | ||
/** | ||
* Creates Apache Ignite thin client instance bean which will be used for accessing the Ignite cluster. | ||
* Note, that the name of the current bean must match value of {@link RepositoryConfig#igniteInstance} | ||
* property that {@link PersonRepository} is marked with. In this particular case, the default value of | ||
* {@link RepositoryConfig#igniteInstance} property is used. | ||
*/ | ||
@Bean | ||
public IgniteClient igniteInstance() { | ||
return Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1:" + DFLT_PORT)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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.springdata22.examples; | ||
|
||
import java.util.List; | ||
import javax.cache.Cache; | ||
import org.apache.ignite.springdata22.examples.model.Person; | ||
import org.apache.ignite.springdata22.repository.IgniteRepository; | ||
import org.apache.ignite.springdata22.repository.config.Query; | ||
import org.apache.ignite.springdata22.repository.config.RepositoryConfig; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
/** | ||
* Apache Ignite Spring Data repository backed by Ignite Person's cache. | ||
* </p> | ||
* To link the repository with an Ignite cache use {@link RepositoryConfig#cacheName()} annotation's parameter. | ||
*/ | ||
@RepositoryConfig(cacheName = "PersonCache") | ||
public interface PersonRepository extends IgniteRepository<Person, Long> { | ||
/** | ||
* Gets all the persons with the given name. | ||
* @param name Person name. | ||
* @return A list of Persons with the given first name. | ||
*/ | ||
public List<Person> findByFirstName(String name); | ||
|
||
/** | ||
* Returns top Person with the specified surname. | ||
* @param name Person surname. | ||
* @return Person that satisfy the query. | ||
*/ | ||
public Cache.Entry<Long, Person> findTopByLastNameLike(String name); | ||
|
||
/** | ||
* Getting ids of all the Person satisfying the custom query from {@link Query} annotation. | ||
* | ||
* @param orgId Query parameter. | ||
* @param pageable Pageable interface. | ||
* @return A list of Persons' ids. | ||
*/ | ||
@Query("SELECT id FROM Person WHERE orgId > ?") | ||
public List<Long> selectId(long orgId, Pageable pageable); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.springdata22.examples; | ||
|
||
import org.apache.ignite.Ignite; | ||
import org.apache.ignite.Ignition; | ||
import org.apache.ignite.configuration.IgniteConfiguration; | ||
import org.apache.ignite.springdata22.repository.IgniteRepository; | ||
import org.apache.ignite.springdata22.repository.config.EnableIgniteRepositories; | ||
import org.apache.ignite.springdata22.repository.support.IgniteRepositoryFactoryBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Every {@link IgniteRepository} is bound to a specific Apache Ignite that it communicates to in order to mutate and | ||
* read data via Spring Data API. To pass an instance of Apache Ignite cache to an {@link IgniteRepository} it's | ||
* required to initialize {@link IgniteRepositoryFactoryBean} with one of the following: | ||
* <ul> | ||
* <li>{@link Ignite} instance bean</li> | ||
* <li>{@link IgniteConfiguration} bean</li> | ||
* <li>A path to Ignite's Spring XML configuration named "igniteSpringCfgPath"</li> | ||
* <ul/> | ||
* In this example the first approach is utilized. | ||
*/ | ||
@Configuration | ||
@EnableIgniteRepositories | ||
public class SpringApplicationConfiguration { | ||
/** | ||
* Creating Apache Ignite instance bean. A bean will be passed to {@link IgniteRepositoryFactoryBean} to initialize | ||
* all Ignite based Spring Data repositories and connect to a cluster. | ||
*/ | ||
@Bean | ||
public Ignite igniteInstance() { | ||
return Ignition.start("modules/spring-data-2.2-ext/examples/config/example-spring-data.xml"); | ||
} | ||
} |
Oops, something went wrong.