9 changed files with 271 additions and 15 deletions
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
/* |
||||
* Copyright 2011 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.springframework.data.mongodb.config; |
||||
|
||||
import java.beans.PropertyEditorSupport; |
||||
import java.net.UnknownHostException; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.springframework.util.StringUtils; |
||||
|
||||
import com.mongodb.ServerAddress; |
||||
import com.mongodb.WriteConcern; |
||||
|
||||
/** |
||||
* Parse a string to a WriteConcern. If it is a well know String as identified by the WriteConcern.valueOf, use the |
||||
* well known WriteConcern value, otherwise pass the string as is to the constructor of the write concern. |
||||
* There is no support for other constructor signatures when parsing from a string value. |
||||
* |
||||
* @author Mark Pollack |
||||
* |
||||
*/ |
||||
public class WriteConcernPropertyEditor extends PropertyEditorSupport { |
||||
|
||||
/** |
||||
* Parse a string to a List<ServerAddress> |
||||
*/ |
||||
public void setAsText(String writeConcernString) { |
||||
|
||||
WriteConcern writeConcern = WriteConcern.valueOf(writeConcernString); |
||||
if (writeConcern != null) { |
||||
// have a well known string
|
||||
setValue(writeConcern); |
||||
} else { |
||||
// pass on the string to the constructor
|
||||
setValue(new WriteConcern(writeConcernString)); |
||||
} |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
package org.springframework.data.mongodb.config; |
||||
|
||||
import com.mongodb.WriteConcern; |
||||
|
||||
public class MyWriteConcern { |
||||
|
||||
public MyWriteConcern(WriteConcern wc) { |
||||
this._w = wc.getWObject(); |
||||
this._continueOnErrorForInsert = wc.getContinueOnErrorForInsert(); |
||||
this._fsync = wc.getFsync(); |
||||
this._j = wc.getJ(); |
||||
this._wtimeout = wc.getWtimeout(); |
||||
} |
||||
|
||||
Object _w = 0; |
||||
int _wtimeout = 0; |
||||
boolean _fsync = false; |
||||
boolean _j = false; |
||||
boolean _continueOnErrorForInsert = false; |
||||
@Override |
||||
public int hashCode() { |
||||
final int prime = 31; |
||||
int result = 1; |
||||
result = prime * result + (_continueOnErrorForInsert ? 1231 : 1237); |
||||
result = prime * result + (_fsync ? 1231 : 1237); |
||||
result = prime * result + (_j ? 1231 : 1237); |
||||
result = prime * result + ((_w == null) ? 0 : _w.hashCode()); |
||||
result = prime * result + _wtimeout; |
||||
return result; |
||||
} |
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
if (this == obj) |
||||
return true; |
||||
if (obj == null) |
||||
return false; |
||||
if (getClass() != obj.getClass()) |
||||
return false; |
||||
MyWriteConcern other = (MyWriteConcern) obj; |
||||
if (_continueOnErrorForInsert != other._continueOnErrorForInsert) |
||||
return false; |
||||
if (_fsync != other._fsync) |
||||
return false; |
||||
if (_j != other._j) |
||||
return false; |
||||
if (_w == null) { |
||||
if (other._w != null) |
||||
return false; |
||||
} else if (!_w.equals(other._w)) |
||||
return false; |
||||
if (_wtimeout != other._wtimeout) |
||||
return false; |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
<?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-1.0.xsd |
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> |
||||
|
||||
<mongo:db-factory id="first" mongo-ref="mongo" write-concern="rack1" /> |
||||
|
||||
<mongo:mongo id="mongo"> |
||||
<mongo:options max-auto-connect-retry-time="27" /> |
||||
</mongo:mongo> |
||||
|
||||
<!-- now part of the namespace |
||||
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> |
||||
<property name="customEditors"> |
||||
<map> |
||||
<entry key="com.mongodb.WriteConcern" value="org.springframework.data.mongodb.config.WriteConcernPropertyEditor"/> |
||||
</map> |
||||
</property> |
||||
</bean> |
||||
--> |
||||
|
||||
</beans> |
||||
Loading…
Reference in new issue