提交 9dbad483 编写于 作者: 武汉红喜's avatar 武汉红喜

delete mongodb

上级 d0779c8f
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb;
import com.mongodb.Mongo;
import com.mongodb.WriteConcern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.core.convert.CustomConversions;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
import java.util.List;
/**
* @author Oliver Gierke
*/
@Configuration
@ComponentScan
@EnableMongoRepositories
class ApplicationConfig extends AbstractMongoConfiguration {
@Autowired
private List<Converter<?, ?>> converters;
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.config.AbstractMongoConfiguration#getDatabaseName()
*/
@Override
protected String getDatabaseName() {
return "e-store";
}
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.config.AbstractMongoConfiguration#mongo()
*/
@Override
public Mongo mongo() throws Exception {
Mongo mongo = new Mongo();
mongo.setWriteConcern(WriteConcern.SAFE);
return mongo;
}
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.config.AbstractMongoConfiguration#customConversions()
*/
@Override
public CustomConversions customConversions() {
return new CustomConversions(converters);
}
}
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb.core;
import org.springframework.data.annotation.Id;
import java.math.BigInteger;
/**
* Base class for document classes.
*
* @author Oliver Gierke
*/
public class AbstractDocument {
@Id
private BigInteger id;
/**
* Returns the identifier of the document.
*
* @return the id
*/
public BigInteger getId() {
return id;
}
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (this.id == null || obj == null || !(this.getClass().equals(obj.getClass()))) {
return false;
}
AbstractDocument that = (AbstractDocument) obj;
return this.id.equals(that.getId());
}
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return id == null ? 0 : id.hashCode();
}
}
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb.core;
import org.springframework.util.Assert;
/**
* An address.
*
* @author Oliver Gierke
*/
public class Address {
private final String street, city, country;
/**
* Creates a new {@link Address} from the given street, city and country.
*
* @param street must not be {@literal null} or empty.
* @param city must not be {@literal null} or empty.
* @param country must not be {@literal null} or empty.
*/
public Address(String street, String city, String country) {
Assert.hasText(street, "Street must not be null or empty!");
Assert.hasText(city, "City must not be null or empty!");
Assert.hasText(country, "Country must not be null or empty!");
this.street = street;
this.city = city;
this.country = country;
}
/**
* Returns a copy of the current {@link Address} instance which is a new entity in terms of persistence.
*
* @return
*/
public Address getCopy() {
return new Address(this.street, this.city, this.country);
}
/**
* Returns the street.
*
* @return
*/
public String getStreet() {
return street;
}
/**
* Returns the city.
*
* @return
*/
public String getCity() {
return city;
}
/**
* Returns the country.
*
* @return
*/
public String getCountry() {
return country;
}
}
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb.core;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.util.Assert;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* A customer.
*
* @author Oliver Gierke
*/
@Document
public class Customer extends AbstractDocument {
private String firstname, lastname;
@Field("email")
@Indexed(unique = true)
private EmailAddress emailAddress;
private Set<Address> addresses = new HashSet<Address>();
/**
* Creates a new {@link Customer} from the given firstname and lastname.
*
* @param firstname must not be {@literal null} or empty.
* @param lastname must not be {@literal null} or empty.
*/
public Customer(String firstname, String lastname) {
Assert.hasText(firstname);
Assert.hasText(lastname);
this.firstname = firstname;
this.lastname = lastname;
}
protected Customer() {
}
/**
* Adds the given {@link Address} to the {@link Customer}.
*
* @param address must not be {@literal null}.
*/
public void add(Address address) {
Assert.notNull(address);
this.addresses.add(address);
}
/**
* Returns the firstname of the {@link Customer}.
*
* @return
*/
public String getFirstname() {
return firstname;
}
/**
* Returns the lastname of the {@link Customer}.
*
* @return
*/
public String getLastname() {
return lastname;
}
/**
* Sets the lastname of the {@link Customer}.
*
* @param lastname
*/
public void setLastname(String lastname) {
this.lastname = lastname;
}
/**
* Returns the {@link EmailAddress} of the {@link Customer}.
*
* @return
*/
public EmailAddress getEmailAddress() {
return emailAddress;
}
/**
* Sets the {@link Customer}'s {@link EmailAddress}.
*
* @param emailAddress must not be {@literal null}.
*/
public void setEmailAddress(EmailAddress emailAddress) {
this.emailAddress = emailAddress;
}
/**
* Return the {@link Customer}'s addresses.
*
* @return
*/
public Set<Address> getAddresses() {
return Collections.unmodifiableSet(addresses);
}
}
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb.core;
import org.springframework.data.repository.Repository;
/**
* Repository interface to access {@link Customer}s.
*
* @author Oliver Gierke
*/
public interface CustomerRepository extends Repository<Customer, Long> {
/**
* Returns the customer with the given identifier.
*
* @param id
* @return
*/
Customer findOne(Long id);
/**
* Saves the given {@link Customer}. #
*
* @param customer
* @return
*/
Customer save(Customer customer);
/**
* Returns the {@link Customer} with the given {@link EmailAddress}.
*
* @return
*/
Customer findByEmailAddress(EmailAddress emailAddress);
}
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb.core;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.util.regex.Pattern;
/**
* Value object to represent email addresses.
*
* @author Oliver Gierke
*/
public final class EmailAddress {
private static final String EMAIL_REGEX = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
private static final Pattern PATTERN = Pattern.compile(EMAIL_REGEX);
@Field("email")
private final String value;
/**
* Creates a new {@link EmailAddress} from the given {@link String} representation.
*
* @param emailAddress must not be {@literal null} or empty.
*/
public EmailAddress(String emailAddress) {
Assert.isTrue(isValid(emailAddress), "Invalid email address!");
this.value = emailAddress;
}
/**
* Returns whether the given {@link String} is a valid {@link EmailAddress} which means you can safely instantiate the
* class.
*
* @param candidate
* @return
*/
public static boolean isValid(String candidate) {
return candidate == null ? false : PATTERN.matcher(candidate).matches();
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return value;
}
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof EmailAddress)) {
return false;
}
EmailAddress that = (EmailAddress) obj;
return this.value.equals(that.value);
}
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return value.hashCode();
}
@Component
static class EmailAddressToStringConverter implements Converter<EmailAddress, String> {
/*
* (non-Javadoc)
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
*/
@Override
public String convert(EmailAddress source) {
return source == null ? null : source.value;
}
}
@Component
static class StringToEmailAddressConverter implements Converter<String, EmailAddress> {
/*
* (non-Javadoc)
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
*/
public EmailAddress convert(String source) {
return StringUtils.hasText(source) ? new EmailAddress(source) : null;
}
}
}
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb.core;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;
/**
* {@link CustomerRepository} implementation using the Spring Data {@link MongoOperations} API.
*
* @author Oliver Gierke
*/
@Repository
@Profile("mongodb")
class MongoDbCustomerRepository implements CustomerRepository {
private final MongoOperations operations;
/**
* Creates a new {@link MongoDbCustomerRepository} using the given {@link MongoOperations}.
*
* @param operations must not be {@literal null}.
*/
@Autowired
public MongoDbCustomerRepository(MongoOperations operations) {
Assert.notNull(operations);
this.operations = operations;
}
/*
* (non-Javadoc)
* @see com.oreilly.springdata.mongodb.core.CustomerRepository#findOne(java.lang.Long)
*/
@Override
public Customer findOne(Long id) {
Query query = query(where("id").is(id));
return operations.findOne(query, Customer.class);
}
/*
* (non-Javadoc)
* @see com.oreilly.springdata.mongodb.core.CustomerRepository#save(com.oreilly.springdata.mongodb.core.Customer)
*/
@Override
public Customer save(Customer customer) {
operations.save(customer);
return customer;
}
/*
* (non-Javadoc)
* @see com.oreilly.springdata.mongodb.core.CustomerRepository#findByEmailAddress(com.oreilly.springdata.mongodb.core.EmailAddress)
*/
@Override
public Customer findByEmailAddress(EmailAddress emailAddress) {
Query query = query(where("emailAddress").is(emailAddress));
return operations.findOne(query, Customer.class);
}
}
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb.core;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.Assert;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* A product.
*
* @author Oliver Gierke
*/
@Document
public class Product extends AbstractDocument {
private String name, description;
private BigDecimal price;
private Map<String, String> attributes = new HashMap<String, String>();
/**
* Creates a new {@link Product} with the given name.
*
* @param name must not be {@literal null} or empty.
* @param price must not be {@literal null} or less than or equal to zero.
*/
public Product(String name, BigDecimal price) {
this(name, price, null);
}
/**
* Creates a new {@link Product} from the given name and description.
*
* @param name must not be {@literal null} or empty.
* @param price must not be {@literal null} or less than or equal to zero.
* @param description
*/
@PersistenceConstructor
public Product(String name, BigDecimal price, String description) {
Assert.hasText(name, "Name must not be null or empty!");
Assert.isTrue(BigDecimal.ZERO.compareTo(price) < 0, "Price must be greater than zero!");
this.name = name;
this.price = price;
this.description = description;
}
/**
* Sets the attribute with the given name to the given value.
*
* @param name must not be {@literal null} or empty.
* @param value
*/
public void setAttribute(String name, String value) {
Assert.hasText(name);
if (value == null) {
this.attributes.remove(value);
} else {
this.attributes.put(name, value);
}
}
/**
* Returns the {@link Product}'s name.
*
* @return
*/
public String getName() {
return name;
}
/**
* Returns the {@link Product}'s description.
*
* @return
*/
public String getDescription() {
return description;
}
/**
* Returns all the custom attributes of the {@link Product}.
*
* @return
*/
public Map<String, String> getAttributes() {
return Collections.unmodifiableMap(attributes);
}
/**
* Returns the price of the {@link Product}.
*
* @return
*/
public BigDecimal getPrice() {
return price;
}
}
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb.core;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
/**
* Repository interface to access {@link Product}s.
*
* @author Oliver Gierke
*/
public interface ProductRepository extends CrudRepository<Product, Long>, QueryDslPredicateExecutor<Product> {
/**
* Returns a {@link Page} of {@link Product}s having a description which contains the given snippet.
*
* @param description
* @param pageable
* @return
*/
Page<Product> findByDescriptionContaining(String description, Pageable pageable);
/**
* Returns all {@link Product}s having the given attribute.
*
* @return
*/
@Query("{ ?0 : ?1 }")
List<Product> findByAttributes(String key, String value);
}
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb.order;
import org.hongxi.whatsmars.spring.data.mongodb.core.AbstractDocument;
import org.hongxi.whatsmars.spring.data.mongodb.core.Product;
import org.hongxi.whatsmars.spring.data.mongodb.core.Product;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.util.Assert;
import java.math.BigDecimal;
/**
* @author Oliver Gierke
*/
public class LineItem extends AbstractDocument {
@DBRef
private Product product;
private BigDecimal price;
private int amount;
/**
* Creates a new {@link LineItem} for the given {@link Product}.
*
* @param product must not be {@literal null}.
*/
public LineItem(Product product) {
this(product, 1);
}
/**
* Creates a new {@link LineItem} for the given {@link Product} and amount.
*
* @param product must not be {@literal null}.
* @param amount
*/
public LineItem(Product product, int amount) {
Assert.notNull(product, "The given Product must not be null!");
Assert.isTrue(amount > 0, "The amount of Products to be bought must be greater than 0!");
this.product = product;
this.amount = amount;
this.price = product.getPrice();
}
public LineItem() {
}
/**
* Returns the {@link Product} the {@link LineItem} refers to.
*
* @return
*/
public Product getProduct() {
return product;
}
/**
* Returns the amount of {@link Product}s to be ordered.
*
* @return
*/
public int getAmount() {
return amount;
}
/**
* Returns the price a single unit of the {@link LineItem}'s product.
*
* @return the price
*/
public BigDecimal getUnitPrice() {
return price;
}
/**
* Returns the total for the {@link LineItem}.
*
* @return
*/
public BigDecimal getTotal() {
return price.multiply(BigDecimal.valueOf(amount));
}
}
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb.order;
import org.hongxi.whatsmars.spring.data.mongodb.core.AbstractDocument;
import org.hongxi.whatsmars.spring.data.mongodb.core.Address;
import org.hongxi.whatsmars.spring.data.mongodb.core.Customer;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.Assert;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* @author Oliver Gierke
*/
@Document
public class Order extends AbstractDocument {
@DBRef
private Customer customer;
private Address billingAddress;
private Address shippingAddress;
private Set<LineItem> lineItems = new HashSet<LineItem>();
/**
* Creates a new {@link Order} for the given {@link Customer}.
*
* @param customer must not be {@literal null}.
* @param shippingAddress must not be {@literal null}.
*/
public Order(Customer customer, Address shippingAddress) {
this(customer, shippingAddress, null);
}
/**
* Creates a new {@link Order} for the given {@link Customer}, shipping and billing {@link Address}.
*
* @param customer must not be {@literal null}.
* @param shippingAddress must not be {@literal null}.
* @param billingAddress can be {@literal null}.
*/
@PersistenceConstructor
public Order(Customer customer, Address shippingAddress, Address billingAddress) {
Assert.notNull(customer);
Assert.notNull(shippingAddress);
this.customer = customer;
this.shippingAddress = shippingAddress;
this.billingAddress = billingAddress;
}
/**
* Adds the given {@link LineItem} to the {@link Order}.
*
* @param lineItem
*/
public void add(LineItem lineItem) {
this.lineItems.add(lineItem);
}
/**
* Returns the {@link Customer} who placed the {@link Order}.
*
* @return
*/
public Customer getCustomer() {
return customer;
}
/**
* Returns the billing {@link Address} for this order.
*
* @return
*/
public Address getBillingAddress() {
return billingAddress != null ? billingAddress : shippingAddress;
}
/**
* Returns the shipping {@link Address} for this order;
*
* @return
*/
public Address getShippingAddress() {
return shippingAddress;
}
/**
* Returns all {@link LineItem}s currently belonging to the {@link Order}.
*
* @return
*/
public Set<LineItem> getLineItems() {
return Collections.unmodifiableSet(lineItems);
}
/**
* Returns the total of the {@link Order}.
*
* @return
*/
public BigDecimal getTotal() {
BigDecimal total = BigDecimal.ZERO;
for (LineItem item : lineItems) {
total = total.add(item.getTotal());
}
return total;
}
}
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.hongxi.whatsmars.spring.data.mongodb.order;
import org.hongxi.whatsmars.spring.data.mongodb.core.Customer;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
* Repository to access {@link Order}s.
*
* @author Oliver Gierke
*/
public interface OrderRepository extends PagingAndSortingRepository<Order, Long> {
/**
* Returns all {@link Order}s of the given {@link Customer}.
*
* @param customer
* @return
*/
List<Order> findByCustomer(Customer customer);
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<mongo:db-factory id="mongoDbFactory" dbname="e-store" />
<mongo:mapping-converter id="mongoConverter" base-package="com.oreilly.springdata.mongodb">
<mongo:custom-converters base-package="com.oreilly.springdata.mongodb" />
</mongo:mapping-converter>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory" />
<constructor-arg ref="mongoConverter" />
<property name="writeConcern" value="SAFE" />
</bean>
<mongo:repositories base-package="org.hongxi.whatsmars.spring.data.mongodb" />
</beans>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册