Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
9dbad483
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9dbad483
编写于
2月 01, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delete mongodb
上级
d0779c8f
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
0 addition
and
1060 deletion
+0
-1060
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/ApplicationConfig.java
...ngxi/whatsmars/spring/data/mongodb/ApplicationConfig.java
+0
-73
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/AbstractDocument.java
.../whatsmars/spring/data/mongodb/core/AbstractDocument.java
+0
-69
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/Address.java
...rg/hongxi/whatsmars/spring/data/mongodb/core/Address.java
+0
-82
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/Customer.java
...g/hongxi/whatsmars/spring/data/mongodb/core/Customer.java
+0
-125
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/CustomerRepository.java
...hatsmars/spring/data/mongodb/core/CustomerRepository.java
+0
-49
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/EmailAddress.java
...ngxi/whatsmars/spring/data/mongodb/core/EmailAddress.java
+0
-121
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/MongoDbCustomerRepository.java
...s/spring/data/mongodb/core/MongoDbCustomerRepository.java
+0
-83
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/Product.java
...rg/hongxi/whatsmars/spring/data/mongodb/core/Product.java
+0
-119
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/ProductRepository.java
...whatsmars/spring/data/mongodb/core/ProductRepository.java
+0
-49
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/order/LineItem.java
.../hongxi/whatsmars/spring/data/mongodb/order/LineItem.java
+0
-100
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/order/Order.java
...org/hongxi/whatsmars/spring/data/mongodb/order/Order.java
+0
-131
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/order/OrderRepository.java
.../whatsmars/spring/data/mongodb/order/OrderRepository.java
+0
-37
whatsmars-spring/src/main/resources/spring-mongodb.xml
whatsmars-spring/src/main/resources/spring-mongodb.xml
+0
-22
未找到文件。
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/ApplicationConfig.java
已删除
100644 → 0
浏览文件 @
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
);
}
}
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/AbstractDocument.java
已删除
100644 → 0
浏览文件 @
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.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
();
}
}
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/Address.java
已删除
100644 → 0
浏览文件 @
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.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
;
}
}
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/Customer.java
已删除
100644 → 0
浏览文件 @
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.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
);
}
}
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/CustomerRepository.java
已删除
100644 → 0
浏览文件 @
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.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
);
}
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/EmailAddress.java
已删除
100644 → 0
浏览文件 @
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.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
;
}
}
}
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/MongoDbCustomerRepository.java
已删除
100644 → 0
浏览文件 @
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.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
);
}
}
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/Product.java
已删除
100644 → 0
浏览文件 @
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.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
;
}
}
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/core/ProductRepository.java
已删除
100644 → 0
浏览文件 @
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.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
);
}
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/order/LineItem.java
已删除
100644 → 0
浏览文件 @
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.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
));
}
}
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/order/Order.java
已删除
100644 → 0
浏览文件 @
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.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
;
}
}
whatsmars-spring/src/main/java/org/hongxi/whatsmars/spring/data/mongodb/order/OrderRepository.java
已删除
100644 → 0
浏览文件 @
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.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
);
}
whatsmars-spring/src/main/resources/spring-mongodb.xml
已删除
100644 → 0
浏览文件 @
d0779c8f
<?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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录