// Path: spring-data-plain-demo/src/main/java/org/springframework/data/demo/data/DeviceInfo.java
// @Entity
// @org.springframework.data.mongodb.core.mapping.Document
// @Data
// public class DeviceInfo {
//     @NotNull
//     @Indexed(unique = true)
//     @Column(unique = true)
//     private String deviceId;
//     private String deviceName;
//     @Id
//     @com.couchbase.client.java.repository.annotation.Id
//     @GeneratedValue(generator = "system-uuid")
//     @GenericGenerator(name = "system-uuid", strategy = "uuid2")
//     private String id;
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/data/LocationUpdate.java
// @Document
// @Data
// @EqualsAndHashCode(of = {"locTime", "device"})
// public class LocationUpdate {
// 	@Id
// 	@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
// 	private String id;
// 
// 	@Field
// 	@NotNull
// 	private DeviceInfo device;
// 
// 	@Field
// 	private double latX;
// 
// 	@Field
// 	private double latY;
// 
// 	@Field
// 	private String locDetail;
// 
// 	@NotNull
// 	@Field
// 	private Date locTime;
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/repository/DeviceInfoRepository.java
// @N1qlPrimaryIndexed
// @ViewIndexed(designDoc = "deviceInfo")
// public interface DeviceInfoRepository extends CouchbaseRepository<DeviceInfo, String> {
// 	DeviceInfo findByDeviceId(String deviceId);
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/repository/LocationUpdateRepository.java
// @N1qlPrimaryIndexed
// @N1qlSecondaryIndexed(indexName = "all")
// public interface LocationUpdateRepository extends CouchbaseRepository<LocationUpdate, String> {
// 	List<LocationUpdate> findByLocTimeBetweenAndDevice_DeviceId(Date startDate, Date endDate, String deviceId);
// }


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.demo.data.DeviceInfo;
import org.springframework.data.demo.data.LocationUpdate;
import org.springframework.data.demo.repository.DeviceInfoRepository;
import org.springframework.data.demo.repository.LocationUpdateRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
package org.springframework.data.demo.service;



@Service
@Transactional
@Validated
public class LocationAndDeviceServiceImpl implements LocationAndDeviceService {
    private final static Logger logger = LoggerFactory.getLogger(LocationAndDeviceServiceImpl.class);
    @Autowired
    protected LocationUpdateRepository locationUpdateRepository;
    @Autowired
    protected DeviceInfoRepository deviceInfoRepository;

    @Override
    @Transactional
    public void deleteAllData() {
        logger.info("deleteAllData-start");
        locationUpdateRepository.deleteAll();
        deviceInfoRepository.deleteAll();
        logger.info("deleteAllData-complete");
    }

    @Override
    @Transactional(readOnly = true)
    public DeviceInfo findDevice(String deviceId) {
        logger.info("findDevice:" + deviceId);
        return deviceInfoRepository.findByDeviceId(deviceId);
    }

    @Override
    @Transactional(readOnly = true)
    public List<LocationUpdate> findLocations(String deviceId, Date startDate, Date endDate) {
// Path: spring-data-plain-demo/src/main/java/org/springframework/data/demo/data/DeviceInfo.java
// @Entity
// @org.springframework.data.mongodb.core.mapping.Document
// @Data
// public class DeviceInfo {
//     @NotNull
//     @Indexed(unique = true)
//     @Column(unique = true)
//     private String deviceId;
//     private String deviceName;
//     @Id
//     @com.couchbase.client.java.repository.annotation.Id
//     @GeneratedValue(generator = "system-uuid")
//     @GenericGenerator(name = "system-uuid", strategy = "uuid2")
//     private String id;
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/data/LocationUpdate.java
// @Document
// @Data
// @EqualsAndHashCode(of = {"locTime", "device"})
// public class LocationUpdate {
// 	@Id
// 	@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
// 	private String id;
// 
// 	@Field
// 	@NotNull
// 	private DeviceInfo device;
// 
// 	@Field
// 	private double latX;
// 
// 	@Field
// 	private double latY;
// 
// 	@Field
// 	private String locDetail;
// 
// 	@NotNull
// 	@Field
// 	private Date locTime;
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/repository/DeviceInfoRepository.java
// @N1qlPrimaryIndexed
// @ViewIndexed(designDoc = "deviceInfo")
// public interface DeviceInfoRepository extends CouchbaseRepository<DeviceInfo, String> {
// 	DeviceInfo findByDeviceId(String deviceId);
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/repository/LocationUpdateRepository.java
// @N1qlPrimaryIndexed
// @N1qlSecondaryIndexed(indexName = "all")
// public interface LocationUpdateRepository extends CouchbaseRepository<LocationUpdate, String> {
// 	List<LocationUpdate> findByLocTimeBetweenAndDevice_DeviceId(Date startDate, Date endDate, String deviceId);
// }


// Path: spring-data-plain-demo/src/main/java/org/springframework/data/demo/service/LocationAndDeviceServiceImpl.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.demo.data.DeviceInfo;
import org.springframework.data.demo.data.LocationUpdate;
import org.springframework.data.demo.repository.DeviceInfoRepository;
import org.springframework.data.demo.repository.LocationUpdateRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;

package org.springframework.data.demo.service;



@Service
@Transactional
@Validated
public class LocationAndDeviceServiceImpl implements LocationAndDeviceService {
    private final static Logger logger = LoggerFactory.getLogger(LocationAndDeviceServiceImpl.class);
    @Autowired
    protected LocationUpdateRepository locationUpdateRepository;
    @Autowired
    protected DeviceInfoRepository deviceInfoRepository;

    @Override
    @Transactional
    public void deleteAllData() {
        logger.info("deleteAllData-start");
        locationUpdateRepository.deleteAll();
        deviceInfoRepository.deleteAll();
        logger.info("deleteAllData-complete");
    }

    @Override
    @Transactional(readOnly = true)
    public DeviceInfo findDevice(String deviceId) {
        logger.info("findDevice:" + deviceId);
        return deviceInfoRepository.findByDeviceId(deviceId);
    }

    @Override
    @Transactional(readOnly = true)
    public List<LocationUpdate> findLocations(String deviceId, Date startDate, Date endDate) {
        logger.info("findLocations:" + deviceId + "," + startDate + "," + endDate);