Format, organize imports, remove eclipse artifacts
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
|
*.iws
|
||||||
target
|
target
|
||||||
.springBeans
|
.springBeans
|
||||||
.ant-targets-build.xml
|
.ant-targets-build.xml
|
||||||
|
|||||||
17
.project
17
.project
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>spring-data-document-dist</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#Fri Oct 08 14:31:54 EDT 2010
|
|
||||||
activeProfiles=
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
fullBuildGoals=process-test-resources
|
|
||||||
includeModules=false
|
|
||||||
resolveWorkspaceProjects=true
|
|
||||||
resourceFilterGoals=process-resources resources\:testResources
|
|
||||||
skipCompilerPlugin=true
|
|
||||||
version=1
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
|
||||||
<classpathentry kind="src" path="src/test/java"/>
|
|
||||||
<classpathentry kind="src" path="src/test/resources"/>
|
|
||||||
<classpathentry kind="src" path="src/main/resources"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
|
||||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
|
||||||
</classpath>
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>spring-data-couchdb</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
||||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#Wed Oct 06 14:49:48 EDT 2010
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.5
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#Wed Oct 06 14:49:46 EDT 2010
|
|
||||||
activeProfiles=
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
fullBuildGoals=process-test-resources
|
|
||||||
includeModules=false
|
|
||||||
resolveWorkspaceProjects=true
|
|
||||||
resourceFilterGoals=process-resources resources\:testResources
|
|
||||||
skipCompilerPlugin=true
|
|
||||||
version=1
|
|
||||||
@@ -23,6 +23,7 @@ public class CouchServerResourceUsageException extends InvalidDataAccessResource
|
|||||||
/**
|
/**
|
||||||
* Create a new CouchServerResourceUsageException,
|
* Create a new CouchServerResourceUsageException,
|
||||||
* wrapping an arbitrary HttpServerErrorException.
|
* wrapping an arbitrary HttpServerErrorException.
|
||||||
|
*
|
||||||
* @param cause the HttpServerErrorException thrown
|
* @param cause the HttpServerErrorException thrown
|
||||||
*/
|
*/
|
||||||
public CouchServerResourceUsageException(HttpServerErrorException cause) {
|
public CouchServerResourceUsageException(HttpServerErrorException cause) {
|
||||||
|
|||||||
@@ -17,14 +17,13 @@ package org.springframework.data.document.couchdb;
|
|||||||
|
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.client.HttpServerErrorException;
|
|
||||||
|
|
||||||
public class CouchUsageException extends InvalidDataAccessApiUsageException
|
public class CouchUsageException extends InvalidDataAccessApiUsageException {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new CouchUsageException,
|
* Create a new CouchUsageException,
|
||||||
* wrapping an arbitrary HttpServerErrorException.
|
* wrapping an arbitrary HttpServerErrorException.
|
||||||
|
*
|
||||||
* @param cause the HttpServerErrorException thrown
|
* @param cause the HttpServerErrorException thrown
|
||||||
*/
|
*/
|
||||||
public CouchUsageException(HttpClientErrorException cause) {
|
public CouchUsageException(HttpClientErrorException cause) {
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ package org.springframework.data.document.couchdb;
|
|||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.web.client.HttpStatusCodeException;
|
import org.springframework.web.client.HttpStatusCodeException;
|
||||||
|
|
||||||
public class DocumentExistsException extends DataIntegrityViolationException
|
public class DocumentExistsException extends DataIntegrityViolationException {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new DocumentExistsException,
|
* Create a new DocumentExistsException,
|
||||||
* wrapping an arbitrary HttpServerErrorException.
|
* wrapping an arbitrary HttpServerErrorException.
|
||||||
|
*
|
||||||
* @param cause the HttpServerErrorException thrown
|
* @param cause the HttpServerErrorException thrown
|
||||||
*/
|
*/
|
||||||
public DocumentExistsException(String documentId, HttpStatusCodeException cause) {
|
public DocumentExistsException(String documentId, HttpStatusCodeException cause) {
|
||||||
|
|||||||
@@ -32,7 +32,4 @@ public class DocumentRetrievalFailureException extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public class UncategorizedCouchDataAccessException extends UncategorizedDataAcce
|
|||||||
/**
|
/**
|
||||||
* Create a new HibernateSystemException,
|
* Create a new HibernateSystemException,
|
||||||
* wrapping an arbitrary HibernateException.
|
* wrapping an arbitrary HibernateException.
|
||||||
|
*
|
||||||
* @param cause the HibernateException thrown
|
* @param cause the HibernateException thrown
|
||||||
*/
|
*/
|
||||||
public UncategorizedCouchDataAccessException(RestClientException cause) {
|
public UncategorizedCouchDataAccessException(RestClientException cause) {
|
||||||
|
|||||||
@@ -69,9 +69,4 @@ public class DbInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,18 +26,9 @@ import org.springframework.data.document.couchdb.CouchUsageException;
|
|||||||
import org.springframework.data.document.couchdb.DocumentRetrievalFailureException;
|
import org.springframework.data.document.couchdb.DocumentRetrievalFailureException;
|
||||||
import org.springframework.data.document.couchdb.UncategorizedCouchDataAccessException;
|
import org.springframework.data.document.couchdb.UncategorizedCouchDataAccessException;
|
||||||
import org.springframework.data.document.couchdb.support.CouchUtils;
|
import org.springframework.data.document.couchdb.support.CouchUtils;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.*;
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.HttpMethod;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.*;
|
||||||
import org.springframework.web.client.HttpServerErrorException;
|
|
||||||
import org.springframework.web.client.RestClientException;
|
|
||||||
import org.springframework.web.client.RestOperations;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
|
|
||||||
public class CouchTemplate implements CouchOperations {
|
public class CouchTemplate implements CouchOperations {
|
||||||
@@ -50,6 +41,7 @@ public class CouchTemplate implements CouchOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of CouchDbDocumentTemplate with a default database
|
* Constructs an instance of CouchDbDocumentTemplate with a default database
|
||||||
|
*
|
||||||
* @param defaultDatabaseUrl the default database to connect to
|
* @param defaultDatabaseUrl the default database to connect to
|
||||||
*/
|
*/
|
||||||
public CouchTemplate(String defaultDatabaseUrl) {
|
public CouchTemplate(String defaultDatabaseUrl) {
|
||||||
@@ -59,6 +51,7 @@ public class CouchTemplate implements CouchOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of CouchDbDocumentTemplate with a default database
|
* Constructs an instance of CouchDbDocumentTemplate with a default database
|
||||||
|
*
|
||||||
* @param defaultDatabaseUrl the default database to connect to
|
* @param defaultDatabaseUrl the default database to connect to
|
||||||
*/
|
*/
|
||||||
public CouchTemplate(String defaultDatabaseUrl, RestOperations restOperations) {
|
public CouchTemplate(String defaultDatabaseUrl, RestOperations restOperations) {
|
||||||
@@ -68,9 +61,6 @@ public class CouchTemplate implements CouchOperations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public <T> T findOne(String id, Class<T> targetClass) {
|
public <T> T findOne(String id, Class<T> targetClass) {
|
||||||
Assert.state(defaultDocumentUrl != null, "defaultDatabaseUrl must be set to use this method");
|
Assert.state(defaultDocumentUrl != null, "defaultDatabaseUrl must be set to use this method");
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -17,20 +17,9 @@ package org.springframework.data.document.couchdb.core.support;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.JsonEncoding;
|
import org.codehaus.jackson.*;
|
||||||
import org.codehaus.jackson.JsonGenerationException;
|
|
||||||
import org.codehaus.jackson.JsonGenerator;
|
|
||||||
import org.codehaus.jackson.JsonNode;
|
|
||||||
import org.codehaus.jackson.JsonParseException;
|
|
||||||
import org.codehaus.jackson.JsonParser;
|
|
||||||
import org.codehaus.jackson.JsonProcessingException;
|
|
||||||
import org.codehaus.jackson.JsonToken;
|
|
||||||
import org.codehaus.jackson.map.JsonMappingException;
|
import org.codehaus.jackson.map.JsonMappingException;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.codehaus.jackson.map.type.TypeFactory;
|
import org.codehaus.jackson.map.type.TypeFactory;
|
||||||
@@ -67,7 +56,7 @@ public class CouchDbMappingJacksonHttpMessageConverter extends
|
|||||||
/**
|
/**
|
||||||
* Sets the {@code ObjectMapper} for this view. If not set, a default
|
* Sets the {@code ObjectMapper} for this view. If not set, a default
|
||||||
* {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
|
* {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
|
||||||
* <p>
|
* <p/>
|
||||||
* Setting a custom-configured {@code ObjectMapper} is one way to take
|
* Setting a custom-configured {@code ObjectMapper} is one way to take
|
||||||
* further control of the JSON serialization process. For example, an
|
* further control of the JSON serialization process. For example, an
|
||||||
* extended {@link org.codehaus.jackson.map.SerializerFactory} can be
|
* extended {@link org.codehaus.jackson.map.SerializerFactory} can be
|
||||||
@@ -84,7 +73,7 @@ public class CouchDbMappingJacksonHttpMessageConverter extends
|
|||||||
/**
|
/**
|
||||||
* Indicates whether the JSON output by this view should be prefixed with
|
* Indicates whether the JSON output by this view should be prefixed with
|
||||||
* "{} &&". Default is false.
|
* "{} &&". Default is false.
|
||||||
* <p>
|
* <p/>
|
||||||
* Prefixing the JSON string in this manner is used to help prevent JSON
|
* Prefixing the JSON string in this manner is used to help prevent JSON
|
||||||
* Hijacking. The prefix renders the string syntactically invalid as a
|
* Hijacking. The prefix renders the string syntactically invalid as a
|
||||||
* script so that it cannot be hijacked. This prefix does not affect the
|
* script so that it cannot be hijacked. This prefix does not affect the
|
||||||
@@ -103,13 +92,13 @@ public class CouchDbMappingJacksonHttpMessageConverter extends
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Jackson {@link JavaType} for the specific class.
|
* Returns the Jackson {@link JavaType} for the specific class.
|
||||||
*
|
* <p/>
|
||||||
* <p>
|
* <p/>
|
||||||
* Default implementation returns
|
* Default implementation returns
|
||||||
* {@link TypeFactory#type(java.lang.reflect.Type)}, but this can be
|
* {@link TypeFactory#type(java.lang.reflect.Type)}, but this can be
|
||||||
* overridden in subclasses, to allow for custom generic collection
|
* overridden in subclasses, to allow for custom generic collection
|
||||||
* handling. For instance:
|
* handling. For instance:
|
||||||
*
|
* <p/>
|
||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* protected JavaType getJavaType(Class<?> clazz) {
|
* protected JavaType getJavaType(Class<?> clazz) {
|
||||||
* if (List.class.isAssignableFrom(clazz)) {
|
* if (List.class.isAssignableFrom(clazz)) {
|
||||||
@@ -120,8 +109,7 @@ public class CouchDbMappingJacksonHttpMessageConverter extends
|
|||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param clazz
|
* @param clazz the class to return the java type for
|
||||||
* the class to return the java type for
|
|
||||||
* @return the java type
|
* @return the java type
|
||||||
*/
|
*/
|
||||||
protected JavaType getJavaType(Class<?> clazz) {
|
protected JavaType getJavaType(Class<?> clazz) {
|
||||||
@@ -238,6 +226,7 @@ public class CouchDbMappingJacksonHttpMessageConverter extends
|
|||||||
private boolean atEndOfRows(JsonParser jp) {
|
private boolean atEndOfRows(JsonParser jp) {
|
||||||
return jp.getCurrentToken() != JsonToken.START_OBJECT;
|
return jp.getCurrentToken() != JsonToken.START_OBJECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void skipToField(JsonParser jp, String fieldName, ParseState state) throws JsonParseException, IOException {
|
private void skipToField(JsonParser jp, String fieldName, ParseState state) throws JsonParseException, IOException {
|
||||||
String lastFieldName = null;
|
String lastFieldName = null;
|
||||||
while (jp.getCurrentToken() != null) {
|
while (jp.getCurrentToken() != null) {
|
||||||
|
|||||||
@@ -15,15 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.couchdb.monitor;
|
package org.springframework.data.document.couchdb.monitor;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class to encapsulate common configuration settings when connecting to a CouchDB database
|
* Base class to encapsulate common configuration settings when connecting to a CouchDB database
|
||||||
*
|
*
|
||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractMonitor {
|
public abstract class AbstractMonitor {
|
||||||
|
|
||||||
@@ -33,6 +30,7 @@ public abstract class AbstractMonitor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the databaseUrl used to connect to CouchDB
|
* Gets the databaseUrl used to connect to CouchDB
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getDatabaseUrl() {
|
public String getDatabaseUrl() {
|
||||||
@@ -40,7 +38,4 @@ public abstract class AbstractMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
* Expose basic server information via JMX
|
* Expose basic server information via JMX
|
||||||
*
|
*
|
||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@ManagedResource(description = "Server Information")
|
@ManagedResource(description = "Server Information")
|
||||||
public class ServerInfo extends AbstractMonitor {
|
public class ServerInfo extends AbstractMonitor {
|
||||||
|
|||||||
@@ -17,11 +17,10 @@
|
|||||||
package org.springframework.data.document.couchdb.support;
|
package org.springframework.data.document.couchdb.support;
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.data.document.UncategorizedDocumentStoreException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class featuring helper methods for internal CouchDB classes.
|
* Helper class featuring helper methods for internal CouchDB classes.
|
||||||
*
|
* <p/>
|
||||||
* <p>Mainly intended for internal use within the framework.
|
* <p>Mainly intended for internal use within the framework.
|
||||||
*
|
*
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
@@ -35,6 +34,7 @@ public abstract class CouchUtils {
|
|||||||
* <code>org.springframework.dao</code> hierarchy.
|
* <code>org.springframework.dao</code> hierarchy.
|
||||||
* Return null if no translation is appropriate: any other exception may
|
* Return null if no translation is appropriate: any other exception may
|
||||||
* have resulted from user code, and should not be translated.
|
* have resulted from user code, and should not be translated.
|
||||||
|
*
|
||||||
* @param ex runtime exception that occurred
|
* @param ex runtime exception that occurred
|
||||||
* @return the corresponding DataAccessException instance,
|
* @return the corresponding DataAccessException instance,
|
||||||
* or <code>null</code> if the exception should not be translated
|
* or <code>null</code> if the exception should not be translated
|
||||||
@@ -46,6 +46,7 @@ public abstract class CouchUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an id variable to a URL
|
* Adds an id variable to a URL
|
||||||
|
*
|
||||||
* @param url the URL to modify
|
* @param url the URL to modify
|
||||||
* @return the modified URL
|
* @return the modified URL
|
||||||
*/
|
*/
|
||||||
@@ -56,6 +57,7 @@ public abstract class CouchUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a 'changes since' variable to a URL
|
* Adds a 'changes since' variable to a URL
|
||||||
|
*
|
||||||
* @param url
|
* @param url
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -65,6 +67,7 @@ public abstract class CouchUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that a URL ends with a slash.
|
* Ensures that a URL ends with a slash.
|
||||||
|
*
|
||||||
* @param url the URL to modify
|
* @param url the URL to modify
|
||||||
* @return the modified URL
|
* @return the modified URL
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
package org.springframework.data.document.couchdb;
|
package org.springframework.data.document.couchdb;
|
||||||
|
|
||||||
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Tareq Abedrabbo (tareq.abedrabbo@opencredo.com)
|
* @author Tareq Abedrabbo (tareq.abedrabbo@opencredo.com)
|
||||||
* @since 13/01/2011
|
* @since 13/01/2011
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.springframework.http.HttpEntity;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Matches the content of the body of an HttpEntity.
|
* Matches the content of the body of an HttpEntity.
|
||||||
|
*
|
||||||
* @author Tareq Abedrabbo
|
* @author Tareq Abedrabbo
|
||||||
* @since 31/01/2011
|
* @since 31/01/2011
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package org.springframework.data.document.couchdb.admin;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.data.document.couchdb.core.CouchConstants;
|
import org.springframework.data.document.couchdb.core.CouchConstants;
|
||||||
|
|||||||
@@ -16,28 +16,22 @@
|
|||||||
|
|
||||||
package org.springframework.data.document.couchdb.core;
|
package org.springframework.data.document.couchdb.core;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import static org.junit.Assume.assumeNoException;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import static org.junit.Assume.assumeTrue;
|
||||||
import org.junit.Before;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.http.HttpEntity;
|
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.http.client.ClientHttpResponse;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
|
||||||
import org.springframework.web.client.RestClientException;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.junit.Assume.assumeNoException;
|
import org.apache.commons.logging.Log;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.http.client.ClientHttpResponse;
|
||||||
|
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for CouchDB integration tests. Checks whether CouchDB is available before running each test,
|
* Base class for CouchDB integration tests. Checks whether CouchDB is available before running each test,
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package org.springframework.data.document.couchdb.core;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.data.document.couchdb.DummyDocument;
|
import org.springframework.data.document.couchdb.DummyDocument;
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for CouchTemplate with mocks
|
* Unit tests for CouchTemplate with mocks
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class CouchTemplateTests {
|
public class CouchTemplateTests {
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<couch:jmx/>
|
<couch:jmx/>
|
||||||
|
|
||||||
<context:mbean-export/>
|
<context:mbean-export/>
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
|
||||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
|
||||||
</classpath>
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>spring-data-document-core</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
|
||||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
||||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
|
||||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#Wed Mar 09 13:51:17 EST 2011
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project-modules id="moduleCoreId" project-version="1.5.0">
|
|
||||||
<wb-module deploy-name="spring-datastore-document-core">
|
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
|
||||||
</wb-module>
|
|
||||||
</project-modules>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<faceted-project>
|
|
||||||
<installed facet="jst.utility" version="1.0"/>
|
|
||||||
<installed facet="java" version="1.6"/>
|
|
||||||
</faceted-project>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#Wed Oct 06 14:49:46 EDT 2010
|
|
||||||
activeProfiles=
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
fullBuildGoals=process-test-resources
|
|
||||||
includeModules=false
|
|
||||||
resolveWorkspaceProjects=true
|
|
||||||
resourceFilterGoals=process-resources resources\:testResources
|
|
||||||
skipCompilerPlugin=true
|
|
||||||
version=1
|
|
||||||
@@ -24,8 +24,7 @@ public abstract class AbstractDocumentStoreTemplate<C> {
|
|||||||
public <T> T execute(DocumentStoreConnectionCallback<C, T> action) {
|
public <T> T execute(DocumentStoreConnectionCallback<C, T> action) {
|
||||||
try {
|
try {
|
||||||
return action.doInConnection(getConnection());
|
return action.doInConnection(getConnection());
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
throw new UncategorizedDocumentStoreException("Failure executing using datastore connection", e);
|
throw new UncategorizedDocumentStoreException("Failure executing using datastore connection", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.springframework.data.document.analytics;
|
package org.springframework.data.document.analytics;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ControllerCounter {
|
public class ControllerCounter {
|
||||||
@@ -26,7 +25,6 @@ public class ControllerCounter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setMethods(Map<String, Double> methods) {
|
public void setMethods(Map<String, Double> methods) {
|
||||||
this.methods = methods;
|
this.methods = methods;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,5 +80,4 @@ public class MvcEvent {
|
|||||||
//Map sessionAttributes
|
//Map sessionAttributes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,67 +18,29 @@
|
|||||||
package org.springframework.data.document.web.bind.annotation.support;
|
package org.springframework.data.document.web.bind.annotation.support;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.*;
|
||||||
import java.lang.reflect.GenericArrayType;
|
import java.util.*;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.BridgeMethodResolver;
|
import org.springframework.core.*;
|
||||||
import org.springframework.core.Conventions;
|
|
||||||
import org.springframework.core.GenericTypeResolver;
|
|
||||||
import org.springframework.core.MethodParameter;
|
|
||||||
import org.springframework.core.ParameterNameDiscoverer;
|
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.*;
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.HttpInputMessage;
|
|
||||||
import org.springframework.http.HttpOutputMessage;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.ui.ExtendedModelMap;
|
import org.springframework.ui.ExtendedModelMap;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.*;
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
|
||||||
import org.springframework.util.MultiValueMap;
|
|
||||||
import org.springframework.util.ReflectionUtils;
|
|
||||||
import org.springframework.validation.BindException;
|
import org.springframework.validation.BindException;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
||||||
import org.springframework.web.bind.WebDataBinder;
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
import org.springframework.web.bind.annotation.CookieValue;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.InitBinder;
|
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestHeader;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.ValueConstants;
|
|
||||||
import org.springframework.web.bind.annotation.support.HandlerMethodInvocationException;
|
import org.springframework.web.bind.annotation.support.HandlerMethodInvocationException;
|
||||||
import org.springframework.web.bind.annotation.support.HandlerMethodResolver;
|
import org.springframework.web.bind.annotation.support.HandlerMethodResolver;
|
||||||
import org.springframework.web.bind.support.DefaultSessionAttributeStore;
|
import org.springframework.web.bind.support.*;
|
||||||
import org.springframework.web.bind.support.SessionAttributeStore;
|
|
||||||
import org.springframework.web.bind.support.SessionStatus;
|
|
||||||
import org.springframework.web.bind.support.SimpleSessionStatus;
|
|
||||||
import org.springframework.web.bind.support.WebArgumentResolver;
|
|
||||||
import org.springframework.web.bind.support.WebBindingInitializer;
|
|
||||||
import org.springframework.web.bind.support.WebRequestDataBinder;
|
|
||||||
import org.springframework.web.context.request.NativeWebRequest;
|
import org.springframework.web.context.request.NativeWebRequest;
|
||||||
import org.springframework.web.context.request.WebRequest;
|
import org.springframework.web.context.request.WebRequest;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -87,20 +49,22 @@ import org.springframework.web.multipart.MultipartRequest;
|
|||||||
/**
|
/**
|
||||||
* Support class for invoking an annotated handler method. Operates on the introspection results of a {@link
|
* Support class for invoking an annotated handler method. Operates on the introspection results of a {@link
|
||||||
* HandlerMethodResolver} for a specific handler type.
|
* HandlerMethodResolver} for a specific handler type.
|
||||||
*
|
* <p/>
|
||||||
* <p>Used by {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter} and {@link
|
* <p>Used by {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter} and {@link
|
||||||
* org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter}.
|
* org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter}.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 2.5.2
|
|
||||||
* @see #invokeHandlerMethod
|
* @see #invokeHandlerMethod
|
||||||
|
* @since 2.5.2
|
||||||
*/
|
*/
|
||||||
public class HandlerMethodInvoker {
|
public class HandlerMethodInvoker {
|
||||||
|
|
||||||
private static final String MODEL_KEY_PREFIX_STALE = SessionAttributeStore.class.getName() + ".STALE.";
|
private static final String MODEL_KEY_PREFIX_STALE = SessionAttributeStore.class.getName() + ".STALE.";
|
||||||
|
|
||||||
/** We'll create a lot of these objects, so we don't want a new logger every time. */
|
/**
|
||||||
|
* We'll create a lot of these objects, so we don't want a new logger every time.
|
||||||
|
*/
|
||||||
private static final Log logger = LogFactory.getLog(HandlerMethodInvoker.class);
|
private static final Log logger = LogFactory.getLog(HandlerMethodInvoker.class);
|
||||||
|
|
||||||
private final HandlerMethodResolver methodResolver;
|
private final HandlerMethodResolver methodResolver;
|
||||||
@@ -177,13 +141,11 @@ public class HandlerMethodInvoker {
|
|||||||
}
|
}
|
||||||
ReflectionUtils.makeAccessible(handlerMethodToInvoke);
|
ReflectionUtils.makeAccessible(handlerMethodToInvoke);
|
||||||
return handlerMethodToInvoke.invoke(handler, args);
|
return handlerMethodToInvoke.invoke(handler, args);
|
||||||
}
|
} catch (IllegalStateException ex) {
|
||||||
catch (IllegalStateException ex) {
|
|
||||||
// Internal assertion failed (e.g. invalid signature):
|
// Internal assertion failed (e.g. invalid signature):
|
||||||
// throw exception with full handler method context...
|
// throw exception with full handler method context...
|
||||||
throw new HandlerMethodInvocationException(handlerMethodToInvoke, ex);
|
throw new HandlerMethodInvocationException(handlerMethodToInvoke, ex);
|
||||||
}
|
} catch (InvocationTargetException ex) {
|
||||||
catch (InvocationTargetException ex) {
|
|
||||||
// User-defined @ModelAttribute/@InitBinder/@RequestMapping method threw an exception...
|
// User-defined @ModelAttribute/@InitBinder/@RequestMapping method threw an exception...
|
||||||
ReflectionUtils.rethrowException(ex.getTargetException());
|
ReflectionUtils.rethrowException(ex.getTargetException());
|
||||||
return null;
|
return null;
|
||||||
@@ -212,8 +174,7 @@ public class HandlerMethodInvoker {
|
|||||||
if (isSessionAttr) {
|
if (isSessionAttr) {
|
||||||
if (this.sessionStatus.isComplete()) {
|
if (this.sessionStatus.isComplete()) {
|
||||||
implicitModel.put(MODEL_KEY_PREFIX_STALE + attrName, Boolean.TRUE);
|
implicitModel.put(MODEL_KEY_PREFIX_STALE + attrName, Boolean.TRUE);
|
||||||
}
|
} else if (!implicitModel.containsKey(MODEL_KEY_PREFIX_STALE + attrName)) {
|
||||||
else if (!implicitModel.containsKey(MODEL_KEY_PREFIX_STALE + attrName)) {
|
|
||||||
this.sessionAttributeStore.storeAttribute(webRequest, attrName, attrValue);
|
this.sessionAttributeStore.storeAttribute(webRequest, attrName, attrValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,8 +188,7 @@ public class HandlerMethodInvoker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (InvocationTargetException ex) {
|
||||||
catch (InvocationTargetException ex) {
|
|
||||||
// User-defined @InitBinder method threw an exception...
|
// User-defined @InitBinder method threw an exception...
|
||||||
ReflectionUtils.rethrowException(ex.getTargetException());
|
ReflectionUtils.rethrowException(ex.getTargetException());
|
||||||
}
|
}
|
||||||
@@ -265,39 +225,32 @@ public class HandlerMethodInvoker {
|
|||||||
required = requestParam.required();
|
required = requestParam.required();
|
||||||
defaultValue = parseDefaultValueAttribute(requestParam.defaultValue());
|
defaultValue = parseDefaultValueAttribute(requestParam.defaultValue());
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (RequestHeader.class.isInstance(paramAnn)) {
|
||||||
else if (RequestHeader.class.isInstance(paramAnn)) {
|
|
||||||
RequestHeader requestHeader = (RequestHeader) paramAnn;
|
RequestHeader requestHeader = (RequestHeader) paramAnn;
|
||||||
headerName = requestHeader.value();
|
headerName = requestHeader.value();
|
||||||
required = requestHeader.required();
|
required = requestHeader.required();
|
||||||
defaultValue = parseDefaultValueAttribute(requestHeader.defaultValue());
|
defaultValue = parseDefaultValueAttribute(requestHeader.defaultValue());
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (RequestBody.class.isInstance(paramAnn)) {
|
||||||
else if (RequestBody.class.isInstance(paramAnn)) {
|
|
||||||
requestBodyFound = true;
|
requestBodyFound = true;
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (CookieValue.class.isInstance(paramAnn)) {
|
||||||
else if (CookieValue.class.isInstance(paramAnn)) {
|
|
||||||
CookieValue cookieValue = (CookieValue) paramAnn;
|
CookieValue cookieValue = (CookieValue) paramAnn;
|
||||||
cookieName = cookieValue.value();
|
cookieName = cookieValue.value();
|
||||||
required = cookieValue.required();
|
required = cookieValue.required();
|
||||||
defaultValue = parseDefaultValueAttribute(cookieValue.defaultValue());
|
defaultValue = parseDefaultValueAttribute(cookieValue.defaultValue());
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (PathVariable.class.isInstance(paramAnn)) {
|
||||||
else if (PathVariable.class.isInstance(paramAnn)) {
|
|
||||||
PathVariable pathVar = (PathVariable) paramAnn;
|
PathVariable pathVar = (PathVariable) paramAnn;
|
||||||
pathVarName = pathVar.value();
|
pathVarName = pathVar.value();
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (ModelAttribute.class.isInstance(paramAnn)) {
|
||||||
else if (ModelAttribute.class.isInstance(paramAnn)) {
|
|
||||||
ModelAttribute attr = (ModelAttribute) paramAnn;
|
ModelAttribute attr = (ModelAttribute) paramAnn;
|
||||||
attrName = attr.value();
|
attrName = attr.value();
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (Value.class.isInstance(paramAnn)) {
|
||||||
else if (Value.class.isInstance(paramAnn)) {
|
|
||||||
defaultValue = ((Value) paramAnn).value();
|
defaultValue = ((Value) paramAnn).value();
|
||||||
}
|
} else if ("Valid".equals(paramAnn.annotationType().getSimpleName())) {
|
||||||
else if ("Valid".equals(paramAnn.annotationType().getSimpleName())) {
|
|
||||||
validate = true;
|
validate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -311,29 +264,22 @@ public class HandlerMethodInvoker {
|
|||||||
Object argValue = resolveCommonArgument(methodParam, webRequest);
|
Object argValue = resolveCommonArgument(methodParam, webRequest);
|
||||||
if (argValue != WebArgumentResolver.UNRESOLVED) {
|
if (argValue != WebArgumentResolver.UNRESOLVED) {
|
||||||
args[i] = argValue;
|
args[i] = argValue;
|
||||||
}
|
} else if (defaultValue != null) {
|
||||||
else if (defaultValue != null) {
|
|
||||||
args[i] = resolveDefaultValue(defaultValue);
|
args[i] = resolveDefaultValue(defaultValue);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Class paramType = methodParam.getParameterType();
|
Class paramType = methodParam.getParameterType();
|
||||||
if (Model.class.isAssignableFrom(paramType) || Map.class.isAssignableFrom(paramType)) {
|
if (Model.class.isAssignableFrom(paramType) || Map.class.isAssignableFrom(paramType)) {
|
||||||
args[i] = implicitModel;
|
args[i] = implicitModel;
|
||||||
}
|
} else if (SessionStatus.class.isAssignableFrom(paramType)) {
|
||||||
else if (SessionStatus.class.isAssignableFrom(paramType)) {
|
|
||||||
args[i] = this.sessionStatus;
|
args[i] = this.sessionStatus;
|
||||||
}
|
} else if (HttpEntity.class.isAssignableFrom(paramType)) {
|
||||||
else if (HttpEntity.class.isAssignableFrom(paramType)) {
|
|
||||||
args[i] = resolveHttpEntityRequest(methodParam, webRequest);
|
args[i] = resolveHttpEntityRequest(methodParam, webRequest);
|
||||||
}
|
} else if (Errors.class.isAssignableFrom(paramType)) {
|
||||||
else if (Errors.class.isAssignableFrom(paramType)) {
|
|
||||||
throw new IllegalStateException("Errors/BindingResult argument declared " +
|
throw new IllegalStateException("Errors/BindingResult argument declared " +
|
||||||
"without preceding model attribute. Check your handler method signature!");
|
"without preceding model attribute. Check your handler method signature!");
|
||||||
}
|
} else if (BeanUtils.isSimpleProperty(paramType)) {
|
||||||
else if (BeanUtils.isSimpleProperty(paramType)) {
|
|
||||||
paramName = "";
|
paramName = "";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
attrName = "";
|
attrName = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,20 +287,15 @@ public class HandlerMethodInvoker {
|
|||||||
|
|
||||||
if (paramName != null) {
|
if (paramName != null) {
|
||||||
args[i] = resolveRequestParam(paramName, required, defaultValue, methodParam, webRequest, handler);
|
args[i] = resolveRequestParam(paramName, required, defaultValue, methodParam, webRequest, handler);
|
||||||
}
|
} else if (headerName != null) {
|
||||||
else if (headerName != null) {
|
|
||||||
args[i] = resolveRequestHeader(headerName, required, defaultValue, methodParam, webRequest, handler);
|
args[i] = resolveRequestHeader(headerName, required, defaultValue, methodParam, webRequest, handler);
|
||||||
}
|
} else if (requestBodyFound) {
|
||||||
else if (requestBodyFound) {
|
|
||||||
args[i] = resolveRequestBody(methodParam, webRequest, handler);
|
args[i] = resolveRequestBody(methodParam, webRequest, handler);
|
||||||
}
|
} else if (cookieName != null) {
|
||||||
else if (cookieName != null) {
|
|
||||||
args[i] = resolveCookieValue(cookieName, required, defaultValue, methodParam, webRequest, handler);
|
args[i] = resolveCookieValue(cookieName, required, defaultValue, methodParam, webRequest, handler);
|
||||||
}
|
} else if (pathVarName != null) {
|
||||||
else if (pathVarName != null) {
|
|
||||||
args[i] = resolvePathVariable(pathVarName, methodParam, webRequest, handler);
|
args[i] = resolvePathVariable(pathVarName, methodParam, webRequest, handler);
|
||||||
}
|
} else if (attrName != null) {
|
||||||
else if (attrName != null) {
|
|
||||||
WebDataBinder binder =
|
WebDataBinder binder =
|
||||||
resolveModelAttribute(attrName, methodParam, implicitModel, webRequest, handler);
|
resolveModelAttribute(attrName, methodParam, implicitModel, webRequest, handler);
|
||||||
boolean assignBindingResult = (args.length > i + 1 && Errors.class.isAssignableFrom(paramTypes[i + 1]));
|
boolean assignBindingResult = (args.length > i + 1 && Errors.class.isAssignableFrom(paramTypes[i + 1]));
|
||||||
@@ -427,12 +368,10 @@ public class HandlerMethodInvoker {
|
|||||||
paramRequired = requestParam.required();
|
paramRequired = requestParam.required();
|
||||||
paramDefaultValue = parseDefaultValueAttribute(requestParam.defaultValue());
|
paramDefaultValue = parseDefaultValueAttribute(requestParam.defaultValue());
|
||||||
break;
|
break;
|
||||||
}
|
} else if (ModelAttribute.class.isInstance(paramAnn)) {
|
||||||
else if (ModelAttribute.class.isInstance(paramAnn)) {
|
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"@ModelAttribute is not supported on @InitBinder methods: " + initBinderMethod);
|
"@ModelAttribute is not supported on @InitBinder methods: " + initBinderMethod);
|
||||||
}
|
} else if (PathVariable.class.isInstance(paramAnn)) {
|
||||||
else if (PathVariable.class.isInstance(paramAnn)) {
|
|
||||||
PathVariable pathVar = (PathVariable) paramAnn;
|
PathVariable pathVar = (PathVariable) paramAnn;
|
||||||
pathVarName = pathVar.value();
|
pathVarName = pathVar.value();
|
||||||
}
|
}
|
||||||
@@ -442,16 +381,13 @@ public class HandlerMethodInvoker {
|
|||||||
Object argValue = resolveCommonArgument(methodParam, webRequest);
|
Object argValue = resolveCommonArgument(methodParam, webRequest);
|
||||||
if (argValue != WebArgumentResolver.UNRESOLVED) {
|
if (argValue != WebArgumentResolver.UNRESOLVED) {
|
||||||
initBinderArgs[i] = argValue;
|
initBinderArgs[i] = argValue;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Class paramType = initBinderParams[i];
|
Class paramType = initBinderParams[i];
|
||||||
if (paramType.isInstance(binder)) {
|
if (paramType.isInstance(binder)) {
|
||||||
initBinderArgs[i] = binder;
|
initBinderArgs[i] = binder;
|
||||||
}
|
} else if (BeanUtils.isSimpleProperty(paramType)) {
|
||||||
else if (BeanUtils.isSimpleProperty(paramType)) {
|
|
||||||
paramName = "";
|
paramName = "";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
|
throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
|
||||||
"] for @InitBinder method: " + initBinderMethod);
|
"] for @InitBinder method: " + initBinderMethod);
|
||||||
}
|
}
|
||||||
@@ -461,8 +397,7 @@ public class HandlerMethodInvoker {
|
|||||||
if (paramName != null) {
|
if (paramName != null) {
|
||||||
initBinderArgs[i] =
|
initBinderArgs[i] =
|
||||||
resolveRequestParam(paramName, paramRequired, paramDefaultValue, methodParam, webRequest, null);
|
resolveRequestParam(paramName, paramRequired, paramDefaultValue, methodParam, webRequest, null);
|
||||||
}
|
} else if (pathVarName != null) {
|
||||||
else if (pathVarName != null) {
|
|
||||||
initBinderArgs[i] = resolvePathVariable(pathVarName, methodParam, webRequest, null);
|
initBinderArgs[i] = resolvePathVariable(pathVarName, methodParam, webRequest, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,8 +424,7 @@ public class HandlerMethodInvoker {
|
|||||||
if (!files.isEmpty()) {
|
if (!files.isEmpty()) {
|
||||||
if (files.size() == 1 && !paramType.isArray() && !Collection.class.isAssignableFrom(paramType)) {
|
if (files.size() == 1 && !paramType.isArray() && !Collection.class.isAssignableFrom(paramType)) {
|
||||||
paramValue = files.get(0);
|
paramValue = files.get(0);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
paramValue = files;
|
paramValue = files;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -500,8 +434,7 @@ public class HandlerMethodInvoker {
|
|||||||
if (paramValues != null) {
|
if (paramValues != null) {
|
||||||
if (paramValues.length == 1 && !paramType.isArray() && !Collection.class.isAssignableFrom(paramType)) {
|
if (paramValues.length == 1 && !paramType.isArray() && !Collection.class.isAssignableFrom(paramType)) {
|
||||||
paramValue = paramValues[0];
|
paramValue = paramValues[0];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
paramValue = paramValues;
|
paramValue = paramValues;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -509,8 +442,7 @@ public class HandlerMethodInvoker {
|
|||||||
if (paramValue == null) {
|
if (paramValue == null) {
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
paramValue = resolveDefaultValue(defaultValue);
|
paramValue = resolveDefaultValue(defaultValue);
|
||||||
}
|
} else if (required) {
|
||||||
else if (required) {
|
|
||||||
raiseMissingParameterException(paramName, paramType);
|
raiseMissingParameterException(paramName, paramType);
|
||||||
}
|
}
|
||||||
paramValue = checkValue(paramName, paramValue, paramType);
|
paramValue = checkValue(paramName, paramValue, paramType);
|
||||||
@@ -530,8 +462,7 @@ public class HandlerMethodInvoker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Map<String, String> result = new LinkedHashMap<String, String>(parameterMap.size());
|
Map<String, String> result = new LinkedHashMap<String, String>(parameterMap.size());
|
||||||
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
|
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
|
||||||
if (entry.getValue().length > 0) {
|
if (entry.getValue().length > 0) {
|
||||||
@@ -562,8 +493,7 @@ public class HandlerMethodInvoker {
|
|||||||
if (headerValue == null) {
|
if (headerValue == null) {
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
headerValue = resolveDefaultValue(defaultValue);
|
headerValue = resolveDefaultValue(defaultValue);
|
||||||
}
|
} else if (required) {
|
||||||
else if (required) {
|
|
||||||
raiseMissingHeaderException(headerName, paramType);
|
raiseMissingHeaderException(headerName, paramType);
|
||||||
}
|
}
|
||||||
headerValue = checkValue(headerName, headerValue, paramType);
|
headerValue = checkValue(headerName, headerValue, paramType);
|
||||||
@@ -578,8 +508,7 @@ public class HandlerMethodInvoker {
|
|||||||
MultiValueMap<String, String> result;
|
MultiValueMap<String, String> result;
|
||||||
if (HttpHeaders.class.isAssignableFrom(mapType)) {
|
if (HttpHeaders.class.isAssignableFrom(mapType)) {
|
||||||
result = new HttpHeaders();
|
result = new HttpHeaders();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
result = new LinkedMultiValueMap<String, String>();
|
result = new LinkedMultiValueMap<String, String>();
|
||||||
}
|
}
|
||||||
for (Iterator<String> iterator = webRequest.getHeaderNames(); iterator.hasNext();) {
|
for (Iterator<String> iterator = webRequest.getHeaderNames(); iterator.hasNext();) {
|
||||||
@@ -589,8 +518,7 @@ public class HandlerMethodInvoker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Map<String, String> result = new LinkedHashMap<String, String>();
|
Map<String, String> result = new LinkedHashMap<String, String>();
|
||||||
for (Iterator<String> iterator = webRequest.getHeaderNames(); iterator.hasNext();) {
|
for (Iterator<String> iterator = webRequest.getHeaderNames(); iterator.hasNext();) {
|
||||||
String headerName = iterator.next();
|
String headerName = iterator.next();
|
||||||
@@ -657,8 +585,7 @@ public class HandlerMethodInvoker {
|
|||||||
Type typeArgument = type.getActualTypeArguments()[0];
|
Type typeArgument = type.getActualTypeArguments()[0];
|
||||||
if (typeArgument instanceof Class) {
|
if (typeArgument instanceof Class) {
|
||||||
return (Class<?>) typeArgument;
|
return (Class<?>) typeArgument;
|
||||||
}
|
} else if (typeArgument instanceof GenericArrayType) {
|
||||||
else if (typeArgument instanceof GenericArrayType) {
|
|
||||||
Type componentType = ((GenericArrayType) typeArgument).getGenericComponentType();
|
Type componentType = ((GenericArrayType) typeArgument).getGenericComponentType();
|
||||||
if (componentType instanceof Class) {
|
if (componentType instanceof Class) {
|
||||||
// Surely, there should be a nicer way to do this
|
// Surely, there should be a nicer way to do this
|
||||||
@@ -684,8 +611,7 @@ public class HandlerMethodInvoker {
|
|||||||
if (cookieValue == null) {
|
if (cookieValue == null) {
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
cookieValue = resolveDefaultValue(defaultValue);
|
cookieValue = resolveDefaultValue(defaultValue);
|
||||||
}
|
} else if (required) {
|
||||||
else if (required) {
|
|
||||||
raiseMissingCookieException(cookieName, paramType);
|
raiseMissingCookieException(cookieName, paramType);
|
||||||
}
|
}
|
||||||
cookieValue = checkValue(cookieName, cookieValue, paramType);
|
cookieValue = checkValue(cookieName, cookieValue, paramType);
|
||||||
@@ -742,8 +668,7 @@ public class HandlerMethodInvoker {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
if (boolean.class.equals(paramType)) {
|
if (boolean.class.equals(paramType)) {
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
}
|
} else if (paramType.isPrimitive()) {
|
||||||
else if (paramType.isPrimitive()) {
|
|
||||||
throw new IllegalStateException("Optional " + paramType + " parameter '" + name +
|
throw new IllegalStateException("Optional " + paramType + " parameter '" + name +
|
||||||
"' is not present but cannot be translated into a null value due to being declared as a " +
|
"' is not present but cannot be translated into a null value due to being declared as a " +
|
||||||
"primitive type. Consider declaring it as object wrapper for the corresponding primitive type.");
|
"primitive type. Consider declaring it as object wrapper for the corresponding primitive type.");
|
||||||
@@ -764,14 +689,12 @@ public class HandlerMethodInvoker {
|
|||||||
Object bindObject;
|
Object bindObject;
|
||||||
if (implicitModel.containsKey(name)) {
|
if (implicitModel.containsKey(name)) {
|
||||||
bindObject = implicitModel.get(name);
|
bindObject = implicitModel.get(name);
|
||||||
}
|
} else if (this.methodResolver.isSessionAttribute(name, paramType)) {
|
||||||
else if (this.methodResolver.isSessionAttribute(name, paramType)) {
|
|
||||||
bindObject = this.sessionAttributeStore.retrieveAttribute(webRequest, name);
|
bindObject = this.sessionAttributeStore.retrieveAttribute(webRequest, name);
|
||||||
if (bindObject == null) {
|
if (bindObject == null) {
|
||||||
raiseSessionRequiredException("Session attribute '" + name + "' required - not found in session");
|
raiseSessionRequiredException("Session attribute '" + name + "' required - not found in session");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
bindObject = BeanUtils.instantiateClass(paramType);
|
bindObject = BeanUtils.instantiateClass(paramType);
|
||||||
}
|
}
|
||||||
WebDataBinder binder = createBinder(webRequest, bindObject, name);
|
WebDataBinder binder = createBinder(webRequest, bindObject, name);
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ public class ActionExecutedContext extends ActionExecutingContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ModelAndView getModelAndView() {
|
public ModelAndView getModelAndView() {
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
}
|
}
|
||||||
@@ -56,6 +55,4 @@ public class ActionExecutedContext extends ActionExecutingContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ package org.springframework.data.document.web.servlet;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@@ -87,6 +86,4 @@ public class ActionExecutingContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,26 +16,11 @@
|
|||||||
|
|
||||||
package org.springframework.data.document.web.servlet.mvc.annotation;
|
package org.springframework.data.document.web.servlet.mvc.annotation;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
@@ -47,32 +32,19 @@ import javax.servlet.http.HttpSession;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.BeanFactoryAware;
|
import org.springframework.beans.factory.BeanFactoryAware;
|
||||||
import org.springframework.beans.factory.config.BeanExpressionContext;
|
import org.springframework.beans.factory.config.BeanExpressionContext;
|
||||||
import org.springframework.beans.factory.config.BeanExpressionResolver;
|
import org.springframework.beans.factory.config.BeanExpressionResolver;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import org.springframework.core.BridgeMethodResolver;
|
import org.springframework.core.*;
|
||||||
import org.springframework.core.Conventions;
|
|
||||||
import org.springframework.core.GenericTypeResolver;
|
|
||||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
|
||||||
import org.springframework.core.Ordered;
|
|
||||||
import org.springframework.core.ParameterNameDiscoverer;
|
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.data.document.web.servlet.ActionExecutedContext;
|
import org.springframework.data.document.web.servlet.ActionExecutedContext;
|
||||||
import org.springframework.data.document.web.servlet.ActionExecutingContext;
|
import org.springframework.data.document.web.servlet.ActionExecutingContext;
|
||||||
import org.springframework.data.document.web.servlet.ActionInterceptor;
|
import org.springframework.data.document.web.servlet.ActionInterceptor;
|
||||||
import org.springframework.data.document.web.servlet.mvc.annotation.support.InterceptingHandlerMethodInvoker;
|
import org.springframework.data.document.web.servlet.mvc.annotation.support.InterceptingHandlerMethodInvoker;
|
||||||
import org.springframework.format.support.FormattingConversionService;
|
import org.springframework.http.*;
|
||||||
import org.springframework.http.HttpEntity;
|
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.HttpInputMessage;
|
|
||||||
import org.springframework.http.HttpOutputMessage;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
@@ -84,13 +56,7 @@ import org.springframework.http.server.ServletServerHttpRequest;
|
|||||||
import org.springframework.http.server.ServletServerHttpResponse;
|
import org.springframework.http.server.ServletServerHttpResponse;
|
||||||
import org.springframework.ui.ExtendedModelMap;
|
import org.springframework.ui.ExtendedModelMap;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.util.AntPathMatcher;
|
import org.springframework.util.*;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
import org.springframework.util.PathMatcher;
|
|
||||||
import org.springframework.util.ReflectionUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.validation.support.BindingAwareModelMap;
|
import org.springframework.validation.support.BindingAwareModelMap;
|
||||||
import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
@@ -98,14 +64,7 @@ import org.springframework.web.HttpSessionRequiredException;
|
|||||||
import org.springframework.web.bind.MissingServletRequestParameterException;
|
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||||
import org.springframework.web.bind.ServletRequestDataBinder;
|
import org.springframework.web.bind.ServletRequestDataBinder;
|
||||||
import org.springframework.web.bind.WebDataBinder;
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
import org.springframework.web.bind.annotation.InitBinder;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
||||||
import org.springframework.web.bind.annotation.SessionAttributes;
|
|
||||||
import org.springframework.web.bind.annotation.support.HandlerMethodInvocationException;
|
import org.springframework.web.bind.annotation.support.HandlerMethodInvocationException;
|
||||||
import org.springframework.web.bind.annotation.support.HandlerMethodInvoker;
|
import org.springframework.web.bind.annotation.support.HandlerMethodInvoker;
|
||||||
import org.springframework.web.bind.annotation.support.HandlerMethodResolver;
|
import org.springframework.web.bind.annotation.support.HandlerMethodResolver;
|
||||||
@@ -134,23 +93,23 @@ import org.springframework.web.util.WebUtils;
|
|||||||
* Implementation of the {@link org.springframework.web.servlet.HandlerAdapter} interface
|
* Implementation of the {@link org.springframework.web.servlet.HandlerAdapter} interface
|
||||||
* that maps handler methods based on HTTP paths, HTTP methods and request parameters
|
* that maps handler methods based on HTTP paths, HTTP methods and request parameters
|
||||||
* expressed through the {@link RequestMapping} annotation.
|
* expressed through the {@link RequestMapping} annotation.
|
||||||
*
|
* <p/>
|
||||||
* <p>Supports request parameter binding through the {@link RequestParam} annotation.
|
* <p>Supports request parameter binding through the {@link RequestParam} annotation.
|
||||||
* Also supports the {@link ModelAttribute} annotation for exposing model attribute
|
* Also supports the {@link ModelAttribute} annotation for exposing model attribute
|
||||||
* values to the view, as well as {@link InitBinder} for binder initialization methods
|
* values to the view, as well as {@link InitBinder} for binder initialization methods
|
||||||
* and {@link SessionAttributes} for automatic session management of specific attributes.
|
* and {@link SessionAttributes} for automatic session management of specific attributes.
|
||||||
*
|
* <p/>
|
||||||
* <p>This adapter can be customized through various bean properties.
|
* <p>This adapter can be customized through various bean properties.
|
||||||
* A common use case is to apply shared binder initialization logic through
|
* A common use case is to apply shared binder initialization logic through
|
||||||
* a custom {@link #setWebBindingInitializer WebBindingInitializer}.
|
* a custom {@link #setWebBindingInitializer WebBindingInitializer}.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 2.5
|
|
||||||
* @see #setPathMatcher
|
* @see #setPathMatcher
|
||||||
* @see #setMethodNameResolver
|
* @see #setMethodNameResolver
|
||||||
* @see #setWebBindingInitializer
|
* @see #setWebBindingInitializer
|
||||||
* @see #setSessionAttributeStore
|
* @see #setSessionAttributeStore
|
||||||
|
* @since 2.5
|
||||||
*/
|
*/
|
||||||
public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
implements HandlerAdapter, Ordered, BeanFactoryAware {
|
implements HandlerAdapter, Ordered, BeanFactoryAware {
|
||||||
@@ -160,12 +119,14 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Log category to use when no mapped handler is found for a request.
|
* Log category to use when no mapped handler is found for a request.
|
||||||
|
*
|
||||||
* @see #pageNotFoundLogger
|
* @see #pageNotFoundLogger
|
||||||
*/
|
*/
|
||||||
public static final String PAGE_NOT_FOUND_LOG_CATEGORY = "org.springframework.web.servlet.PageNotFound";
|
public static final String PAGE_NOT_FOUND_LOG_CATEGORY = "org.springframework.web.servlet.PageNotFound";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Additional logger to use when no mapped handler is found for a request.
|
* Additional logger to use when no mapped handler is found for a request.
|
||||||
|
*
|
||||||
* @see #PAGE_NOT_FOUND_LOG_CATEGORY
|
* @see #PAGE_NOT_FOUND_LOG_CATEGORY
|
||||||
*/
|
*/
|
||||||
protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY);
|
protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY);
|
||||||
@@ -221,6 +182,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
* context. Else, the path within the current servlet mapping is used if applicable
|
* context. Else, the path within the current servlet mapping is used if applicable
|
||||||
* (that is, in the case of a ".../*" servlet mapping in web.xml).
|
* (that is, in the case of a ".../*" servlet mapping in web.xml).
|
||||||
* <p>Default is "false".
|
* <p>Default is "false".
|
||||||
|
*
|
||||||
* @see org.springframework.web.util.UrlPathHelper#setAlwaysUseFullPath
|
* @see org.springframework.web.util.UrlPathHelper#setAlwaysUseFullPath
|
||||||
*/
|
*/
|
||||||
public void setAlwaysUseFullPath(boolean alwaysUseFullPath) {
|
public void setAlwaysUseFullPath(boolean alwaysUseFullPath) {
|
||||||
@@ -232,6 +194,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
* <i>undecoded</i> by the Servlet API, in contrast to the servlet path.
|
* <i>undecoded</i> by the Servlet API, in contrast to the servlet path.
|
||||||
* <p>Uses either the request encoding or the default encoding according
|
* <p>Uses either the request encoding or the default encoding according
|
||||||
* to the Servlet spec (ISO-8859-1).
|
* to the Servlet spec (ISO-8859-1).
|
||||||
|
*
|
||||||
* @see org.springframework.web.util.UrlPathHelper#setUrlDecode
|
* @see org.springframework.web.util.UrlPathHelper#setUrlDecode
|
||||||
*/
|
*/
|
||||||
public void setUrlDecode(boolean urlDecode) {
|
public void setUrlDecode(boolean urlDecode) {
|
||||||
@@ -291,6 +254,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
* <p>In contrast to the "cacheSeconds" property which will apply to all general handlers
|
* <p>In contrast to the "cacheSeconds" property which will apply to all general handlers
|
||||||
* (but not to <code>@SessionAttributes</code> annotated handlers), this setting will
|
* (but not to <code>@SessionAttributes</code> annotated handlers), this setting will
|
||||||
* apply to <code>@SessionAttributes</code> annotated handlers only.
|
* apply to <code>@SessionAttributes</code> annotated handlers only.
|
||||||
|
*
|
||||||
* @see #setCacheSeconds
|
* @see #setCacheSeconds
|
||||||
* @see org.springframework.web.bind.annotation.SessionAttributes
|
* @see org.springframework.web.bind.annotation.SessionAttributes
|
||||||
*/
|
*/
|
||||||
@@ -313,6 +277,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
* as well, since it will always be the same object reference for the
|
* as well, since it will always be the same object reference for the
|
||||||
* same active logical session. However, this is not guaranteed across
|
* same active logical session. However, this is not guaranteed across
|
||||||
* different servlet containers; the only 100% safe way is a session mutex.
|
* different servlet containers; the only 100% safe way is a session mutex.
|
||||||
|
*
|
||||||
* @see org.springframework.web.util.HttpSessionMutexListener
|
* @see org.springframework.web.util.HttpSessionMutexListener
|
||||||
* @see org.springframework.web.util.WebUtils#getSessionMutex(javax.servlet.http.HttpSession)
|
* @see org.springframework.web.util.WebUtils#getSessionMutex(javax.servlet.http.HttpSession)
|
||||||
*/
|
*/
|
||||||
@@ -387,6 +352,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
/**
|
/**
|
||||||
* Specify the order value for this HandlerAdapter bean.
|
* Specify the order value for this HandlerAdapter bean.
|
||||||
* <p>Default value is <code>Integer.MAX_VALUE</code>, meaning that it's non-ordered.
|
* <p>Default value is <code>Integer.MAX_VALUE</code>, meaning that it's non-ordered.
|
||||||
|
*
|
||||||
* @see org.springframework.core.Ordered#getOrder()
|
* @see org.springframework.core.Ordered#getOrder()
|
||||||
*/
|
*/
|
||||||
public void setOrder(int order) {
|
public void setOrder(int order) {
|
||||||
@@ -416,8 +382,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
// Always prevent caching in case of session attribute management.
|
// Always prevent caching in case of session attribute management.
|
||||||
checkAndPrepare(request, response, this.cacheSecondsForSessionAttributeHandlers, true);
|
checkAndPrepare(request, response, this.cacheSecondsForSessionAttributeHandlers, true);
|
||||||
// Prepare cached set of session attributes names.
|
// Prepare cached set of session attributes names.
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Uses configured default cacheSeconds setting.
|
// Uses configured default cacheSeconds setting.
|
||||||
checkAndPrepare(request, response, true);
|
checkAndPrepare(request, response, true);
|
||||||
}
|
}
|
||||||
@@ -476,6 +441,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
* Template method for creating a new ServletRequestDataBinder instance.
|
* Template method for creating a new ServletRequestDataBinder instance.
|
||||||
* <p>The default implementation creates a standard ServletRequestDataBinder.
|
* <p>The default implementation creates a standard ServletRequestDataBinder.
|
||||||
* This can be overridden for custom ServletRequestDataBinder subclasses.
|
* This can be overridden for custom ServletRequestDataBinder subclasses.
|
||||||
|
*
|
||||||
* @param request current HTTP request
|
* @param request current HTTP request
|
||||||
* @param target the target object to bind onto (or <code>null</code>
|
* @param target the target object to bind onto (or <code>null</code>
|
||||||
* if the binder is just used to convert a plain parameter value)
|
* if the binder is just used to convert a plain parameter value)
|
||||||
@@ -494,6 +460,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
* Template method for creating a new HttpInputMessage instance.
|
* Template method for creating a new HttpInputMessage instance.
|
||||||
* <p>The default implementation creates a standard {@link ServletServerHttpRequest}.
|
* <p>The default implementation creates a standard {@link ServletServerHttpRequest}.
|
||||||
* This can be overridden for custom {@code HttpInputMessage} implementations
|
* This can be overridden for custom {@code HttpInputMessage} implementations
|
||||||
|
*
|
||||||
* @param servletRequest current HTTP request
|
* @param servletRequest current HTTP request
|
||||||
* @return the HttpInputMessage instance to use
|
* @return the HttpInputMessage instance to use
|
||||||
* @throws Exception in case of errors
|
* @throws Exception in case of errors
|
||||||
@@ -506,6 +473,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
* Template method for creating a new HttpOuputMessage instance.
|
* Template method for creating a new HttpOuputMessage instance.
|
||||||
* <p>The default implementation creates a standard {@link ServletServerHttpResponse}.
|
* <p>The default implementation creates a standard {@link ServletServerHttpResponse}.
|
||||||
* This can be overridden for custom {@code HttpOutputMessage} implementations
|
* This can be overridden for custom {@code HttpOutputMessage} implementations
|
||||||
|
*
|
||||||
* @param servletResponse current HTTP response
|
* @param servletResponse current HTTP response
|
||||||
* @return the HttpInputMessage instance to use
|
* @return the HttpInputMessage instance to use
|
||||||
* @throws Exception in case of errors
|
* @throws Exception in case of errors
|
||||||
@@ -570,8 +538,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
if (mappingInfo.matches(request)) {
|
if (mappingInfo.matches(request)) {
|
||||||
match = true;
|
match = true;
|
||||||
matchingPatterns.add(combinedPattern);
|
matchingPatterns.add(combinedPattern);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (!mappingInfo.matchesRequestMethod(request)) {
|
if (!mappingInfo.matchesRequestMethod(request)) {
|
||||||
allowedMethods.addAll(mappingInfo.methodNames());
|
allowedMethods.addAll(mappingInfo.methodNames());
|
||||||
}
|
}
|
||||||
@@ -581,15 +548,13 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
}
|
}
|
||||||
Collections.sort(matchingPatterns, pathComparator);
|
Collections.sort(matchingPatterns, pathComparator);
|
||||||
mappingInfo.matchedPatterns = matchingPatterns;
|
mappingInfo.matchedPatterns = matchingPatterns;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// No paths specified: parameter match sufficient.
|
// No paths specified: parameter match sufficient.
|
||||||
match = mappingInfo.matches(request);
|
match = mappingInfo.matches(request);
|
||||||
if (match && mappingInfo.methods.length == 0 && mappingInfo.params.length == 0 &&
|
if (match && mappingInfo.methods.length == 0 && mappingInfo.params.length == 0 &&
|
||||||
resolvedMethodName != null && !resolvedMethodName.equals(handlerMethod.getName())) {
|
resolvedMethodName != null && !resolvedMethodName.equals(handlerMethod.getName())) {
|
||||||
match = false;
|
match = false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (!mappingInfo.matchesRequestMethod(request)) {
|
if (!mappingInfo.matchesRequestMethod(request)) {
|
||||||
allowedMethods.addAll(mappingInfo.methodNames());
|
allowedMethods.addAll(mappingInfo.methodNames());
|
||||||
}
|
}
|
||||||
@@ -610,8 +575,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
if (oldMappedMethod != null) {
|
if (oldMappedMethod != null) {
|
||||||
targetHandlerMethods.put(mappingInfo, oldMappedMethod);
|
targetHandlerMethods.put(mappingInfo, oldMappedMethod);
|
||||||
oldMappedMethod = null;
|
oldMappedMethod = null;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
targetHandlerMethods.remove(mappingInfo);
|
targetHandlerMethods.remove(mappingInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -638,8 +602,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
extractHandlerMethodUriTemplates(bestMatchedPath, lookupPath, request);
|
extractHandlerMethodUriTemplates(bestMatchedPath, lookupPath, request);
|
||||||
}
|
}
|
||||||
return targetHandlerMethods.get(bestMappingMatch);
|
return targetHandlerMethods.get(bestMappingMatch);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (!allowedMethods.isEmpty()) {
|
if (!allowedMethods.isEmpty()) {
|
||||||
throw new HttpRequestMethodNotSupportedException(request.getMethod(),
|
throw new HttpRequestMethodNotSupportedException(request.getMethod(),
|
||||||
StringUtils.toStringArray(allowedMethods));
|
StringUtils.toStringArray(allowedMethods));
|
||||||
@@ -800,14 +763,12 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
triggerAfterCompletion(executingContext, interceptorIndex, mav, null);
|
triggerAfterCompletion(executingContext, interceptorIndex, mav, null);
|
||||||
|
|
||||||
return mav;
|
return mav;
|
||||||
}
|
} catch (IllegalStateException ex) {
|
||||||
catch (IllegalStateException ex) {
|
|
||||||
// Internal assertion failed (e.g. invalid signature):
|
// Internal assertion failed (e.g. invalid signature):
|
||||||
// throw exception with full handler method context...
|
// throw exception with full handler method context...
|
||||||
triggerAfterCompletion(executingContext, interceptorIndex, mav, ex);
|
triggerAfterCompletion(executingContext, interceptorIndex, mav, ex);
|
||||||
throw new HandlerMethodInvocationException(handlerMethodToInvoke, ex);
|
throw new HandlerMethodInvocationException(handlerMethodToInvoke, ex);
|
||||||
}
|
} catch (InvocationTargetException ex) {
|
||||||
catch (InvocationTargetException ex) {
|
|
||||||
// User-defined @ModelAttribute/@InitBinder/@RequestMapping method threw an exception...
|
// User-defined @ModelAttribute/@InitBinder/@RequestMapping method threw an exception...
|
||||||
triggerAfterCompletion(executingContext, interceptorIndex, mav, ex);
|
triggerAfterCompletion(executingContext, interceptorIndex, mav, ex);
|
||||||
ReflectionUtils.rethrowException(ex.getTargetException());
|
ReflectionUtils.rethrowException(ex.getTargetException());
|
||||||
@@ -830,8 +791,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
ActionExecutedContext actionExecutedContext = new ActionExecutedContext(executingContext, modelAndView, ex);
|
ActionExecutedContext actionExecutedContext = new ActionExecutedContext(executingContext, modelAndView, ex);
|
||||||
try {
|
try {
|
||||||
interceptor.afterCompletion(actionExecutedContext);
|
interceptor.afterCompletion(actionExecutedContext);
|
||||||
}
|
} catch (Throwable ex2) {
|
||||||
catch (Throwable ex2) {
|
|
||||||
logger.error("ActionInterceptor threw exception", ex2);
|
logger.error("ActionInterceptor threw exception", ex2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -897,11 +857,9 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
Cookie cookieValue = WebUtils.getCookie(servletRequest, cookieName);
|
Cookie cookieValue = WebUtils.getCookie(servletRequest, cookieName);
|
||||||
if (Cookie.class.isAssignableFrom(paramType)) {
|
if (Cookie.class.isAssignableFrom(paramType)) {
|
||||||
return cookieValue;
|
return cookieValue;
|
||||||
}
|
} else if (cookieValue != null) {
|
||||||
else if (cookieValue != null) {
|
|
||||||
return urlPathHelper.decodeRequestString(servletRequest, cookieValue.getValue());
|
return urlPathHelper.decodeRequestString(servletRequest, cookieValue.getValue());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -934,8 +892,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
"Current request is not of type [" + parameterType.getName() + "]: " + request);
|
"Current request is not of type [" + parameterType.getName() + "]: " + request);
|
||||||
}
|
}
|
||||||
return nativeRequest;
|
return nativeRequest;
|
||||||
}
|
} else if (ServletResponse.class.isAssignableFrom(parameterType)) {
|
||||||
else if (ServletResponse.class.isAssignableFrom(parameterType)) {
|
|
||||||
this.responseArgumentUsed = true;
|
this.responseArgumentUsed = true;
|
||||||
Object nativeResponse = webRequest.getNativeResponse(parameterType);
|
Object nativeResponse = webRequest.getNativeResponse(parameterType);
|
||||||
if (nativeResponse == null) {
|
if (nativeResponse == null) {
|
||||||
@@ -943,27 +900,20 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
"Current response is not of type [" + parameterType.getName() + "]: " + response);
|
"Current response is not of type [" + parameterType.getName() + "]: " + response);
|
||||||
}
|
}
|
||||||
return nativeResponse;
|
return nativeResponse;
|
||||||
}
|
} else if (HttpSession.class.isAssignableFrom(parameterType)) {
|
||||||
else if (HttpSession.class.isAssignableFrom(parameterType)) {
|
|
||||||
return request.getSession();
|
return request.getSession();
|
||||||
}
|
} else if (Principal.class.isAssignableFrom(parameterType)) {
|
||||||
else if (Principal.class.isAssignableFrom(parameterType)) {
|
|
||||||
return request.getUserPrincipal();
|
return request.getUserPrincipal();
|
||||||
}
|
} else if (Locale.class.equals(parameterType)) {
|
||||||
else if (Locale.class.equals(parameterType)) {
|
|
||||||
return RequestContextUtils.getLocale(request);
|
return RequestContextUtils.getLocale(request);
|
||||||
}
|
} else if (InputStream.class.isAssignableFrom(parameterType)) {
|
||||||
else if (InputStream.class.isAssignableFrom(parameterType)) {
|
|
||||||
return request.getInputStream();
|
return request.getInputStream();
|
||||||
}
|
} else if (Reader.class.isAssignableFrom(parameterType)) {
|
||||||
else if (Reader.class.isAssignableFrom(parameterType)) {
|
|
||||||
return request.getReader();
|
return request.getReader();
|
||||||
}
|
} else if (OutputStream.class.isAssignableFrom(parameterType)) {
|
||||||
else if (OutputStream.class.isAssignableFrom(parameterType)) {
|
|
||||||
this.responseArgumentUsed = true;
|
this.responseArgumentUsed = true;
|
||||||
return response.getOutputStream();
|
return response.getOutputStream();
|
||||||
}
|
} else if (Writer.class.isAssignableFrom(parameterType)) {
|
||||||
else if (Writer.class.isAssignableFrom(parameterType)) {
|
|
||||||
this.responseArgumentUsed = true;
|
this.responseArgumentUsed = true;
|
||||||
return response.getWriter();
|
return response.getWriter();
|
||||||
}
|
}
|
||||||
@@ -980,8 +930,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
String reason = responseStatusAnn.reason();
|
String reason = responseStatusAnn.reason();
|
||||||
if (!StringUtils.hasText(reason)) {
|
if (!StringUtils.hasText(reason)) {
|
||||||
webRequest.getResponse().setStatus(responseStatus.value());
|
webRequest.getResponse().setStatus(responseStatus.value());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
webRequest.getResponse().sendError(responseStatus.value(), reason);
|
webRequest.getResponse().sendError(responseStatus.value(), reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1005,48 +954,37 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
if (returnValue instanceof HttpEntity) {
|
if (returnValue instanceof HttpEntity) {
|
||||||
handleHttpEntityResponse((HttpEntity<?>) returnValue, webRequest);
|
handleHttpEntityResponse((HttpEntity<?>) returnValue, webRequest);
|
||||||
return null;
|
return null;
|
||||||
}
|
} else if (AnnotationUtils.findAnnotation(handlerMethod, ResponseBody.class) != null) {
|
||||||
else if (AnnotationUtils.findAnnotation(handlerMethod, ResponseBody.class) != null) {
|
|
||||||
handleResponseBody(returnValue, webRequest);
|
handleResponseBody(returnValue, webRequest);
|
||||||
return null;
|
return null;
|
||||||
}
|
} else if (returnValue instanceof ModelAndView) {
|
||||||
else if (returnValue instanceof ModelAndView) {
|
|
||||||
ModelAndView mav = (ModelAndView) returnValue;
|
ModelAndView mav = (ModelAndView) returnValue;
|
||||||
mav.getModelMap().mergeAttributes(implicitModel);
|
mav.getModelMap().mergeAttributes(implicitModel);
|
||||||
return mav;
|
return mav;
|
||||||
}
|
} else if (returnValue instanceof Model) {
|
||||||
else if (returnValue instanceof Model) {
|
|
||||||
return new ModelAndView().addAllObjects(implicitModel).addAllObjects(((Model) returnValue).asMap());
|
return new ModelAndView().addAllObjects(implicitModel).addAllObjects(((Model) returnValue).asMap());
|
||||||
}
|
} else if (returnValue instanceof View) {
|
||||||
else if (returnValue instanceof View) {
|
|
||||||
return new ModelAndView((View) returnValue).addAllObjects(implicitModel);
|
return new ModelAndView((View) returnValue).addAllObjects(implicitModel);
|
||||||
}
|
} else if (AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class) != null) {
|
||||||
else if (AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class) != null) {
|
|
||||||
addReturnValueAsModelAttribute(handlerMethod, handlerType, returnValue, implicitModel);
|
addReturnValueAsModelAttribute(handlerMethod, handlerType, returnValue, implicitModel);
|
||||||
return new ModelAndView().addAllObjects(implicitModel);
|
return new ModelAndView().addAllObjects(implicitModel);
|
||||||
}
|
} else if (returnValue instanceof Map) {
|
||||||
else if (returnValue instanceof Map) {
|
|
||||||
return new ModelAndView().addAllObjects(implicitModel).addAllObjects((Map) returnValue);
|
return new ModelAndView().addAllObjects(implicitModel).addAllObjects((Map) returnValue);
|
||||||
}
|
} else if (returnValue instanceof String) {
|
||||||
else if (returnValue instanceof String) {
|
|
||||||
return new ModelAndView((String) returnValue).addAllObjects(implicitModel);
|
return new ModelAndView((String) returnValue).addAllObjects(implicitModel);
|
||||||
}
|
} else if (returnValue == null) {
|
||||||
else if (returnValue == null) {
|
|
||||||
// Either returned null or was 'void' return.
|
// Either returned null or was 'void' return.
|
||||||
if (this.responseArgumentUsed || webRequest.isNotModified()) {
|
if (this.responseArgumentUsed || webRequest.isNotModified()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Assuming view name translation...
|
// Assuming view name translation...
|
||||||
return new ModelAndView().addAllObjects(implicitModel);
|
return new ModelAndView().addAllObjects(implicitModel);
|
||||||
}
|
}
|
||||||
}
|
} else if (!BeanUtils.isSimpleProperty(returnValue.getClass())) {
|
||||||
else if (!BeanUtils.isSimpleProperty(returnValue.getClass())) {
|
|
||||||
// Assume a single model attribute...
|
// Assume a single model attribute...
|
||||||
addReturnValueAsModelAttribute(handlerMethod, handlerType, returnValue, implicitModel);
|
addReturnValueAsModelAttribute(handlerMethod, handlerType, returnValue, implicitModel);
|
||||||
return new ModelAndView().addAllObjects(implicitModel);
|
return new ModelAndView().addAllObjects(implicitModel);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new IllegalArgumentException("Invalid handler method return value: " + returnValue);
|
throw new IllegalArgumentException("Invalid handler method return value: " + returnValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1078,8 +1016,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
Object body = responseEntity.getBody();
|
Object body = responseEntity.getBody();
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
writeWithMessageConverters(body, inputMessage, outputMessage);
|
writeWithMessageConverters(body, inputMessage, outputMessage);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// flush headers
|
// flush headers
|
||||||
outputMessage.getBody();
|
outputMessage.getBody();
|
||||||
}
|
}
|
||||||
@@ -1253,14 +1190,11 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||||||
int info2MethodCount = info2.methods.length;
|
int info2MethodCount = info2.methods.length;
|
||||||
if (info1MethodCount == 0 && info2MethodCount > 0) {
|
if (info1MethodCount == 0 && info2MethodCount > 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else if (info2MethodCount == 0 && info1MethodCount > 0) {
|
||||||
else if (info2MethodCount == 0 && info1MethodCount > 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else if (info1MethodCount == 1 & info2MethodCount > 1) {
|
||||||
else if (info1MethodCount == 1 & info2MethodCount > 1) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else if (info2MethodCount == 1 & info1MethodCount > 1) {
|
||||||
else if (info2MethodCount == 1 & info1MethodCount > 1) {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ abstract class ServletAnnotationMappingUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the given request matches the specified request methods.
|
* Check whether the given request matches the specified request methods.
|
||||||
|
*
|
||||||
* @param methods the HTTP request methods to check against
|
* @param methods the HTTP request methods to check against
|
||||||
* @param request the current HTTP request to check
|
* @param request the current HTTP request to check
|
||||||
*/
|
*/
|
||||||
@@ -53,6 +54,7 @@ abstract class ServletAnnotationMappingUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the given request matches the specified parameter conditions.
|
* Check whether the given request matches the specified parameter conditions.
|
||||||
|
*
|
||||||
* @param params the parameter conditions, following
|
* @param params the parameter conditions, following
|
||||||
* {@link org.springframework.web.bind.annotation.RequestMapping#params() RequestMapping.#params()}
|
* {@link org.springframework.web.bind.annotation.RequestMapping#params() RequestMapping.#params()}
|
||||||
* @param request the current HTTP request to check
|
* @param request the current HTTP request to check
|
||||||
@@ -66,12 +68,10 @@ abstract class ServletAnnotationMappingUtils {
|
|||||||
if (WebUtils.hasSubmitParameter(request, param.substring(1))) {
|
if (WebUtils.hasSubmitParameter(request, param.substring(1))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else if (!WebUtils.hasSubmitParameter(request, param)) {
|
||||||
else if (!WebUtils.hasSubmitParameter(request, param)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
boolean negated = separator > 0 && param.charAt(separator - 1) == '!';
|
boolean negated = separator > 0 && param.charAt(separator - 1) == '!';
|
||||||
String key = !negated ? param.substring(0, separator) : param.substring(0, separator - 1);
|
String key = !negated ? param.substring(0, separator) : param.substring(0, separator - 1);
|
||||||
String value = param.substring(separator + 1);
|
String value = param.substring(separator + 1);
|
||||||
@@ -86,6 +86,7 @@ abstract class ServletAnnotationMappingUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the given request matches the specified header conditions.
|
* Check whether the given request matches the specified header conditions.
|
||||||
|
*
|
||||||
* @param headers the header conditions, following
|
* @param headers the header conditions, following
|
||||||
* {@link org.springframework.web.bind.annotation.RequestMapping#headers() RequestMapping.headers()}
|
* {@link org.springframework.web.bind.annotation.RequestMapping#headers() RequestMapping.headers()}
|
||||||
* @param request the current HTTP request to check
|
* @param request the current HTTP request to check
|
||||||
@@ -99,12 +100,10 @@ abstract class ServletAnnotationMappingUtils {
|
|||||||
if (request.getHeader(header.substring(1)) != null) {
|
if (request.getHeader(header.substring(1)) != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else if (request.getHeader(header) == null) {
|
||||||
else if (request.getHeader(header) == null) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
boolean negated = separator > 0 && header.charAt(separator - 1) == '!';
|
boolean negated = separator > 0 && header.charAt(separator - 1) == '!';
|
||||||
String key = !negated ? header.substring(0, separator) : header.substring(0, separator - 1);
|
String key = !negated ? header.substring(0, separator) : header.substring(0, separator - 1);
|
||||||
String value = header.substring(separator + 1);
|
String value = header.substring(separator + 1);
|
||||||
@@ -126,8 +125,7 @@ abstract class ServletAnnotationMappingUtils {
|
|||||||
if (!found) {
|
if (!found) {
|
||||||
return negated;
|
return negated;
|
||||||
}
|
}
|
||||||
}
|
} else if (!value.equals(request.getHeader(key))) {
|
||||||
else if (!value.equals(request.getHeader(key))) {
|
|
||||||
return negated;
|
return negated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,68 +17,30 @@
|
|||||||
package org.springframework.data.document.web.servlet.mvc.annotation.support;
|
package org.springframework.data.document.web.servlet.mvc.annotation.support;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.*;
|
||||||
import java.lang.reflect.GenericArrayType;
|
import java.util.*;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.BridgeMethodResolver;
|
import org.springframework.core.*;
|
||||||
import org.springframework.core.Conventions;
|
|
||||||
import org.springframework.core.GenericTypeResolver;
|
|
||||||
import org.springframework.core.MethodParameter;
|
|
||||||
import org.springframework.core.ParameterNameDiscoverer;
|
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.data.document.web.servlet.ActionInterceptor;
|
import org.springframework.data.document.web.servlet.ActionInterceptor;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.*;
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.HttpInputMessage;
|
|
||||||
import org.springframework.http.HttpOutputMessage;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.ui.ExtendedModelMap;
|
import org.springframework.ui.ExtendedModelMap;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.*;
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
|
||||||
import org.springframework.util.MultiValueMap;
|
|
||||||
import org.springframework.util.ReflectionUtils;
|
|
||||||
import org.springframework.validation.BindException;
|
import org.springframework.validation.BindException;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
||||||
import org.springframework.web.bind.WebDataBinder;
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
import org.springframework.web.bind.annotation.CookieValue;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.InitBinder;
|
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestHeader;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.ValueConstants;
|
|
||||||
import org.springframework.web.bind.annotation.support.HandlerMethodInvocationException;
|
import org.springframework.web.bind.annotation.support.HandlerMethodInvocationException;
|
||||||
import org.springframework.web.bind.annotation.support.HandlerMethodResolver;
|
import org.springframework.web.bind.annotation.support.HandlerMethodResolver;
|
||||||
import org.springframework.web.bind.support.DefaultSessionAttributeStore;
|
import org.springframework.web.bind.support.*;
|
||||||
import org.springframework.web.bind.support.SessionAttributeStore;
|
|
||||||
import org.springframework.web.bind.support.SessionStatus;
|
|
||||||
import org.springframework.web.bind.support.SimpleSessionStatus;
|
|
||||||
import org.springframework.web.bind.support.WebArgumentResolver;
|
|
||||||
import org.springframework.web.bind.support.WebBindingInitializer;
|
|
||||||
import org.springframework.web.bind.support.WebRequestDataBinder;
|
|
||||||
import org.springframework.web.context.request.NativeWebRequest;
|
import org.springframework.web.context.request.NativeWebRequest;
|
||||||
import org.springframework.web.context.request.WebRequest;
|
import org.springframework.web.context.request.WebRequest;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -87,20 +49,22 @@ import org.springframework.web.multipart.MultipartRequest;
|
|||||||
/**
|
/**
|
||||||
* Support class for invoking an annotated handler method. Operates on the introspection results of a {@link
|
* Support class for invoking an annotated handler method. Operates on the introspection results of a {@link
|
||||||
* HandlerMethodResolver} for a specific handler type.
|
* HandlerMethodResolver} for a specific handler type.
|
||||||
*
|
* <p/>
|
||||||
* <p>Used by {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter} and {@link
|
* <p>Used by {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter} and {@link
|
||||||
* org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter}.
|
* org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter}.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 2.5.2
|
|
||||||
* @see #invokeHandlerMethod
|
* @see #invokeHandlerMethod
|
||||||
|
* @since 2.5.2
|
||||||
*/
|
*/
|
||||||
public class InterceptingHandlerMethodInvoker {
|
public class InterceptingHandlerMethodInvoker {
|
||||||
|
|
||||||
private static final String MODEL_KEY_PREFIX_STALE = SessionAttributeStore.class.getName() + ".STALE.";
|
private static final String MODEL_KEY_PREFIX_STALE = SessionAttributeStore.class.getName() + ".STALE.";
|
||||||
|
|
||||||
/** We'll create a lot of these objects, so we don't want a new logger every time. */
|
/**
|
||||||
|
* We'll create a lot of these objects, so we don't want a new logger every time.
|
||||||
|
*/
|
||||||
private static final Log logger = LogFactory.getLog(InterceptingHandlerMethodInvoker.class);
|
private static final Log logger = LogFactory.getLog(InterceptingHandlerMethodInvoker.class);
|
||||||
|
|
||||||
protected final HandlerMethodResolver methodResolver;
|
protected final HandlerMethodResolver methodResolver;
|
||||||
@@ -184,13 +148,11 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
}
|
}
|
||||||
ReflectionUtils.makeAccessible(handlerMethodToInvoke);
|
ReflectionUtils.makeAccessible(handlerMethodToInvoke);
|
||||||
return handlerMethodToInvoke.invoke(handler, args);
|
return handlerMethodToInvoke.invoke(handler, args);
|
||||||
}
|
} catch (IllegalStateException ex) {
|
||||||
catch (IllegalStateException ex) {
|
|
||||||
// Internal assertion failed (e.g. invalid signature):
|
// Internal assertion failed (e.g. invalid signature):
|
||||||
// throw exception with full handler method context...
|
// throw exception with full handler method context...
|
||||||
throw new HandlerMethodInvocationException(handlerMethodToInvoke, ex);
|
throw new HandlerMethodInvocationException(handlerMethodToInvoke, ex);
|
||||||
}
|
} catch (InvocationTargetException ex) {
|
||||||
catch (InvocationTargetException ex) {
|
|
||||||
// User-defined @ModelAttribute/@InitBinder/@RequestMapping method threw an exception...
|
// User-defined @ModelAttribute/@InitBinder/@RequestMapping method threw an exception...
|
||||||
ReflectionUtils.rethrowException(ex.getTargetException());
|
ReflectionUtils.rethrowException(ex.getTargetException());
|
||||||
return null;
|
return null;
|
||||||
@@ -219,8 +181,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
if (isSessionAttr) {
|
if (isSessionAttr) {
|
||||||
if (this.sessionStatus.isComplete()) {
|
if (this.sessionStatus.isComplete()) {
|
||||||
implicitModel.put(MODEL_KEY_PREFIX_STALE + attrName, Boolean.TRUE);
|
implicitModel.put(MODEL_KEY_PREFIX_STALE + attrName, Boolean.TRUE);
|
||||||
}
|
} else if (!implicitModel.containsKey(MODEL_KEY_PREFIX_STALE + attrName)) {
|
||||||
else if (!implicitModel.containsKey(MODEL_KEY_PREFIX_STALE + attrName)) {
|
|
||||||
this.sessionAttributeStore.storeAttribute(webRequest, attrName, attrValue);
|
this.sessionAttributeStore.storeAttribute(webRequest, attrName, attrValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,8 +195,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (InvocationTargetException ex) {
|
||||||
catch (InvocationTargetException ex) {
|
|
||||||
// User-defined @InitBinder method threw an exception...
|
// User-defined @InitBinder method threw an exception...
|
||||||
ReflectionUtils.rethrowException(ex.getTargetException());
|
ReflectionUtils.rethrowException(ex.getTargetException());
|
||||||
}
|
}
|
||||||
@@ -272,39 +232,32 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
required = requestParam.required();
|
required = requestParam.required();
|
||||||
defaultValue = parseDefaultValueAttribute(requestParam.defaultValue());
|
defaultValue = parseDefaultValueAttribute(requestParam.defaultValue());
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (RequestHeader.class.isInstance(paramAnn)) {
|
||||||
else if (RequestHeader.class.isInstance(paramAnn)) {
|
|
||||||
RequestHeader requestHeader = (RequestHeader) paramAnn;
|
RequestHeader requestHeader = (RequestHeader) paramAnn;
|
||||||
headerName = requestHeader.value();
|
headerName = requestHeader.value();
|
||||||
required = requestHeader.required();
|
required = requestHeader.required();
|
||||||
defaultValue = parseDefaultValueAttribute(requestHeader.defaultValue());
|
defaultValue = parseDefaultValueAttribute(requestHeader.defaultValue());
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (RequestBody.class.isInstance(paramAnn)) {
|
||||||
else if (RequestBody.class.isInstance(paramAnn)) {
|
|
||||||
requestBodyFound = true;
|
requestBodyFound = true;
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (CookieValue.class.isInstance(paramAnn)) {
|
||||||
else if (CookieValue.class.isInstance(paramAnn)) {
|
|
||||||
CookieValue cookieValue = (CookieValue) paramAnn;
|
CookieValue cookieValue = (CookieValue) paramAnn;
|
||||||
cookieName = cookieValue.value();
|
cookieName = cookieValue.value();
|
||||||
required = cookieValue.required();
|
required = cookieValue.required();
|
||||||
defaultValue = parseDefaultValueAttribute(cookieValue.defaultValue());
|
defaultValue = parseDefaultValueAttribute(cookieValue.defaultValue());
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (PathVariable.class.isInstance(paramAnn)) {
|
||||||
else if (PathVariable.class.isInstance(paramAnn)) {
|
|
||||||
PathVariable pathVar = (PathVariable) paramAnn;
|
PathVariable pathVar = (PathVariable) paramAnn;
|
||||||
pathVarName = pathVar.value();
|
pathVarName = pathVar.value();
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (ModelAttribute.class.isInstance(paramAnn)) {
|
||||||
else if (ModelAttribute.class.isInstance(paramAnn)) {
|
|
||||||
ModelAttribute attr = (ModelAttribute) paramAnn;
|
ModelAttribute attr = (ModelAttribute) paramAnn;
|
||||||
attrName = attr.value();
|
attrName = attr.value();
|
||||||
annotationsFound++;
|
annotationsFound++;
|
||||||
}
|
} else if (Value.class.isInstance(paramAnn)) {
|
||||||
else if (Value.class.isInstance(paramAnn)) {
|
|
||||||
defaultValue = ((Value) paramAnn).value();
|
defaultValue = ((Value) paramAnn).value();
|
||||||
}
|
} else if ("Valid".equals(paramAnn.annotationType().getSimpleName())) {
|
||||||
else if ("Valid".equals(paramAnn.annotationType().getSimpleName())) {
|
|
||||||
validate = true;
|
validate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,29 +271,22 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
Object argValue = resolveCommonArgument(methodParam, webRequest);
|
Object argValue = resolveCommonArgument(methodParam, webRequest);
|
||||||
if (argValue != WebArgumentResolver.UNRESOLVED) {
|
if (argValue != WebArgumentResolver.UNRESOLVED) {
|
||||||
args[i] = argValue;
|
args[i] = argValue;
|
||||||
}
|
} else if (defaultValue != null) {
|
||||||
else if (defaultValue != null) {
|
|
||||||
args[i] = resolveDefaultValue(defaultValue);
|
args[i] = resolveDefaultValue(defaultValue);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Class paramType = methodParam.getParameterType();
|
Class paramType = methodParam.getParameterType();
|
||||||
if (Model.class.isAssignableFrom(paramType) || Map.class.isAssignableFrom(paramType)) {
|
if (Model.class.isAssignableFrom(paramType) || Map.class.isAssignableFrom(paramType)) {
|
||||||
args[i] = implicitModel;
|
args[i] = implicitModel;
|
||||||
}
|
} else if (SessionStatus.class.isAssignableFrom(paramType)) {
|
||||||
else if (SessionStatus.class.isAssignableFrom(paramType)) {
|
|
||||||
args[i] = this.sessionStatus;
|
args[i] = this.sessionStatus;
|
||||||
}
|
} else if (HttpEntity.class.isAssignableFrom(paramType)) {
|
||||||
else if (HttpEntity.class.isAssignableFrom(paramType)) {
|
|
||||||
args[i] = resolveHttpEntityRequest(methodParam, webRequest);
|
args[i] = resolveHttpEntityRequest(methodParam, webRequest);
|
||||||
}
|
} else if (Errors.class.isAssignableFrom(paramType)) {
|
||||||
else if (Errors.class.isAssignableFrom(paramType)) {
|
|
||||||
throw new IllegalStateException("Errors/BindingResult argument declared " +
|
throw new IllegalStateException("Errors/BindingResult argument declared " +
|
||||||
"without preceding model attribute. Check your handler method signature!");
|
"without preceding model attribute. Check your handler method signature!");
|
||||||
}
|
} else if (BeanUtils.isSimpleProperty(paramType)) {
|
||||||
else if (BeanUtils.isSimpleProperty(paramType)) {
|
|
||||||
paramName = "";
|
paramName = "";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
attrName = "";
|
attrName = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -348,20 +294,15 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
|
|
||||||
if (paramName != null) {
|
if (paramName != null) {
|
||||||
args[i] = resolveRequestParam(paramName, required, defaultValue, methodParam, webRequest, handler);
|
args[i] = resolveRequestParam(paramName, required, defaultValue, methodParam, webRequest, handler);
|
||||||
}
|
} else if (headerName != null) {
|
||||||
else if (headerName != null) {
|
|
||||||
args[i] = resolveRequestHeader(headerName, required, defaultValue, methodParam, webRequest, handler);
|
args[i] = resolveRequestHeader(headerName, required, defaultValue, methodParam, webRequest, handler);
|
||||||
}
|
} else if (requestBodyFound) {
|
||||||
else if (requestBodyFound) {
|
|
||||||
args[i] = resolveRequestBody(methodParam, webRequest, handler);
|
args[i] = resolveRequestBody(methodParam, webRequest, handler);
|
||||||
}
|
} else if (cookieName != null) {
|
||||||
else if (cookieName != null) {
|
|
||||||
args[i] = resolveCookieValue(cookieName, required, defaultValue, methodParam, webRequest, handler);
|
args[i] = resolveCookieValue(cookieName, required, defaultValue, methodParam, webRequest, handler);
|
||||||
}
|
} else if (pathVarName != null) {
|
||||||
else if (pathVarName != null) {
|
|
||||||
args[i] = resolvePathVariable(pathVarName, methodParam, webRequest, handler);
|
args[i] = resolvePathVariable(pathVarName, methodParam, webRequest, handler);
|
||||||
}
|
} else if (attrName != null) {
|
||||||
else if (attrName != null) {
|
|
||||||
WebDataBinder binder =
|
WebDataBinder binder =
|
||||||
resolveModelAttribute(attrName, methodParam, implicitModel, webRequest, handler);
|
resolveModelAttribute(attrName, methodParam, implicitModel, webRequest, handler);
|
||||||
boolean assignBindingResult = (args.length > i + 1 && Errors.class.isAssignableFrom(paramTypes[i + 1]));
|
boolean assignBindingResult = (args.length > i + 1 && Errors.class.isAssignableFrom(paramTypes[i + 1]));
|
||||||
@@ -434,12 +375,10 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
paramRequired = requestParam.required();
|
paramRequired = requestParam.required();
|
||||||
paramDefaultValue = parseDefaultValueAttribute(requestParam.defaultValue());
|
paramDefaultValue = parseDefaultValueAttribute(requestParam.defaultValue());
|
||||||
break;
|
break;
|
||||||
}
|
} else if (ModelAttribute.class.isInstance(paramAnn)) {
|
||||||
else if (ModelAttribute.class.isInstance(paramAnn)) {
|
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"@ModelAttribute is not supported on @InitBinder methods: " + initBinderMethod);
|
"@ModelAttribute is not supported on @InitBinder methods: " + initBinderMethod);
|
||||||
}
|
} else if (PathVariable.class.isInstance(paramAnn)) {
|
||||||
else if (PathVariable.class.isInstance(paramAnn)) {
|
|
||||||
PathVariable pathVar = (PathVariable) paramAnn;
|
PathVariable pathVar = (PathVariable) paramAnn;
|
||||||
pathVarName = pathVar.value();
|
pathVarName = pathVar.value();
|
||||||
}
|
}
|
||||||
@@ -449,16 +388,13 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
Object argValue = resolveCommonArgument(methodParam, webRequest);
|
Object argValue = resolveCommonArgument(methodParam, webRequest);
|
||||||
if (argValue != WebArgumentResolver.UNRESOLVED) {
|
if (argValue != WebArgumentResolver.UNRESOLVED) {
|
||||||
initBinderArgs[i] = argValue;
|
initBinderArgs[i] = argValue;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Class paramType = initBinderParams[i];
|
Class paramType = initBinderParams[i];
|
||||||
if (paramType.isInstance(binder)) {
|
if (paramType.isInstance(binder)) {
|
||||||
initBinderArgs[i] = binder;
|
initBinderArgs[i] = binder;
|
||||||
}
|
} else if (BeanUtils.isSimpleProperty(paramType)) {
|
||||||
else if (BeanUtils.isSimpleProperty(paramType)) {
|
|
||||||
paramName = "";
|
paramName = "";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
|
throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
|
||||||
"] for @InitBinder method: " + initBinderMethod);
|
"] for @InitBinder method: " + initBinderMethod);
|
||||||
}
|
}
|
||||||
@@ -468,8 +404,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
if (paramName != null) {
|
if (paramName != null) {
|
||||||
initBinderArgs[i] =
|
initBinderArgs[i] =
|
||||||
resolveRequestParam(paramName, paramRequired, paramDefaultValue, methodParam, webRequest, null);
|
resolveRequestParam(paramName, paramRequired, paramDefaultValue, methodParam, webRequest, null);
|
||||||
}
|
} else if (pathVarName != null) {
|
||||||
else if (pathVarName != null) {
|
|
||||||
initBinderArgs[i] = resolvePathVariable(pathVarName, methodParam, webRequest, null);
|
initBinderArgs[i] = resolvePathVariable(pathVarName, methodParam, webRequest, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -496,8 +431,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
if (!files.isEmpty()) {
|
if (!files.isEmpty()) {
|
||||||
if (files.size() == 1 && !paramType.isArray() && !Collection.class.isAssignableFrom(paramType)) {
|
if (files.size() == 1 && !paramType.isArray() && !Collection.class.isAssignableFrom(paramType)) {
|
||||||
paramValue = files.get(0);
|
paramValue = files.get(0);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
paramValue = files;
|
paramValue = files;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -507,8 +441,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
if (paramValues != null) {
|
if (paramValues != null) {
|
||||||
if (paramValues.length == 1 && !paramType.isArray() && !Collection.class.isAssignableFrom(paramType)) {
|
if (paramValues.length == 1 && !paramType.isArray() && !Collection.class.isAssignableFrom(paramType)) {
|
||||||
paramValue = paramValues[0];
|
paramValue = paramValues[0];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
paramValue = paramValues;
|
paramValue = paramValues;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -516,8 +449,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
if (paramValue == null) {
|
if (paramValue == null) {
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
paramValue = resolveDefaultValue(defaultValue);
|
paramValue = resolveDefaultValue(defaultValue);
|
||||||
}
|
} else if (required) {
|
||||||
else if (required) {
|
|
||||||
raiseMissingParameterException(paramName, paramType);
|
raiseMissingParameterException(paramName, paramType);
|
||||||
}
|
}
|
||||||
paramValue = checkValue(paramName, paramValue, paramType);
|
paramValue = checkValue(paramName, paramValue, paramType);
|
||||||
@@ -537,8 +469,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Map<String, String> result = new LinkedHashMap<String, String>(parameterMap.size());
|
Map<String, String> result = new LinkedHashMap<String, String>(parameterMap.size());
|
||||||
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
|
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
|
||||||
if (entry.getValue().length > 0) {
|
if (entry.getValue().length > 0) {
|
||||||
@@ -569,8 +500,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
if (headerValue == null) {
|
if (headerValue == null) {
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
headerValue = resolveDefaultValue(defaultValue);
|
headerValue = resolveDefaultValue(defaultValue);
|
||||||
}
|
} else if (required) {
|
||||||
else if (required) {
|
|
||||||
raiseMissingHeaderException(headerName, paramType);
|
raiseMissingHeaderException(headerName, paramType);
|
||||||
}
|
}
|
||||||
headerValue = checkValue(headerName, headerValue, paramType);
|
headerValue = checkValue(headerName, headerValue, paramType);
|
||||||
@@ -585,8 +515,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
MultiValueMap<String, String> result;
|
MultiValueMap<String, String> result;
|
||||||
if (HttpHeaders.class.isAssignableFrom(mapType)) {
|
if (HttpHeaders.class.isAssignableFrom(mapType)) {
|
||||||
result = new HttpHeaders();
|
result = new HttpHeaders();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
result = new LinkedMultiValueMap<String, String>();
|
result = new LinkedMultiValueMap<String, String>();
|
||||||
}
|
}
|
||||||
for (Iterator<String> iterator = webRequest.getHeaderNames(); iterator.hasNext();) {
|
for (Iterator<String> iterator = webRequest.getHeaderNames(); iterator.hasNext();) {
|
||||||
@@ -596,8 +525,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Map<String, String> result = new LinkedHashMap<String, String>();
|
Map<String, String> result = new LinkedHashMap<String, String>();
|
||||||
for (Iterator<String> iterator = webRequest.getHeaderNames(); iterator.hasNext();) {
|
for (Iterator<String> iterator = webRequest.getHeaderNames(); iterator.hasNext();) {
|
||||||
String headerName = iterator.next();
|
String headerName = iterator.next();
|
||||||
@@ -664,8 +592,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
Type typeArgument = type.getActualTypeArguments()[0];
|
Type typeArgument = type.getActualTypeArguments()[0];
|
||||||
if (typeArgument instanceof Class) {
|
if (typeArgument instanceof Class) {
|
||||||
return (Class<?>) typeArgument;
|
return (Class<?>) typeArgument;
|
||||||
}
|
} else if (typeArgument instanceof GenericArrayType) {
|
||||||
else if (typeArgument instanceof GenericArrayType) {
|
|
||||||
Type componentType = ((GenericArrayType) typeArgument).getGenericComponentType();
|
Type componentType = ((GenericArrayType) typeArgument).getGenericComponentType();
|
||||||
if (componentType instanceof Class) {
|
if (componentType instanceof Class) {
|
||||||
// Surely, there should be a nicer way to do this
|
// Surely, there should be a nicer way to do this
|
||||||
@@ -691,8 +618,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
if (cookieValue == null) {
|
if (cookieValue == null) {
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
cookieValue = resolveDefaultValue(defaultValue);
|
cookieValue = resolveDefaultValue(defaultValue);
|
||||||
}
|
} else if (required) {
|
||||||
else if (required) {
|
|
||||||
raiseMissingCookieException(cookieName, paramType);
|
raiseMissingCookieException(cookieName, paramType);
|
||||||
}
|
}
|
||||||
cookieValue = checkValue(cookieName, cookieValue, paramType);
|
cookieValue = checkValue(cookieName, cookieValue, paramType);
|
||||||
@@ -749,8 +675,7 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
if (boolean.class.equals(paramType)) {
|
if (boolean.class.equals(paramType)) {
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
}
|
} else if (paramType.isPrimitive()) {
|
||||||
else if (paramType.isPrimitive()) {
|
|
||||||
throw new IllegalStateException("Optional " + paramType + " parameter '" + name +
|
throw new IllegalStateException("Optional " + paramType + " parameter '" + name +
|
||||||
"' is not present but cannot be translated into a null value due to being declared as a " +
|
"' is not present but cannot be translated into a null value due to being declared as a " +
|
||||||
"primitive type. Consider declaring it as object wrapper for the corresponding primitive type.");
|
"primitive type. Consider declaring it as object wrapper for the corresponding primitive type.");
|
||||||
@@ -771,14 +696,12 @@ public class InterceptingHandlerMethodInvoker {
|
|||||||
Object bindObject;
|
Object bindObject;
|
||||||
if (implicitModel.containsKey(name)) {
|
if (implicitModel.containsKey(name)) {
|
||||||
bindObject = implicitModel.get(name);
|
bindObject = implicitModel.get(name);
|
||||||
}
|
} else if (this.methodResolver.isSessionAttribute(name, paramType)) {
|
||||||
else if (this.methodResolver.isSessionAttribute(name, paramType)) {
|
|
||||||
bindObject = this.sessionAttributeStore.retrieveAttribute(webRequest, name);
|
bindObject = this.sessionAttributeStore.retrieveAttribute(webRequest, name);
|
||||||
if (bindObject == null) {
|
if (bindObject == null) {
|
||||||
raiseSessionRequiredException("Session attribute '" + name + "' required - not found in session");
|
raiseSessionRequiredException("Session attribute '" + name + "' required - not found in session");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
bindObject = BeanUtils.instantiateClass(paramType);
|
bindObject = BeanUtils.instantiateClass(paramType);
|
||||||
}
|
}
|
||||||
WebDataBinder binder = createBinder(webRequest, bindObject, name);
|
WebDataBinder binder = createBinder(webRequest, bindObject, name);
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>spring-data-document-parent</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#Tue Jun 29 21:59:00 EDT 2010
|
|
||||||
activeProfiles=
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
fullBuildGoals=process-test-resources
|
|
||||||
includeModules=false
|
|
||||||
resolveWorkspaceProjects=true
|
|
||||||
resourceFilterGoals=process-resources resources\:testResources
|
|
||||||
skipCompilerPlugin=true
|
|
||||||
version=1
|
|
||||||
@@ -62,7 +62,8 @@
|
|||||||
</downloadUrl>
|
</downloadUrl>
|
||||||
<site>
|
<site>
|
||||||
<id>static.springframework.org</id>
|
<id>static.springframework.org</id>
|
||||||
<url>scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/data-document/docs/${project.version}
|
<url>
|
||||||
|
scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/data-document/docs/${project.version}
|
||||||
</url>
|
</url>
|
||||||
</site>
|
</site>
|
||||||
<repository>
|
<repository>
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry including="**/*.aj|**/*.java" kind="src" output="target/classes" path="src/main/java"/>
|
|
||||||
<classpathentry including="**/*.aj|**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
|
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
|
||||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
|
||||||
</classpath>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>spring-data-mongodb-cross-store</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.ajdt.core.ajbuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.eclipse.ajdt.ui.ajnature</nature>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
||||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#Tue Mar 01 09:48:37 EST 2011
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#Mon Feb 28 16:25:59 EST 2011
|
|
||||||
activeProfiles=
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
fullBuildGoals=process-test-resources
|
|
||||||
resolveWorkspaceProjects=true
|
|
||||||
resourceFilterGoals=process-resources resources\:testResources
|
|
||||||
skipCompilerPlugin=true
|
|
||||||
version=1
|
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package org.springframework.persistence.document;
|
package org.springframework.persistence.document;
|
||||||
|
|
||||||
import java.util.Map;
|
import com.mongodb.BasicDBObject;
|
||||||
|
import com.mongodb.DBCollection;
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import com.mongodb.MongoException;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -14,13 +16,6 @@ import org.springframework.persistence.support.ChangeSetBacked;
|
|||||||
import org.springframework.persistence.support.ChangeSetPersister;
|
import org.springframework.persistence.support.ChangeSetPersister;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DB;
|
|
||||||
import com.mongodb.DBCollection;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
import com.mongodb.MongoException;
|
|
||||||
|
|
||||||
//import edu.emory.mathcs.backport.java.util.Arrays;
|
//import edu.emory.mathcs.backport.java.util.Arrays;
|
||||||
|
|
||||||
public class MongoChangeSetPersister implements ChangeSetPersister<Object> {
|
public class MongoChangeSetPersister implements ChangeSetPersister<Object> {
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import org.springframework.persistence.support.ChangeSetPersister.NotFoundExcept
|
|||||||
import org.springframework.persistence.support.EntityInstantiator;
|
import org.springframework.persistence.support.EntityInstantiator;
|
||||||
import org.springframework.persistence.support.HashMapChangeSet;
|
import org.springframework.persistence.support.HashMapChangeSet;
|
||||||
|
|
||||||
import com.mongodb.DB;
|
|
||||||
|
|
||||||
public class MongoEntityOperations extends OrderedEntityOperations<Object, ChangeSetBacked> {
|
public class MongoEntityOperations extends OrderedEntityOperations<Object, ChangeSetBacked> {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -45,8 +43,7 @@ public class MongoEntityOperations extends OrderedEntityOperations<Object, Chang
|
|||||||
ChangeSet cs = new HashMapChangeSet();
|
ChangeSet cs = new HashMapChangeSet();
|
||||||
changeSetPersister.getPersistentState(entityClass, key, cs);
|
changeSetPersister.getPersistentState(entityClass, key, cs);
|
||||||
return entityInstantiator.createEntityFromState(cs, entityClass);
|
return entityInstantiator.createEntityFromState(cs, entityClass);
|
||||||
}
|
} catch (NotFoundException ex) {
|
||||||
catch (NotFoundException ex) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.springframework.data.document.persistence;
|
|||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.PersistenceContext;
|
||||||
|
|
||||||
|
import com.mongodb.*;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -17,12 +18,6 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.mongodb.DBCollection;
|
|
||||||
import com.mongodb.DBCursor;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
import com.mongodb.MongoException;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext.xml")
|
@ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext.xml")
|
||||||
public class CrossStoreMongoTests {
|
public class CrossStoreMongoTests {
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import javax.persistence.Id;
|
|||||||
@Entity
|
@Entity
|
||||||
public class Account {
|
public class Account {
|
||||||
|
|
||||||
@Id private Long id;
|
@Id
|
||||||
|
private Long id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,7 @@ package org.springframework.persistence.document.test;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Configurable;
|
import org.springframework.beans.factory.annotation.Configurable;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.persistence.support.ChangeSet;
|
import org.springframework.persistence.support.*;
|
||||||
import org.springframework.persistence.support.ChangeSetBacked;
|
|
||||||
import org.springframework.persistence.support.ChangeSetConfiguration;
|
|
||||||
import org.springframework.persistence.support.ChangeSetPersister;
|
|
||||||
import org.springframework.persistence.support.ChangeSetSynchronizer;
|
|
||||||
import org.springframework.persistence.support.HashMapChangeSet;
|
|
||||||
import org.springframework.persistence.support.ChangeSetPersister.NotFoundException;
|
import org.springframework.persistence.support.ChangeSetPersister.NotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,8 +46,7 @@ privileged aspect MongoPerson_Roo_Mongo_Entity {
|
|||||||
try {
|
try {
|
||||||
changeSetPersister().getPersistentState(MongoPerson.class, id, rv);
|
changeSetPersister().getPersistentState(MongoPerson.class, id, rv);
|
||||||
return new MongoPerson(rv);
|
return new MongoPerson(rv);
|
||||||
}
|
} catch (NotFoundException ex) {
|
||||||
catch (NotFoundException ex) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import org.springframework.persistence.RelatedEntity;
|
|||||||
@Entity
|
@Entity
|
||||||
public class Person {
|
public class Person {
|
||||||
|
|
||||||
@Id Long id;
|
@Id
|
||||||
|
Long id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
version="2.0"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
||||||
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
|
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
|
||||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||||
<class>org.springframework.persistence.document.test.Account</class>
|
<class>org.springframework.persistence.document.test.Account</class>
|
||||||
|
|||||||
@@ -66,7 +66,8 @@
|
|||||||
<property name="changeSetConfiguration" ref="mongoChangeSetConfiguration"/>
|
<property name="changeSetConfiguration" ref="mongoChangeSetConfiguration"/>
|
||||||
</bean>
|
</bean>
|
||||||
<bean id="mongoChangeSetPersister" class="org.springframework.persistence.document.MongoChangeSetPersister"/>
|
<bean id="mongoChangeSetPersister" class="org.springframework.persistence.document.MongoChangeSetPersister"/>
|
||||||
<bean id="mongoChangeSetSynchronizer" class="org.springframework.persistence.support.SimpleReflectiveChangeSetSynchronizer" />
|
<bean id="mongoChangeSetSynchronizer"
|
||||||
|
class="org.springframework.persistence.support.SimpleReflectiveChangeSetSynchronizer"/>
|
||||||
<bean id="mongoChangeSetConfiguration" class="org.springframework.persistence.support.ChangeSetConfiguration">
|
<bean id="mongoChangeSetConfiguration" class="org.springframework.persistence.support.ChangeSetConfiguration">
|
||||||
<property name="changeSetPersister" ref="mongoChangeSetPersister"/>
|
<property name="changeSetPersister" ref="mongoChangeSetPersister"/>
|
||||||
<property name="changeSetManager" ref="mongoChangeSetSynchronizer"/>
|
<property name="changeSetManager" ref="mongoChangeSetSynchronizer"/>
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
|
|
||||||
<classpathentry kind="src" path="src/main/resources"/>
|
|
||||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="owner.project.facets" value="java"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
|
||||||
</classpath>
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>spring-data-mongodb</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
|
||||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
||||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
|
||||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#Wed Mar 09 13:51:37 EST 2011
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project-modules id="moduleCoreId" project-version="1.5.0">
|
|
||||||
<wb-module deploy-name="spring-data-mongodb">
|
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
|
|
||||||
</wb-module>
|
|
||||||
</project-modules>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<faceted-project>
|
|
||||||
<installed facet="jst.utility" version="1.0"/>
|
|
||||||
<installed facet="java" version="1.6"/>
|
|
||||||
</faceted-project>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#Wed Oct 06 14:49:46 EDT 2010
|
|
||||||
activeProfiles=
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
fullBuildGoals=process-test-resources
|
|
||||||
includeModules=false
|
|
||||||
resolveWorkspaceProjects=true
|
|
||||||
resourceFilterGoals=process-resources resources\:testResources
|
|
||||||
skipCompilerPlugin=true
|
|
||||||
version=1
|
|
||||||
@@ -15,10 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb;
|
package org.springframework.data.document.mongodb;
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
|
|
||||||
import com.mongodb.DBCollection;
|
import com.mongodb.DBCollection;
|
||||||
import com.mongodb.MongoException;
|
import com.mongodb.MongoException;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
|
||||||
public interface CollectionCallback<T> {
|
public interface CollectionCallback<T> {
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package org.springframework.data.document.mongodb;
|
|||||||
* Provides a simple wrapper to encapsulate the variety of settings you can use when creating a collection.
|
* Provides a simple wrapper to encapsulate the variety of settings you can use when creating a collection.
|
||||||
*
|
*
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class CollectionOptions {
|
public class CollectionOptions {
|
||||||
|
|
||||||
@@ -31,6 +30,7 @@ public class CollectionOptions {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new <code>CollectionOptions</code> instance.
|
* Constructs a new <code>CollectionOptions</code> instance.
|
||||||
|
*
|
||||||
* @param size the collection size in bytes, this data space is preallocated
|
* @param size the collection size in bytes, this data space is preallocated
|
||||||
* @param maxDocuments the maximum number of documents in the collection.
|
* @param maxDocuments the maximum number of documents in the collection.
|
||||||
* @param capped true to created a "capped" collection (fixed size with auto-FIFO behavior
|
* @param capped true to created a "capped" collection (fixed size with auto-FIFO behavior
|
||||||
|
|||||||
@@ -15,10 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb;
|
package org.springframework.data.document.mongodb;
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
|
|
||||||
import com.mongodb.DB;
|
import com.mongodb.DB;
|
||||||
import com.mongodb.MongoException;
|
import com.mongodb.MongoException;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
|
||||||
public interface DbCallback<T> {
|
public interface DbCallback<T> {
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,10 @@ package org.springframework.data.document.mongodb;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import com.mongodb.DB;
|
||||||
import org.springframework.transaction.support.ResourceHolderSupport;
|
import org.springframework.transaction.support.ResourceHolderSupport;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import com.mongodb.DB;
|
|
||||||
|
|
||||||
class DbHolder extends ResourceHolderSupport {
|
class DbHolder extends ResourceHolderSupport {
|
||||||
private static final Object DEFAULT_KEY = new Object();
|
private static final Object DEFAULT_KEY = new Object();
|
||||||
|
|
||||||
|
|||||||
@@ -15,25 +15,25 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb;
|
package org.springframework.data.document.mongodb;
|
||||||
|
|
||||||
|
import com.mongodb.DB;
|
||||||
|
import com.mongodb.Mongo;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||||
|
|
||||||
import com.mongodb.DB;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mongo server administration exposed via JMX annotations
|
* Mongo server administration exposed via JMX annotations
|
||||||
*
|
*
|
||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ManagedResource(description = "Mongo Admin Operations")
|
@ManagedResource(description = "Mongo Admin Operations")
|
||||||
public class MongoAdmin implements MongoAdminOperations {
|
public class MongoAdmin implements MongoAdminOperations {
|
||||||
|
|
||||||
/** Logger available to subclasses */
|
/**
|
||||||
|
* Logger available to subclasses
|
||||||
|
*/
|
||||||
protected final Log logger = LogFactory.getLog(getClass());
|
protected final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private Mongo mongo;
|
private Mongo mongo;
|
||||||
|
|||||||
@@ -16,23 +16,21 @@
|
|||||||
|
|
||||||
package org.springframework.data.document.mongodb;
|
package org.springframework.data.document.mongodb;
|
||||||
|
|
||||||
|
import com.mongodb.DB;
|
||||||
|
import com.mongodb.Mongo;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import com.mongodb.DB;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class featuring helper methods for internal MongoDb classes.
|
* Helper class featuring helper methods for internal MongoDb classes.
|
||||||
*
|
* <p/>
|
||||||
* <p>Mainly intended for internal use within the framework.
|
* <p>Mainly intended for internal use within the framework.
|
||||||
*
|
*
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
* @author Graeme Rocher
|
* @author Graeme Rocher
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*
|
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public abstract class MongoDbUtils {
|
public abstract class MongoDbUtils {
|
||||||
@@ -58,7 +56,6 @@ public abstract class MongoDbUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Obtains a {@link DB} connection for the given {@link Mongo} instance and database name
|
* Obtains a {@link DB} connection for the given {@link Mongo} instance and database name
|
||||||
*
|
*
|
||||||
* @param mongo The {@link Mongo} instance
|
* @param mongo The {@link Mongo} instance
|
||||||
@@ -109,8 +106,7 @@ public abstract class MongoDbUtils {
|
|||||||
DbHolder holderToUse = dbHolder;
|
DbHolder holderToUse = dbHolder;
|
||||||
if (holderToUse == null) {
|
if (holderToUse == null) {
|
||||||
holderToUse = new DbHolder(db);
|
holderToUse = new DbHolder(db);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
holderToUse.addDB(db);
|
holderToUse.addDB(db);
|
||||||
}
|
}
|
||||||
TransactionSynchronizationManager.registerSynchronization(new MongoSynchronization(holderToUse, mongo));
|
TransactionSynchronizationManager.registerSynchronization(new MongoSynchronization(holderToUse, mongo));
|
||||||
@@ -133,6 +129,7 @@ public abstract class MongoDbUtils {
|
|||||||
/**
|
/**
|
||||||
* Return whether the given DB instance is transactional, that is,
|
* Return whether the given DB instance is transactional, that is,
|
||||||
* bound to the current thread by Spring's transaction facilities.
|
* bound to the current thread by Spring's transaction facilities.
|
||||||
|
*
|
||||||
* @param db the DB to check
|
* @param db the DB to check
|
||||||
* @param mongo the Mongo instance that the DB was created with
|
* @param mongo the Mongo instance that the DB was created with
|
||||||
* (may be <code>null</code>)
|
* (may be <code>null</code>)
|
||||||
@@ -150,6 +147,7 @@ public abstract class MongoDbUtils {
|
|||||||
/**
|
/**
|
||||||
* Perform actual closing of the Mongo DB object,
|
* Perform actual closing of the Mongo DB object,
|
||||||
* catching and logging any cleanup exceptions thrown.
|
* catching and logging any cleanup exceptions thrown.
|
||||||
|
*
|
||||||
* @param db the DB to close (may be <code>null</code>)
|
* @param db the DB to close (may be <code>null</code>)
|
||||||
*/
|
*/
|
||||||
public static void closeDB(DB db) {
|
public static void closeDB(DB db) {
|
||||||
@@ -157,8 +155,7 @@ public abstract class MongoDbUtils {
|
|||||||
LOGGER.debug("Closing Mongo DB object");
|
LOGGER.debug("Closing Mongo DB object");
|
||||||
try {
|
try {
|
||||||
db.requestDone();
|
db.requestDone();
|
||||||
}
|
} catch (Throwable ex) {
|
||||||
catch (Throwable ex) {
|
|
||||||
LOGGER.debug("Unexpected exception on closing Mongo DB object", ex);
|
LOGGER.debug("Unexpected exception on closing Mongo DB object", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,25 +15,23 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb;
|
package org.springframework.data.document.mongodb;
|
||||||
|
|
||||||
|
import com.mongodb.MongoException;
|
||||||
|
import com.mongodb.MongoException.DuplicateKey;
|
||||||
|
import com.mongodb.MongoException.Network;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.DataAccessResourceFailureException;
|
import org.springframework.dao.DataAccessResourceFailureException;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||||
import org.springframework.data.document.UncategorizedDocumentStoreException;
|
import org.springframework.data.document.UncategorizedDocumentStoreException;
|
||||||
|
|
||||||
import com.mongodb.MongoException;
|
|
||||||
import com.mongodb.MongoException.DuplicateKey;
|
|
||||||
import com.mongodb.MongoException.Network;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple {@link PersistenceExceptionTranslator} for Mongo. Convert the given runtime exception to an appropriate
|
* Simple {@link PersistenceExceptionTranslator} for Mongo. Convert the given runtime exception to an appropriate
|
||||||
* exception from the {@code org.springframework.dao} hierarchy. Return {@literal null} if no translation is
|
* exception from the {@code org.springframework.dao} hierarchy. Return {@literal null} if no translation is
|
||||||
* appropriate: any other exception may have resulted from user code, and should not be translated.
|
* appropriate: any other exception may have resulted from user code, and should not be translated.
|
||||||
|
*
|
||||||
* @param ex runtime exception that occurred
|
* @param ex runtime exception that occurred
|
||||||
* @return the corresponding DataAccessException instance, or {@literal null} if the exception should not be translated
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
|
* @return the corresponding DataAccessException instance, or {@literal null} if the exception should not be translated
|
||||||
*/
|
*/
|
||||||
public class MongoExceptionTranslator implements PersistenceExceptionTranslator {
|
public class MongoExceptionTranslator implements PersistenceExceptionTranslator {
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ package org.springframework.data.document.mongodb;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.mongodb.Mongo;
|
||||||
|
import com.mongodb.MongoOptions;
|
||||||
|
import com.mongodb.ServerAddress;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
@@ -26,16 +29,11 @@ import org.springframework.dao.DataAccessException;
|
|||||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
import com.mongodb.MongoOptions;
|
|
||||||
import com.mongodb.ServerAddress;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenient factory for configuring MongoDB.
|
* Convenient factory for configuring MongoDB.
|
||||||
*
|
*
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
* @author Graeme Rocher
|
* @author Graeme Rocher
|
||||||
*
|
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class MongoFactoryBean implements FactoryBean<Mongo>, InitializingBean, PersistenceExceptionTranslator {
|
public class MongoFactoryBean implements FactoryBean<Mongo>, InitializingBean, PersistenceExceptionTranslator {
|
||||||
@@ -105,8 +103,7 @@ public class MongoFactoryBean implements FactoryBean<Mongo>, InitializingBean, P
|
|||||||
if (host == null) {
|
if (host == null) {
|
||||||
logger.warn("Property host not specified. Using default configuration");
|
logger.warn("Property host not specified. Using default configuration");
|
||||||
mongo = new Mongo();
|
mongo = new Mongo();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ServerAddress defaultOptions = new ServerAddress();
|
ServerAddress defaultOptions = new ServerAddress();
|
||||||
if (mongoOptions == null) mongoOptions = new MongoOptions();
|
if (mongoOptions == null) mongoOptions = new MongoOptions();
|
||||||
if (replicaPair != null) {
|
if (replicaPair != null) {
|
||||||
@@ -114,16 +111,13 @@ public class MongoFactoryBean implements FactoryBean<Mongo>, InitializingBean, P
|
|||||||
throw new CannotGetMongoDbConnectionException("A replica pair must have two server entries");
|
throw new CannotGetMongoDbConnectionException("A replica pair must have two server entries");
|
||||||
}
|
}
|
||||||
mongo = new Mongo(replicaPair.get(0), replicaPair.get(1), mongoOptions);
|
mongo = new Mongo(replicaPair.get(0), replicaPair.get(1), mongoOptions);
|
||||||
}
|
} else if (replicaSetSeeds != null) {
|
||||||
else if(replicaSetSeeds != null) {
|
|
||||||
mongo = new Mongo(replicaSetSeeds, mongoOptions);
|
mongo = new Mongo(replicaSetSeeds, mongoOptions);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
String mongoHost = host != null ? host : defaultOptions.getHost();
|
String mongoHost = host != null ? host : defaultOptions.getHost();
|
||||||
if (port != null) {
|
if (port != null) {
|
||||||
mongo = new Mongo(new ServerAddress(mongoHost, port), mongoOptions);
|
mongo = new Mongo(new ServerAddress(mongoHost, port), mongoOptions);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
mongo = new Mongo(mongoHost, mongoOptions);
|
mongo = new Mongo(mongoHost, mongoOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,13 @@ package org.springframework.data.document.mongodb;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.data.document.mongodb.query.IndexDefinition;
|
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
|
||||||
import org.springframework.data.document.mongodb.query.Update;
|
|
||||||
|
|
||||||
import com.mongodb.CommandResult;
|
import com.mongodb.CommandResult;
|
||||||
import com.mongodb.DBCollection;
|
import com.mongodb.DBCollection;
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
import com.mongodb.WriteResult;
|
import com.mongodb.WriteResult;
|
||||||
|
import org.springframework.data.document.mongodb.query.IndexDefinition;
|
||||||
|
import org.springframework.data.document.mongodb.query.Query;
|
||||||
|
import org.springframework.data.document.mongodb.query.Update;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface that specifies a basic set of MongoDB operations. Implemented by {@link MongoTemplate}.
|
* Interface that specifies a basic set of MongoDB operations. Implemented by {@link MongoTemplate}.
|
||||||
@@ -40,12 +39,14 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The default collection name used by this template.
|
* The default collection name used by this template.
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getDefaultCollectionName();
|
String getDefaultCollectionName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default collection used by this template.
|
* The default collection used by this template.
|
||||||
|
*
|
||||||
* @return The default collection used by this template
|
* @return The default collection used by this template
|
||||||
*/
|
*/
|
||||||
DBCollection getDefaultCollection();
|
DBCollection getDefaultCollection();
|
||||||
@@ -55,6 +56,7 @@ public interface MongoOperations {
|
|||||||
* JSON.parse that is part of the MongoDB driver to convert the JSON string to a DBObject.
|
* JSON.parse that is part of the MongoDB driver to convert the JSON string to a DBObject.
|
||||||
* Any errors that result from executing this command will be converted into Spring's DAO
|
* Any errors that result from executing this command will be converted into Spring's DAO
|
||||||
* exception hierarchy.
|
* exception hierarchy.
|
||||||
|
*
|
||||||
* @param jsonCommand a MongoDB command expressed as a JSON string.
|
* @param jsonCommand a MongoDB command expressed as a JSON string.
|
||||||
*/
|
*/
|
||||||
CommandResult executeCommand(String jsonCommand);
|
CommandResult executeCommand(String jsonCommand);
|
||||||
@@ -62,25 +64,25 @@ public interface MongoOperations {
|
|||||||
/**
|
/**
|
||||||
* Execute a MongoDB command. Any errors that result from executing this command will be converted
|
* Execute a MongoDB command. Any errors that result from executing this command will be converted
|
||||||
* into Spring's DAO exception hierarchy.
|
* into Spring's DAO exception hierarchy.
|
||||||
|
*
|
||||||
* @param command a MongoDB command
|
* @param command a MongoDB command
|
||||||
*/
|
*/
|
||||||
CommandResult executeCommand(DBObject command);
|
CommandResult executeCommand(DBObject command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a {@link DbCallback} translating any exceptions as necessary.
|
* Executes a {@link DbCallback} translating any exceptions as necessary.
|
||||||
*
|
* <p/>
|
||||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
||||||
*
|
*
|
||||||
* @param <T> return type
|
* @param <T> return type
|
||||||
* @param action callback object that specifies the MongoDB actions to perform on the passed in DB instance.
|
* @param action callback object that specifies the MongoDB actions to perform on the passed in DB instance.
|
||||||
*
|
|
||||||
* @return a result object returned by the action or <tt>null</tt>
|
* @return a result object returned by the action or <tt>null</tt>
|
||||||
*/
|
*/
|
||||||
<T> T execute(DbCallback<T> action);
|
<T> T execute(DbCallback<T> action);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the given {@link CollectionCallback} on the default collection.
|
* Executes the given {@link CollectionCallback} on the default collection.
|
||||||
*
|
* <p/>
|
||||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
||||||
*
|
*
|
||||||
* @param <T> return type
|
* @param <T> return type
|
||||||
@@ -91,7 +93,7 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the given {@link CollectionCallback} on the collection of the given name.
|
* Executes the given {@link CollectionCallback} on the collection of the given name.
|
||||||
*
|
* <p/>
|
||||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
||||||
*
|
*
|
||||||
* @param <T> return type
|
* @param <T> return type
|
||||||
@@ -106,7 +108,7 @@ public interface MongoOperations {
|
|||||||
* Executes the given {@link DbCallback} within the same connection to the database so as to ensure
|
* Executes the given {@link DbCallback} within the same connection to the database so as to ensure
|
||||||
* consistency in a write heavy environment where you may read the data that you wrote. See the
|
* consistency in a write heavy environment where you may read the data that you wrote. See the
|
||||||
* comments on {@see <a href=http://www.mongodb.org/display/DOCS/Java+Driver+Concurrency>Java Driver Concurrency</a>}
|
* comments on {@see <a href=http://www.mongodb.org/display/DOCS/Java+Driver+Concurrency>Java Driver Concurrency</a>}
|
||||||
*
|
* <p/>
|
||||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
||||||
*
|
*
|
||||||
* @param <T> return type
|
* @param <T> return type
|
||||||
@@ -117,6 +119,7 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an uncapped collection with the provided name.
|
* Create an uncapped collection with the provided name.
|
||||||
|
*
|
||||||
* @param collectionName name of the collection
|
* @param collectionName name of the collection
|
||||||
* @return the created collection
|
* @return the created collection
|
||||||
*/
|
*/
|
||||||
@@ -124,6 +127,7 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a collect with the provided name and options.
|
* Create a collect with the provided name and options.
|
||||||
|
*
|
||||||
* @param collectionName name of the collection
|
* @param collectionName name of the collection
|
||||||
* @param collectionOptions options to use when creating the collection.
|
* @param collectionOptions options to use when creating the collection.
|
||||||
* @return the created collection
|
* @return the created collection
|
||||||
@@ -132,13 +136,14 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of collection names.
|
* A set of collection names.
|
||||||
|
*
|
||||||
* @return list of collection names
|
* @return list of collection names
|
||||||
*/
|
*/
|
||||||
Set<String> getCollectionNames();
|
Set<String> getCollectionNames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a collection by name, creating it if it doesn't exist.
|
* Get a collection by name, creating it if it doesn't exist.
|
||||||
*
|
* <p/>
|
||||||
* Translate any exceptions as necessary.
|
* Translate any exceptions as necessary.
|
||||||
*
|
*
|
||||||
* @param collectionName name of the collection
|
* @param collectionName name of the collection
|
||||||
@@ -148,7 +153,7 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check to see if a collection with a given name exists.
|
* Check to see if a collection with a given name exists.
|
||||||
*
|
* <p/>
|
||||||
* Translate any exceptions as necessary.
|
* Translate any exceptions as necessary.
|
||||||
*
|
*
|
||||||
* @param collectionName name of the collection
|
* @param collectionName name of the collection
|
||||||
@@ -158,7 +163,7 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Drop the collection with the given name.
|
* Drop the collection with the given name.
|
||||||
*
|
* <p/>
|
||||||
* Translate any exceptions as necessary.
|
* Translate any exceptions as necessary.
|
||||||
*
|
*
|
||||||
* @param collectionName name of the collection to drop/delete.
|
* @param collectionName name of the collection to drop/delete.
|
||||||
@@ -167,11 +172,11 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Query for a list of objects of type T from the default collection.
|
* Query for a list of objects of type T from the default collection.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient
|
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient
|
||||||
* way to map objects since the test for class type is done in the client and not on the server.
|
* way to map objects since the test for class type is done in the client and not on the server.
|
||||||
*
|
*
|
||||||
@@ -182,13 +187,14 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Query for a list of objects of type T from the specified collection.
|
* Query for a list of objects of type T from the specified collection.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient
|
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient
|
||||||
* way to map objects since the test for class type is done in the client and not on the server.
|
* way to map objects since the test for class type is done in the client and not on the server.
|
||||||
|
*
|
||||||
* @param collectionName name of the collection to retrieve the objects from
|
* @param collectionName name of the collection to retrieve the objects from
|
||||||
* @param targetClass the parameterized type of the returned list.
|
* @param targetClass the parameterized type of the returned list.
|
||||||
* @return the converted collection
|
* @return the converted collection
|
||||||
@@ -227,11 +233,11 @@ public interface MongoOperations {
|
|||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object
|
* Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object
|
||||||
* of the specified type.
|
* of the specified type.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
||||||
* feature rich {@link Query}.
|
* feature rich {@link Query}.
|
||||||
*
|
*
|
||||||
@@ -244,11 +250,11 @@ public interface MongoOperations {
|
|||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object
|
* Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object
|
||||||
* of the specified type.
|
* of the specified type.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
||||||
* feature rich {@link Query}.
|
* feature rich {@link Query}.
|
||||||
*
|
*
|
||||||
@@ -263,11 +269,11 @@ public interface MongoOperations {
|
|||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the specified collection to a single instance of an object
|
* Map the results of an ad-hoc query on the specified collection to a single instance of an object
|
||||||
* of the specified type.
|
* of the specified type.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
||||||
* feature rich {@link Query}.
|
* feature rich {@link Query}.
|
||||||
*
|
*
|
||||||
@@ -282,11 +288,11 @@ public interface MongoOperations {
|
|||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the specified collection to a single instance of an object
|
* Map the results of an ad-hoc query on the specified collection to a single instance of an object
|
||||||
* of the specified type.
|
* of the specified type.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
||||||
* feature rich {@link Query}.
|
* feature rich {@link Query}.
|
||||||
*
|
*
|
||||||
@@ -301,11 +307,11 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.
|
* Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
||||||
* feature rich {@link Query}.
|
* feature rich {@link Query}.
|
||||||
*
|
*
|
||||||
@@ -317,11 +323,11 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.
|
* Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
||||||
* feature rich {@link Query}.
|
* feature rich {@link Query}.
|
||||||
*
|
*
|
||||||
@@ -335,11 +341,11 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the specified collection to a List of the specified type.
|
* Map the results of an ad-hoc query on the specified collection to a List of the specified type.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
||||||
* feature rich {@link Query}.
|
* feature rich {@link Query}.
|
||||||
*
|
*
|
||||||
@@ -353,11 +359,11 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the specified collection to a List of the specified type.
|
* Map the results of an ad-hoc query on the specified collection to a List of the specified type.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
||||||
* feature rich {@link Query}.
|
* feature rich {@link Query}.
|
||||||
*
|
*
|
||||||
@@ -373,11 +379,11 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the specified collection to a List of the specified type.
|
* Map the results of an ad-hoc query on the specified collection to a List of the specified type.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
||||||
* feature rich {@link Query}.
|
* feature rich {@link Query}.
|
||||||
*
|
*
|
||||||
@@ -392,19 +398,19 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert the object into the default collection.
|
* Insert the object into the default collection.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted to the MongoDB native representation using an instance of
|
* The object is converted to the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property
|
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property
|
||||||
* is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from
|
* is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from
|
||||||
* ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's
|
* ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's
|
||||||
* new Type Conversion API.
|
* new Type Conversion API.
|
||||||
* See <a href="http://static.springsource.org/spring/docs/3.0.x/reference/validation.html#core-convert">Spring 3 Type Conversion"</a>
|
* See <a href="http://static.springsource.org/spring/docs/3.0.x/reference/validation.html#core-convert">Spring 3 Type Conversion"</a>
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
* <p/>
|
||||||
*
|
* <p/>
|
||||||
* Insert is used to initially store the object into the database.
|
* Insert is used to initially store the object into the database.
|
||||||
* To update an existing object use the save method.
|
* To update an existing object use the save method.
|
||||||
*
|
*
|
||||||
@@ -414,11 +420,11 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert the object into the specified collection.
|
* Insert the object into the specified collection.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted to the MongoDB native representation using an instance of
|
* The object is converted to the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* Insert is used to initially store the object into the
|
* Insert is used to initially store the object into the
|
||||||
* database. To update an existing object use the save method.
|
* database. To update an existing object use the save method.
|
||||||
*
|
*
|
||||||
@@ -429,10 +435,10 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert the object into the default collection.
|
* Insert the object into the default collection.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted to the MongoDB native representation using an instance of
|
* The object is converted to the MongoDB native representation using an instance of
|
||||||
* {@see MongoWriter}
|
* {@see MongoWriter}
|
||||||
*
|
* <p/>
|
||||||
* Insert is used to initially store the object into the
|
* Insert is used to initially store the object into the
|
||||||
* database. To update an existing object use the save method.
|
* database. To update an existing object use the save method.
|
||||||
*
|
*
|
||||||
@@ -444,10 +450,10 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert the object into the specified collection.
|
* Insert the object into the specified collection.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted to the MongoDB native representation using an instance of
|
* The object is converted to the MongoDB native representation using an instance of
|
||||||
* {@see MongoWriter}
|
* {@see MongoWriter}
|
||||||
*
|
* <p/>
|
||||||
* Insert is used to initially store the object into the
|
* Insert is used to initially store the object into the
|
||||||
* database. To update an existing object use the save method.
|
* database. To update an existing object use the save method.
|
||||||
*
|
*
|
||||||
@@ -467,6 +473,7 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a list of objects into the specified collection in a single batch write to the database.
|
* Insert a list of objects into the specified collection in a single batch write to the database.
|
||||||
|
*
|
||||||
* @param collectionName name of the collection to store the object in
|
* @param collectionName name of the collection to store the object in
|
||||||
* @param listToSave the list of objects to save.
|
* @param listToSave the list of objects to save.
|
||||||
*/
|
*/
|
||||||
@@ -494,11 +501,11 @@ public interface MongoOperations {
|
|||||||
/**
|
/**
|
||||||
* Save the object to the default collection. This will perform an insert if the object is not already
|
* Save the object to the default collection. This will perform an insert if the object is not already
|
||||||
* present, that is an 'upsert'.
|
* present, that is an 'upsert'.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted to the MongoDB native representation using an instance of
|
* The object is converted to the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property
|
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property
|
||||||
* is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from
|
* is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from
|
||||||
* ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's
|
* ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's
|
||||||
@@ -513,11 +520,11 @@ public interface MongoOperations {
|
|||||||
/**
|
/**
|
||||||
* Save the object to the specified collection. This will perform an insert if the object is not already
|
* Save the object to the specified collection. This will perform an insert if the object is not already
|
||||||
* present, that is an 'upsert'.
|
* present, that is an 'upsert'.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted to the MongoDB native representation using an instance of
|
* The object is converted to the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property
|
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property
|
||||||
* is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from
|
* is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from
|
||||||
* ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's
|
* ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's
|
||||||
@@ -534,7 +541,7 @@ public interface MongoOperations {
|
|||||||
* Save the object into the default collection using the provided writer.
|
* Save the object into the default collection using the provided writer.
|
||||||
* This will perform an insert if the object is not already
|
* This will perform an insert if the object is not already
|
||||||
* present, that is an 'upsert'.
|
* present, that is an 'upsert'.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted to the MongoDB native representation using an instance of
|
* The object is converted to the MongoDB native representation using an instance of
|
||||||
* {@see MongoWriter}
|
* {@see MongoWriter}
|
||||||
*
|
*
|
||||||
@@ -548,7 +555,7 @@ public interface MongoOperations {
|
|||||||
* Save the object into the specified collection using the provided writer.
|
* Save the object into the specified collection using the provided writer.
|
||||||
* This will perform an insert if the object is not already
|
* This will perform an insert if the object is not already
|
||||||
* present, that is an 'upsert'.
|
* present, that is an 'upsert'.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted to the MongoDB native representation using an instance of
|
* The object is converted to the MongoDB native representation using an instance of
|
||||||
* {@see MongoWriter}
|
* {@see MongoWriter}
|
||||||
*
|
*
|
||||||
@@ -605,12 +612,14 @@ public interface MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all documents from the default collection that match the provided query document criteria.
|
* Remove all documents from the default collection that match the provided query document criteria.
|
||||||
|
*
|
||||||
* @param queryDoc the query document that specifies the criteria used to remove a record
|
* @param queryDoc the query document that specifies the criteria used to remove a record
|
||||||
*/
|
*/
|
||||||
void remove(Query query);
|
void remove(Query query);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all documents from the specified collection that match the provided query document criteria.
|
* Remove all documents from the specified collection that match the provided query document criteria.
|
||||||
|
*
|
||||||
* @param collectionName name of the collection where the objects will removed
|
* @param collectionName name of the collection where the objects will removed
|
||||||
* @param queryDoc the query document that specifies the criteria used to remove a record
|
* @param queryDoc the query document that specifies the criteria used to remove a record
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,32 +15,29 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb;
|
package org.springframework.data.document.mongodb;
|
||||||
|
|
||||||
|
import com.mongodb.MongoOptions;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
|
|
||||||
import com.mongodb.MongoOptions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A factory bean for consruction a MongoOptions instance
|
* A factory bean for consruction a MongoOptions instance
|
||||||
*
|
*
|
||||||
* @author Graeme Rocher
|
* @author Graeme Rocher
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class MongoOptionsFactoryBean implements FactoryBean<MongoOptions>, InitializingBean {
|
public class MongoOptionsFactoryBean implements FactoryBean<MongoOptions>, InitializingBean {
|
||||||
|
|
||||||
private static final MongoOptions MONGO_OPTIONS = new MongoOptions();
|
private static final MongoOptions MONGO_OPTIONS = new MongoOptions();
|
||||||
/**
|
/**
|
||||||
number of connections allowed per host
|
* number of connections allowed per host
|
||||||
will block if run out
|
* will block if run out
|
||||||
*/
|
*/
|
||||||
private int connectionsPerHost = MONGO_OPTIONS.connectionsPerHost;
|
private int connectionsPerHost = MONGO_OPTIONS.connectionsPerHost;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
multiplier for connectionsPerHost for # of threads that can block
|
* multiplier for connectionsPerHost for # of threads that can block
|
||||||
if connectionsPerHost is 10, and threadsAllowedToBlockForConnectionMultiplier is 5,
|
* if connectionsPerHost is 10, and threadsAllowedToBlockForConnectionMultiplier is 5,
|
||||||
then 50 threads can block
|
* then 50 threads can block
|
||||||
more than that and an exception will be throw
|
* more than that and an exception will be throw
|
||||||
*/
|
*/
|
||||||
private int threadsAllowedToBlockForConnectionMultiplier = MONGO_OPTIONS.threadsAllowedToBlockForConnectionMultiplier;
|
private int threadsAllowedToBlockForConnectionMultiplier = MONGO_OPTIONS.threadsAllowedToBlockForConnectionMultiplier;
|
||||||
|
|
||||||
@@ -50,34 +47,34 @@ public class MongoOptionsFactoryBean implements FactoryBean<MongoOptions>, Initi
|
|||||||
private int maxWaitTime = MONGO_OPTIONS.maxWaitTime;
|
private int maxWaitTime = MONGO_OPTIONS.maxWaitTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
connect timeout in milliseconds. 0 is default and infinite
|
* connect timeout in milliseconds. 0 is default and infinite
|
||||||
*/
|
*/
|
||||||
private int connectTimeout = MONGO_OPTIONS.connectTimeout;
|
private int connectTimeout = MONGO_OPTIONS.connectTimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
socket timeout. 0 is default and infinite
|
* socket timeout. 0 is default and infinite
|
||||||
*/
|
*/
|
||||||
private int socketTimeout = MONGO_OPTIONS.socketTimeout;
|
private int socketTimeout = MONGO_OPTIONS.socketTimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
this controls whether or not on a connect, the system retries automatically
|
* this controls whether or not on a connect, the system retries automatically
|
||||||
*/
|
*/
|
||||||
private boolean autoConnectRetry = MONGO_OPTIONS.autoConnectRetry;
|
private boolean autoConnectRetry = MONGO_OPTIONS.autoConnectRetry;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
number of connections allowed per host
|
* number of connections allowed per host
|
||||||
will block if run out
|
* will block if run out
|
||||||
*/
|
*/
|
||||||
public void setConnectionsPerHost(int connectionsPerHost) {
|
public void setConnectionsPerHost(int connectionsPerHost) {
|
||||||
this.connectionsPerHost = connectionsPerHost;
|
this.connectionsPerHost = connectionsPerHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
multiplier for connectionsPerHost for # of threads that can block
|
* multiplier for connectionsPerHost for # of threads that can block
|
||||||
if connectionsPerHost is 10, and threadsAllowedToBlockForConnectionMultiplier is 5,
|
* if connectionsPerHost is 10, and threadsAllowedToBlockForConnectionMultiplier is 5,
|
||||||
then 50 threads can block
|
* then 50 threads can block
|
||||||
more than that and an exception will be throw
|
* more than that and an exception will be throw
|
||||||
*/
|
*/
|
||||||
public void setThreadsAllowedToBlockForConnectionMultiplier(
|
public void setThreadsAllowedToBlockForConnectionMultiplier(
|
||||||
int threadsAllowedToBlockForConnectionMultiplier) {
|
int threadsAllowedToBlockForConnectionMultiplier) {
|
||||||
@@ -92,21 +89,21 @@ public class MongoOptionsFactoryBean implements FactoryBean<MongoOptions>, Initi
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
connect timeout in milliseconds. 0 is default and infinite
|
* connect timeout in milliseconds. 0 is default and infinite
|
||||||
*/
|
*/
|
||||||
public void setConnectTimeout(int connectTimeout) {
|
public void setConnectTimeout(int connectTimeout) {
|
||||||
this.connectTimeout = connectTimeout;
|
this.connectTimeout = connectTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
socket timeout. 0 is default and infinite
|
* socket timeout. 0 is default and infinite
|
||||||
*/
|
*/
|
||||||
public void setSocketTimeout(int socketTimeout) {
|
public void setSocketTimeout(int socketTimeout) {
|
||||||
this.socketTimeout = socketTimeout;
|
this.socketTimeout = socketTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
this controls whether or not on a connect, the system retries automatically
|
* this controls whether or not on a connect, the system retries automatically
|
||||||
*/
|
*/
|
||||||
public void setAutoConnectRetry(boolean autoConnectRetry) {
|
public void setAutoConnectRetry(boolean autoConnectRetry) {
|
||||||
this.autoConnectRetry = autoConnectRetry;
|
this.autoConnectRetry = autoConnectRetry;
|
||||||
|
|||||||
@@ -15,16 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb;
|
package org.springframework.data.document.mongodb;
|
||||||
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An iterable of {@link MongoPropertyDescriptor}s that allows dedicated access to the {@link MongoPropertyDescriptor}
|
* An iterable of {@link MongoPropertyDescriptor}s that allows dedicated access to the {@link MongoPropertyDescriptor}
|
||||||
* that captures the id-property.
|
* that captures the id-property.
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.mongodb.*;
|
||||||
|
import com.mongodb.util.JSON;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
@@ -33,28 +35,14 @@ import org.springframework.core.convert.ConversionFailedException;
|
|||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.data.document.mongodb.MongoPropertyDescriptors.MongoPropertyDescriptor;
|
import org.springframework.data.document.mongodb.MongoPropertyDescriptors.MongoPropertyDescriptor;
|
||||||
import org.springframework.data.document.mongodb.convert.MappingMongoConverter;
|
import org.springframework.data.document.mongodb.convert.MongoConverter;
|
||||||
|
import org.springframework.data.document.mongodb.convert.SimpleMongoConverter;
|
||||||
import org.springframework.data.document.mongodb.query.IndexDefinition;
|
import org.springframework.data.document.mongodb.query.IndexDefinition;
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
import org.springframework.data.document.mongodb.query.Query;
|
||||||
import org.springframework.data.document.mongodb.query.Update;
|
import org.springframework.data.document.mongodb.query.Update;
|
||||||
import org.springframework.data.document.mongodb.convert.MongoConverter;
|
|
||||||
import org.springframework.data.document.mongodb.convert.SimpleMongoConverter;
|
|
||||||
import org.springframework.data.mapping.model.MappingConfigurationBuilder;
|
|
||||||
import org.springframework.jca.cci.core.ConnectionCallback;
|
import org.springframework.jca.cci.core.ConnectionCallback;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.CommandResult;
|
|
||||||
import com.mongodb.DB;
|
|
||||||
import com.mongodb.DBCollection;
|
|
||||||
import com.mongodb.DBCursor;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
import com.mongodb.MongoException;
|
|
||||||
import com.mongodb.WriteConcern;
|
|
||||||
import com.mongodb.WriteResult;
|
|
||||||
import com.mongodb.util.JSON;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary implementation of {@link MongoOperations}.
|
* Primary implementation of {@link MongoOperations}.
|
||||||
*
|
*
|
||||||
@@ -93,6 +81,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor used for a basic template configuration
|
* Constructor used for a basic template configuration
|
||||||
|
*
|
||||||
* @param mongo
|
* @param mongo
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
*/
|
*/
|
||||||
@@ -103,6 +92,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
/**
|
/**
|
||||||
* Constructor used for a basic template configuration with a specific {@link com.mongodb.WriteConcern}
|
* Constructor used for a basic template configuration with a specific {@link com.mongodb.WriteConcern}
|
||||||
* to be used for all database write operations
|
* to be used for all database write operations
|
||||||
|
*
|
||||||
* @param mongo
|
* @param mongo
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
* @param writeConcern
|
* @param writeConcern
|
||||||
@@ -113,6 +103,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor used for a basic template configuration with a default collection name
|
* Constructor used for a basic template configuration with a default collection name
|
||||||
|
*
|
||||||
* @param mongo
|
* @param mongo
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
* @param defaultCollectionName
|
* @param defaultCollectionName
|
||||||
@@ -124,6 +115,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
/**
|
/**
|
||||||
* Constructor used for a basic template configuration with a default collection name and
|
* Constructor used for a basic template configuration with a default collection name and
|
||||||
* with a specific {@link com.mongodb.WriteConcern} to be used for all database write operations
|
* with a specific {@link com.mongodb.WriteConcern} to be used for all database write operations
|
||||||
|
*
|
||||||
* @param mongo
|
* @param mongo
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
* @param defaultCollectionName
|
* @param defaultCollectionName
|
||||||
@@ -135,6 +127,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor used for a template configuration with a default collection name and a custom {@link org.springframework.data.document.mongodb.convert.MongoConverter}
|
* Constructor used for a template configuration with a default collection name and a custom {@link org.springframework.data.document.mongodb.convert.MongoConverter}
|
||||||
|
*
|
||||||
* @param mongo
|
* @param mongo
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
* @param defaultCollectionName
|
* @param defaultCollectionName
|
||||||
@@ -147,6 +140,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
/**
|
/**
|
||||||
* Constructor used for a template configuration with a default collection name and a custom {@link MongoConverter}
|
* Constructor used for a template configuration with a default collection name and a custom {@link MongoConverter}
|
||||||
* and with a specific {@link com.mongodb.WriteConcern} to be used for all database write operations
|
* and with a specific {@link com.mongodb.WriteConcern} to be used for all database write operations
|
||||||
|
*
|
||||||
* @param mongo
|
* @param mongo
|
||||||
* @param databaseName
|
* @param databaseName
|
||||||
* @param defaultCollectionName
|
* @param defaultCollectionName
|
||||||
@@ -440,8 +434,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
DBObject indexOptions = indexDefinition.getIndexOptions();
|
DBObject indexOptions = indexDefinition.getIndexOptions();
|
||||||
if (indexOptions != null) {
|
if (indexOptions != null) {
|
||||||
collection.ensureIndex(indexDefinition.getIndexObject(), indexOptions);
|
collection.ensureIndex(indexDefinition.getIndexObject(), indexOptions);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
collection.ensureIndex(indexDefinition.getIndexObject());
|
collection.ensureIndex(indexDefinition.getIndexObject());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -631,8 +624,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
public Object doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
public Object doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
||||||
if (writeConcern == null) {
|
if (writeConcern == null) {
|
||||||
collection.insert(dbDoc);
|
collection.insert(dbDoc);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
collection.insert(dbDoc, writeConcern);
|
collection.insert(dbDoc, writeConcern);
|
||||||
}
|
}
|
||||||
return dbDoc.get(ID);
|
return dbDoc.get(ID);
|
||||||
@@ -650,8 +642,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
public Void doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
public Void doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
||||||
if (writeConcern == null) {
|
if (writeConcern == null) {
|
||||||
collection.insert(dbDocList);
|
collection.insert(dbDocList);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
collection.insert(dbDocList.toArray((DBObject[]) new BasicDBObject[dbDocList.size()]), writeConcern);
|
collection.insert(dbDocList.toArray((DBObject[]) new BasicDBObject[dbDocList.size()]), writeConcern);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -663,8 +654,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
Object id = dbo.get(ID);
|
Object id = dbo.get(ID);
|
||||||
if (id instanceof ObjectId) {
|
if (id instanceof ObjectId) {
|
||||||
ids.add((ObjectId) id);
|
ids.add((ObjectId) id);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// no id was generated
|
// no id was generated
|
||||||
ids.add(null);
|
ids.add(null);
|
||||||
}
|
}
|
||||||
@@ -682,8 +672,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
public ObjectId doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
public ObjectId doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
||||||
if (writeConcern == null) {
|
if (writeConcern == null) {
|
||||||
collection.save(dbDoc);
|
collection.save(dbDoc);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
collection.save(dbDoc, writeConcern);
|
collection.save(dbDoc, writeConcern);
|
||||||
}
|
}
|
||||||
return (ObjectId) dbDoc.get(ID);
|
return (ObjectId) dbDoc.get(ID);
|
||||||
@@ -707,8 +696,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
WriteResult wr;
|
WriteResult wr;
|
||||||
if (writeConcern == null) {
|
if (writeConcern == null) {
|
||||||
wr = collection.update(query.getQueryObject(), update.getUpdateObject());
|
wr = collection.update(query.getQueryObject(), update.getUpdateObject());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
wr = collection.update(query.getQueryObject(), update.getUpdateObject(), false, false, writeConcern);
|
wr = collection.update(query.getQueryObject(), update.getUpdateObject(), false, false, writeConcern);
|
||||||
}
|
}
|
||||||
handleAnyWriteResultErrors(wr, query.getQueryObject(), "update with '" + update.getUpdateObject() + "'");
|
handleAnyWriteResultErrors(wr, query.getQueryObject(), "update with '" + update.getUpdateObject() + "'");
|
||||||
@@ -733,8 +721,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
WriteResult wr = null;
|
WriteResult wr = null;
|
||||||
if (writeConcern == null) {
|
if (writeConcern == null) {
|
||||||
wr = collection.updateMulti(query.getQueryObject(), update.getUpdateObject());
|
wr = collection.updateMulti(query.getQueryObject(), update.getUpdateObject());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
wr = collection.update(query.getQueryObject(), update.getUpdateObject(), false, true, writeConcern);
|
wr = collection.update(query.getQueryObject(), update.getUpdateObject(), false, true, writeConcern);
|
||||||
}
|
}
|
||||||
handleAnyWriteResultErrors(wr, query.getQueryObject(), "update with '" + update.getUpdateObject() + "'");
|
handleAnyWriteResultErrors(wr, query.getQueryObject(), "update with '" + update.getUpdateObject() + "'");
|
||||||
@@ -759,8 +746,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
WriteResult wr = null;
|
WriteResult wr = null;
|
||||||
if (writeConcern == null) {
|
if (writeConcern == null) {
|
||||||
wr = collection.remove(query.getQueryObject());
|
wr = collection.remove(query.getQueryObject());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
wr = collection.remove(query.getQueryObject(), writeConcern);
|
wr = collection.remove(query.getQueryObject(), writeConcern);
|
||||||
}
|
}
|
||||||
handleAnyWriteResultErrors(wr, query.getQueryObject(), "remove");
|
handleAnyWriteResultErrors(wr, query.getQueryObject(), "remove");
|
||||||
@@ -802,6 +788,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the specified collection using the provided options
|
* Create the specified collection using the provided options
|
||||||
|
*
|
||||||
* @param collectionName
|
* @param collectionName
|
||||||
* @param collectionOptions
|
* @param collectionOptions
|
||||||
* @return the collection that was created
|
* @return the collection that was created
|
||||||
@@ -816,7 +803,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the default MongoDB collection to an object using the provided MongoReader
|
* Map the results of an ad-hoc query on the default MongoDB collection to an object using the provided MongoReader
|
||||||
*
|
* <p/>
|
||||||
* The query document is specified as a standard DBObject and so is the fields specification.
|
* The query document is specified as a standard DBObject and so is the fields specification.
|
||||||
*
|
*
|
||||||
* @param collectionName name of the collection to retrieve the objects from
|
* @param collectionName name of the collection to retrieve the objects from
|
||||||
@@ -838,13 +825,13 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.
|
* Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.
|
||||||
*
|
* <p/>
|
||||||
* The object is converted from the MongoDB native representation using an instance of
|
* The object is converted from the MongoDB native representation using an instance of
|
||||||
* {@see MongoConverter}. Unless configured otherwise, an
|
* {@see MongoConverter}. Unless configured otherwise, an
|
||||||
* instance of SimpleMongoConverter will be used.
|
* instance of SimpleMongoConverter will be used.
|
||||||
*
|
* <p/>
|
||||||
* The query document is specified as a standard DBObject and so is the fields specification.
|
* The query document is specified as a standard DBObject and so is the fields specification.
|
||||||
*
|
* <p/>
|
||||||
* Can be overridden by subclasses.
|
* Can be overridden by subclasses.
|
||||||
*
|
*
|
||||||
* @param collectionName name of the collection to retrieve the objects from
|
* @param collectionName name of the collection to retrieve the objects from
|
||||||
@@ -863,7 +850,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the default MongoDB collection to a List using the provided MongoReader
|
* Map the results of an ad-hoc query on the default MongoDB collection to a List using the provided MongoReader
|
||||||
*
|
* <p/>
|
||||||
* The query document is specified as a standard DBObject and so is the fields specification.
|
* The query document is specified as a standard DBObject and so is the fields specification.
|
||||||
*
|
*
|
||||||
* @param collectionName name of the collection to retrieve the objects from
|
* @param collectionName name of the collection to retrieve the objects from
|
||||||
@@ -918,8 +905,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
Object target = null;
|
Object target = null;
|
||||||
if (id instanceof ObjectId) {
|
if (id instanceof ObjectId) {
|
||||||
target = this.mongoConverter.convertObjectId((ObjectId) id, idDescriptor.getPropertyType());
|
target = this.mongoConverter.convertObjectId((ObjectId) id, idDescriptor.getPropertyType());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
target = id;
|
target = id;
|
||||||
}
|
}
|
||||||
bw.setPropertyValue(idDescriptor.getName(), target);
|
bw.setPropertyValue(idDescriptor.getName(), target);
|
||||||
@@ -939,8 +925,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
MongoConverter converter = null;
|
MongoConverter converter = null;
|
||||||
if (reader instanceof SimpleMongoConverter) {
|
if (reader instanceof SimpleMongoConverter) {
|
||||||
converter = (MongoConverter) reader;
|
converter = (MongoConverter) reader;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String idKey = null;
|
String idKey = null;
|
||||||
@@ -974,8 +959,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
query.removeField(idKey);
|
query.removeField(idKey);
|
||||||
if (newValue != null) {
|
if (newValue != null) {
|
||||||
query.put(MongoPropertyDescriptor.ID_KEY, newValue);
|
query.put(MongoPropertyDescriptor.ID_KEY, newValue);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
query.put(MongoPropertyDescriptor.ID_KEY, value);
|
query.put(MongoPropertyDescriptor.ID_KEY, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -993,10 +977,9 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks and handles any errors.
|
* Checks and handles any errors.
|
||||||
*
|
* <p/>
|
||||||
* TODO: current implementation logs errors - will be configurable to log warning, errors or
|
* TODO: current implementation logs errors - will be configurable to log warning, errors or
|
||||||
* throw exception in later versions
|
* throw exception in later versions
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private void handleAnyWriteResultErrors(WriteResult wr, DBObject query, String operation) {
|
private void handleAnyWriteResultErrors(WriteResult wr, DBObject query, String operation) {
|
||||||
if (WriteResultChecking.NONE == this.writeResultChecking) {
|
if (WriteResultChecking.NONE == this.writeResultChecking) {
|
||||||
@@ -1009,18 +992,15 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
(query == null ? "" : "' using '" + query.toString() + "' query") + " failed: " + error;
|
(query == null ? "" : "' using '" + query.toString() + "' query") + " failed: " + error;
|
||||||
if (WriteResultChecking.EXCEPTION == this.writeResultChecking) {
|
if (WriteResultChecking.EXCEPTION == this.writeResultChecking) {
|
||||||
throw new DataIntegrityViolationException(message);
|
throw new DataIntegrityViolationException(message);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
LOGGER.error(message);
|
LOGGER.error(message);
|
||||||
}
|
}
|
||||||
}
|
} else if (n == 0) {
|
||||||
else if(n == 0) {
|
|
||||||
String message = "Execution of '" + operation +
|
String message = "Execution of '" + operation +
|
||||||
(query == null ? "" : "' using '" + query.toString() + "' query") + " did not succeed: 0 documents updated";
|
(query == null ? "" : "' using '" + query.toString() + "' query") + " did not succeed: 0 documents updated";
|
||||||
if (WriteResultChecking.EXCEPTION == this.writeResultChecking) {
|
if (WriteResultChecking.EXCEPTION == this.writeResultChecking) {
|
||||||
throw new DataIntegrityViolationException(message);
|
throw new DataIntegrityViolationException(message);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
LOGGER.warn(message);
|
LOGGER.warn(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1073,8 +1053,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
public DBObject doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
public DBObject doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
||||||
if (fields == null) {
|
if (fields == null) {
|
||||||
return collection.findOne(query);
|
return collection.findOne(query);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return collection.findOne(query, fields);
|
return collection.findOne(query, fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1105,8 +1084,7 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
public DBCursor doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
public DBCursor doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
||||||
if (fields == null) {
|
if (fields == null) {
|
||||||
return collection.find(query);
|
return collection.find(query);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return collection.find(query, fields);
|
return collection.find(query, fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,15 +20,15 @@ import com.mongodb.DBObject;
|
|||||||
/**
|
/**
|
||||||
* A MongoWriter is responsible for converting an object of type T to the native MongoDB representation DBObject.
|
* A MongoWriter is responsible for converting an object of type T to the native MongoDB representation DBObject.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the object to convert to a DBObject
|
||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
*
|
|
||||||
* @param <T> the type of the object to convert to a DBObject
|
|
||||||
*/
|
*/
|
||||||
public interface MongoWriter<T> {
|
public interface MongoWriter<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the given object of type T to the native MongoDB object representation DBObject.
|
* Write the given object of type T to the native MongoDB object representation DBObject.
|
||||||
|
*
|
||||||
* @param t The object to convert to a DBObject
|
* @param t The object to convert to a DBObject
|
||||||
* @param dbo The DBObject to use for writing.
|
* @param dbo The DBObject to use for writing.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,14 +22,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
|||||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
import org.springframework.beans.factory.xml.ParserContext;
|
||||||
import org.springframework.data.document.mongodb.MongoAdmin;
|
import org.springframework.data.document.mongodb.MongoAdmin;
|
||||||
import org.springframework.data.document.mongodb.monitor.AssertMetrics;
|
import org.springframework.data.document.mongodb.monitor.*;
|
||||||
import org.springframework.data.document.mongodb.monitor.BackgroundFlushingMetrics;
|
|
||||||
import org.springframework.data.document.mongodb.monitor.BtreeIndexCounters;
|
|
||||||
import org.springframework.data.document.mongodb.monitor.ConnectionMetrics;
|
|
||||||
import org.springframework.data.document.mongodb.monitor.GlobalLockMetrics;
|
|
||||||
import org.springframework.data.document.mongodb.monitor.MemoryMetrics;
|
|
||||||
import org.springframework.data.document.mongodb.monitor.OperationCounters;
|
|
||||||
import org.springframework.data.document.mongodb.monitor.ServerInfo;
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,11 @@
|
|||||||
|
|
||||||
package org.springframework.data.document.mongodb.convert;
|
package org.springframework.data.document.mongodb.convert;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import com.mongodb.BasicDBList;
|
import com.mongodb.BasicDBList;
|
||||||
import com.mongodb.BasicDBObject;
|
import com.mongodb.BasicDBObject;
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
@@ -40,15 +45,9 @@ import org.springframework.expression.Expression;
|
|||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unchecked"})
|
|
||||||
public class MappingMongoConverter implements MongoConverter, ApplicationContextAware {
|
public class MappingMongoConverter implements MongoConverter, ApplicationContextAware {
|
||||||
|
|
||||||
private static final String CUSTOM_TYPE_KEY = "_class";
|
private static final String CUSTOM_TYPE_KEY = "_class";
|
||||||
@@ -112,6 +111,7 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
|||||||
return conversionService.convert(id, ObjectId.class);
|
return conversionService.convert(id, ObjectId.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked"})
|
||||||
public <S extends Object> S read(Class<S> clazz, final DBObject dbo) {
|
public <S extends Object> S read(Class<S> clazz, final DBObject dbo) {
|
||||||
if (null == dbo) {
|
if (null == dbo) {
|
||||||
return null;
|
return null;
|
||||||
@@ -358,6 +358,7 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked"})
|
||||||
protected void writePropertyInternal(PersistentProperty prop, Object obj, DBObject dbo) {
|
protected void writePropertyInternal(PersistentProperty prop, Object obj, DBObject dbo) {
|
||||||
org.springframework.data.document.mongodb.mapping.DBRef dbref = prop.getField()
|
org.springframework.data.document.mongodb.mapping.DBRef dbref = prop.getField()
|
||||||
.getAnnotation(org.springframework.data.document.mongodb.mapping.DBRef.class);
|
.getAnnotation(org.springframework.data.document.mongodb.mapping.DBRef.class);
|
||||||
@@ -457,6 +458,7 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
|||||||
return dbo;
|
return dbo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked"})
|
||||||
protected Object getValueInternal(PersistentProperty prop, DBObject dbo, StandardEvaluationContext ctx, Value spelExpr) {
|
protected Object getValueInternal(PersistentProperty prop, DBObject dbo, StandardEvaluationContext ctx, Value spelExpr) {
|
||||||
String name = prop.getName();
|
String name = prop.getName();
|
||||||
Object o;
|
Object o;
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.convert;
|
package org.springframework.data.document.mongodb.convert;
|
||||||
|
|
||||||
import static org.springframework.beans.PropertyAccessorFactory.*;
|
import static org.springframework.beans.PropertyAccessorFactory.forBeanPropertyAccess;
|
||||||
|
import static org.springframework.beans.PropertyAccessorFactory.forDirectFieldAccess;
|
||||||
|
|
||||||
import org.springframework.beans.BeanWrapper;
|
import org.springframework.beans.BeanWrapper;
|
||||||
import org.springframework.beans.ConfigurablePropertyAccessor;
|
import org.springframework.beans.ConfigurablePropertyAccessor;
|
||||||
|
|||||||
@@ -15,6 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.convert;
|
package org.springframework.data.document.mongodb.convert;
|
||||||
|
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.mongodb.BasicDBList;
|
import com.mongodb.BasicDBList;
|
||||||
import com.mongodb.BasicDBObject;
|
import com.mongodb.BasicDBObject;
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
@@ -34,12 +40,6 @@ import org.springframework.data.document.mongodb.MongoPropertyDescriptors.MongoP
|
|||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.comparator.CompoundComparator;
|
import org.springframework.util.comparator.CompoundComparator;
|
||||||
|
|
||||||
import java.lang.reflect.*;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic {@link MongoConverter} implementation to convert between domain classes and {@link DBObject}s.
|
* Basic {@link MongoConverter} implementation to convert between domain classes and {@link DBObject}s.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -16,13 +16,13 @@
|
|||||||
|
|
||||||
package org.springframework.data.document.mongodb.mapping;
|
package org.springframework.data.document.mongodb.mapping;
|
||||||
|
|
||||||
import org.springframework.data.annotation.Reference;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import org.springframework.data.annotation.Reference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,6 +16,12 @@
|
|||||||
|
|
||||||
package org.springframework.data.document.mongodb.mapping;
|
package org.springframework.data.document.mongodb.mapping;
|
||||||
|
|
||||||
|
import java.beans.PropertyDescriptor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
import com.mongodb.BasicDBObject;
|
||||||
import com.mongodb.DBCollection;
|
import com.mongodb.DBCollection;
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
@@ -35,12 +41,6 @@ import org.springframework.data.mapping.MappingBeanHelper;
|
|||||||
import org.springframework.data.mapping.model.*;
|
import org.springframework.data.mapping.model.*;
|
||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
|
|
||||||
import java.beans.PropertyDescriptor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,20 +15,18 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.monitor;
|
package org.springframework.data.document.mongodb.monitor;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.data.document.mongodb.MongoDbUtils;
|
|
||||||
|
|
||||||
import com.mongodb.CommandResult;
|
import com.mongodb.CommandResult;
|
||||||
import com.mongodb.DB;
|
import com.mongodb.DB;
|
||||||
import com.mongodb.Mongo;
|
import com.mongodb.Mongo;
|
||||||
import com.mongodb.MongoException;
|
import com.mongodb.MongoException;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.springframework.data.document.mongodb.MongoDbUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class to encapsulate common configuration settings when connecting to a database
|
* Base class to encapsulate common configuration settings when connecting to a database
|
||||||
*
|
*
|
||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractMonitor {
|
public abstract class AbstractMonitor {
|
||||||
|
|
||||||
|
|||||||
@@ -15,18 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.monitor;
|
package org.springframework.data.document.mongodb.monitor;
|
||||||
|
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import com.mongodb.Mongo;
|
||||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||||
import org.springframework.jmx.support.MetricType;
|
import org.springframework.jmx.support.MetricType;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JMX Metrics for assertions
|
* JMX Metrics for assertions
|
||||||
*
|
*
|
||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@ManagedResource(description = "Assertion Metrics")
|
@ManagedResource(description = "Assertion Metrics")
|
||||||
public class AssertMetrics extends AbstractMonitor {
|
public class AssertMetrics extends AbstractMonitor {
|
||||||
|
|||||||
@@ -17,18 +17,16 @@ package org.springframework.data.document.mongodb.monitor;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import com.mongodb.Mongo;
|
||||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||||
import org.springframework.jmx.support.MetricType;
|
import org.springframework.jmx.support.MetricType;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JMX Metrics for Background Flushing
|
* JMX Metrics for Background Flushing
|
||||||
*
|
*
|
||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@ManagedResource(description = "Background Flushing Metrics")
|
@ManagedResource(description = "Background Flushing Metrics")
|
||||||
public class BackgroundFlushingMetrics extends AbstractMonitor {
|
public class BackgroundFlushingMetrics extends AbstractMonitor {
|
||||||
|
|||||||
@@ -15,18 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.monitor;
|
package org.springframework.data.document.mongodb.monitor;
|
||||||
|
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import com.mongodb.Mongo;
|
||||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||||
import org.springframework.jmx.support.MetricType;
|
import org.springframework.jmx.support.MetricType;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JMX Metrics for B-tree index counters
|
* JMX Metrics for B-tree index counters
|
||||||
*
|
*
|
||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@ManagedResource(description = "Btree Metrics")
|
@ManagedResource(description = "Btree Metrics")
|
||||||
public class BtreeIndexCounters extends AbstractMonitor {
|
public class BtreeIndexCounters extends AbstractMonitor {
|
||||||
|
|||||||
@@ -15,18 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.monitor;
|
package org.springframework.data.document.mongodb.monitor;
|
||||||
|
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import com.mongodb.Mongo;
|
||||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||||
import org.springframework.jmx.support.MetricType;
|
import org.springframework.jmx.support.MetricType;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JMX Metrics for Connections
|
* JMX Metrics for Connections
|
||||||
*
|
*
|
||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@ManagedResource(description = "Connection metrics")
|
@ManagedResource(description = "Connection metrics")
|
||||||
public class ConnectionMetrics extends AbstractMonitor {
|
public class ConnectionMetrics extends AbstractMonitor {
|
||||||
|
|||||||
@@ -15,17 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.monitor;
|
package org.springframework.data.document.mongodb.monitor;
|
||||||
|
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import com.mongodb.Mongo;
|
||||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||||
import org.springframework.jmx.support.MetricType;
|
import org.springframework.jmx.support.MetricType;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JMX Metrics for Global Locks
|
* JMX Metrics for Global Locks
|
||||||
* @author Mark Pollack
|
|
||||||
*
|
*
|
||||||
|
* @author Mark Pollack
|
||||||
*/
|
*/
|
||||||
@ManagedResource(description = "Global Lock Metrics")
|
@ManagedResource(description = "Global Lock Metrics")
|
||||||
public class GlobalLockMetrics extends AbstractMonitor {
|
public class GlobalLockMetrics extends AbstractMonitor {
|
||||||
|
|||||||
@@ -15,17 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.monitor;
|
package org.springframework.data.document.mongodb.monitor;
|
||||||
|
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import com.mongodb.Mongo;
|
||||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||||
import org.springframework.jmx.support.MetricType;
|
import org.springframework.jmx.support.MetricType;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JMX Metrics for Memory
|
* JMX Metrics for Memory
|
||||||
* @author Mark Pollack
|
|
||||||
*
|
*
|
||||||
|
* @author Mark Pollack
|
||||||
*/
|
*/
|
||||||
@ManagedResource(description = "Memory Metrics")
|
@ManagedResource(description = "Memory Metrics")
|
||||||
public class MemoryMetrics extends AbstractMonitor {
|
public class MemoryMetrics extends AbstractMonitor {
|
||||||
|
|||||||
@@ -15,17 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.monitor;
|
package org.springframework.data.document.mongodb.monitor;
|
||||||
|
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import com.mongodb.Mongo;
|
||||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||||
import org.springframework.jmx.support.MetricType;
|
import org.springframework.jmx.support.MetricType;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JMX Metrics for Operation counters
|
* JMX Metrics for Operation counters
|
||||||
* @author Mark Pollack
|
|
||||||
*
|
*
|
||||||
|
* @author Mark Pollack
|
||||||
*/
|
*/
|
||||||
@ManagedResource(description = "Operation Counters")
|
@ManagedResource(description = "Operation Counters")
|
||||||
public class OperationCounters extends AbstractMonitor {
|
public class OperationCounters extends AbstractMonitor {
|
||||||
|
|||||||
@@ -18,18 +18,16 @@ package org.springframework.data.document.mongodb.monitor;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
import com.mongodb.Mongo;
|
||||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||||
import org.springframework.jmx.support.MetricType;
|
import org.springframework.jmx.support.MetricType;
|
||||||
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expose basic server information via JMX
|
* Expose basic server information via JMX
|
||||||
*
|
*
|
||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@ManagedResource(description = "Server Information")
|
@ManagedResource(description = "Server Information")
|
||||||
public class ServerInfo extends AbstractMonitor {
|
public class ServerInfo extends AbstractMonitor {
|
||||||
@@ -45,8 +43,7 @@ public class ServerInfo extends AbstractMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ManagedMetric(displayName = "Uptime Estimate")
|
@ManagedMetric(displayName = "Uptime Estimate")
|
||||||
public double getUptimeEstimate()
|
public double getUptimeEstimate() {
|
||||||
{
|
|
||||||
return (Double) getServerStatus().get("uptimeEstimate");
|
return (Double) getServerStatus().get("uptimeEstimate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.data.document.InvalidDocumentStoreApiUsageException;
|
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
import com.mongodb.BasicDBObject;
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
|
import org.springframework.data.document.InvalidDocumentStoreApiUsageException;
|
||||||
|
|
||||||
public class Criteria implements CriteriaDefinition {
|
public class Criteria implements CriteriaDefinition {
|
||||||
|
|
||||||
@@ -108,6 +107,7 @@ public class Criteria implements CriteriaDefinition {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a criterion using the $in operator
|
* Creates a criterion using the $in operator
|
||||||
|
*
|
||||||
* @param o
|
* @param o
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -232,12 +232,10 @@ public class Criteria implements CriteriaDefinition {
|
|||||||
notDbo.put(k, convertValueIfNecessary(this.criteria.get(k)));
|
notDbo.put(k, convertValueIfNecessary(this.criteria.get(k)));
|
||||||
dbo.put("$not", notDbo);
|
dbo.put("$not", notDbo);
|
||||||
not = false;
|
not = false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if ("$not".equals(k)) {
|
if ("$not".equals(k)) {
|
||||||
not = true;
|
not = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dbo.put(k, convertValueIfNecessary(this.criteria.get(k)));
|
dbo.put(k, convertValueIfNecessary(this.criteria.get(k)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,8 +244,7 @@ public class Criteria implements CriteriaDefinition {
|
|||||||
if (isValue != null) {
|
if (isValue != null) {
|
||||||
queryCriteria.put(this.key, convertValueIfNecessary(this.isValue));
|
queryCriteria.put(this.key, convertValueIfNecessary(this.isValue));
|
||||||
queryCriteria.putAll(dbo);
|
queryCriteria.putAll(dbo);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
queryCriteria.put(this.key, dbo);
|
queryCriteria.put(this.key, dbo);
|
||||||
}
|
}
|
||||||
return queryCriteria;
|
return queryCriteria;
|
||||||
|
|||||||
@@ -15,10 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.query;
|
package org.springframework.data.document.mongodb.query;
|
||||||
|
|
||||||
import org.bson.types.BasicBSONList;
|
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
import com.mongodb.BasicDBObject;
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
|
import org.bson.types.BasicBSONList;
|
||||||
|
|
||||||
public class OrCriteria implements CriteriaDefinition {
|
public class OrCriteria implements CriteriaDefinition {
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.repository;
|
package org.springframework.data.document.mongodb.repository;
|
||||||
|
|
||||||
import static org.springframework.data.document.mongodb.repository.QueryUtils.*;
|
import static org.springframework.data.document.mongodb.repository.QueryUtils.applyPagination;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.mongodb.DBCollection;
|
||||||
|
import com.mongodb.DBCursor;
|
||||||
|
import com.mongodb.DBObject;
|
||||||
import org.springframework.data.document.mongodb.CollectionCallback;
|
import org.springframework.data.document.mongodb.CollectionCallback;
|
||||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
import org.springframework.data.document.mongodb.MongoTemplate;
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
import org.springframework.data.document.mongodb.query.Query;
|
||||||
@@ -29,10 +32,6 @@ import org.springframework.data.repository.query.ParametersParameterAccessor;
|
|||||||
import org.springframework.data.repository.query.RepositoryQuery;
|
import org.springframework.data.repository.query.RepositoryQuery;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import com.mongodb.DBCollection;
|
|
||||||
import com.mongodb.DBCursor;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for {@link RepositoryQuery} implementations for Mongo.
|
* Base class for {@link RepositoryQuery} implementations for Mongo.
|
||||||
*
|
*
|
||||||
@@ -88,6 +87,7 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a {@link Query} instance using the given {@link ParameterAccessor}
|
* Create a {@link Query} instance using the given {@link ParameterAccessor}
|
||||||
|
*
|
||||||
* @param accessor
|
* @param accessor
|
||||||
* @param converter
|
* @param converter
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
@@ -17,14 +17,13 @@ package org.springframework.data.document.mongodb.repository;
|
|||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import com.mongodb.BasicDBObject;
|
||||||
|
import com.mongodb.DBObject;
|
||||||
import org.springframework.data.document.mongodb.MongoWriter;
|
import org.springframework.data.document.mongodb.MongoWriter;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.repository.query.ParameterAccessor;
|
import org.springframework.data.repository.query.ParameterAccessor;
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom {@link ParameterAccessor} that uses a {@link MongoWriter} to serialize parameters into Mongo format.
|
* Custom {@link ParameterAccessor} that uses a {@link MongoWriter} to serialize parameters into Mongo format.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.repository;
|
package org.springframework.data.document.mongodb.repository;
|
||||||
|
|
||||||
import static org.springframework.data.document.mongodb.query.Criteria.*;
|
import static org.springframework.data.document.mongodb.query.Criteria.where;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ import org.springframework.data.repository.util.ClassUtils;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* TODO - Extract methods for {@link #getAnnotatedQuery()} into superclass as it is currently copied from Spring Data
|
* TODO - Extract methods for {@link #getAnnotatedQuery()} into superclass as it is currently copied from Spring Data
|
||||||
* JPA
|
* JPA
|
||||||
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
class MongoQueryMethod extends QueryMethod {
|
class MongoQueryMethod extends QueryMethod {
|
||||||
|
|||||||
@@ -102,7 +102,6 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -15,11 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.repository;
|
package org.springframework.data.document.mongodb.repository;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.*;
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,13 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.repository;
|
package org.springframework.data.document.mongodb.repository;
|
||||||
|
|
||||||
|
import com.mongodb.DBCursor;
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
import org.springframework.data.document.mongodb.query.Query;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.domain.Sort.Order;
|
import org.springframework.data.domain.Sort.Order;
|
||||||
|
|
||||||
import com.mongodb.DBCursor;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection of utility methods to apply sorting and pagination to a
|
* Collection of utility methods to apply sorting and pagination to a
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb.repository;
|
package org.springframework.data.document.mongodb.repository;
|
||||||
|
|
||||||
import static org.springframework.data.document.mongodb.query.Criteria.*;
|
import static org.springframework.data.document.mongodb.query.Criteria.where;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb;
|
package org.springframework.data.document.mongodb;
|
||||||
|
|
||||||
|
import com.mongodb.CommandResult;
|
||||||
|
import com.mongodb.DB;
|
||||||
|
import com.mongodb.Mongo;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -24,13 +27,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import com.mongodb.CommandResult;
|
|
||||||
import com.mongodb.DB;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* This test class assumes that you are already running the MongoDB server.
|
* This test class assumes that you are already running the MongoDB server.
|
||||||
*
|
*
|
||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user