|
| 1 | +/* |
| 2 | + * Copyright 2012-2019 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package software.xdev.spring.data.eclipse.store.demo.lazy; |
| 18 | + |
| 19 | +import org.slf4j.Logger; |
| 20 | +import org.slf4j.LoggerFactory; |
| 21 | +import org.springframework.boot.CommandLineRunner; |
| 22 | +import org.springframework.boot.SpringApplication; |
| 23 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 24 | + |
| 25 | + |
| 26 | +@SpringBootApplication |
| 27 | +public class LazyDemoApplication implements CommandLineRunner |
| 28 | +{ |
| 29 | + private static final Logger LOG = LoggerFactory.getLogger(LazyDemoApplication.class); |
| 30 | + private final CustomerRepository customerRepository; |
| 31 | + private final PetRepository petRepository; |
| 32 | + |
| 33 | + public LazyDemoApplication( |
| 34 | + final CustomerRepository customerRepository, |
| 35 | + final PetRepository petRepository |
| 36 | + ) |
| 37 | + { |
| 38 | + this.customerRepository = customerRepository; |
| 39 | + this.petRepository = petRepository; |
| 40 | + } |
| 41 | + |
| 42 | + public static void main(final String[] args) |
| 43 | + { |
| 44 | + SpringApplication.run(LazyDemoApplication.class, args); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public void run(final String... args) |
| 49 | + { |
| 50 | + this.customerRepository.deleteAll(); |
| 51 | + |
| 52 | + // save a couple of customers |
| 53 | + this.customerRepository.save(new Customer("Stevie", "Nicks")); |
| 54 | + this.customerRepository.save(new Customer("Mick", "Fleetwood")); |
| 55 | + |
| 56 | + // fetch all customers |
| 57 | + LOG.info("Customers found with findAll():"); |
| 58 | + this.customerRepository.findAll().forEach(c -> LOG.info(c.toString())); |
| 59 | + |
| 60 | + // save a pet |
| 61 | + this.petRepository.save(new Pet("1", "Peter", 2)); |
| 62 | + |
| 63 | + // fetch all pets |
| 64 | + LOG.info("Pets found with findAll():"); |
| 65 | + this.petRepository.findAll().forEach(p -> LOG.info(p.toString())); |
| 66 | + } |
| 67 | +} |
0 commit comments