Cleanup and adding class-level expiry.

This commit is contained in:
Michael Nitschinger
2013-01-22 15:54:34 +01:00
parent a7f8eb5fbe
commit 66f6df4860
6 changed files with 50 additions and 7 deletions

View File

@@ -52,7 +52,6 @@ public class CouchbaseTemplate implements CouchbaseOperations {
public void insert(Object objectToSave) {
ConvertedCouchbaseDocument converted = new ConvertedCouchbaseDocument();
couchbaseConverter.write(objectToSave, converted);
client.set(converted.getId(), converted.getExpiry(), converted.getValue());
}

View File

@@ -28,11 +28,8 @@ import com.couchbase.spring.core.mapping.CouchbasePersistentProperty;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.codehaus.jackson.JsonEncoding;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
@@ -43,7 +40,6 @@ import org.springframework.data.mapping.model.BeanWrapper;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.mapping.PropertyHandler;
public class MappingCouchbaseConverter extends AbstractCouchbaseConverter
@@ -110,6 +106,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter
String id = wrapper.getProperty(idProperty, String.class, false);
target.setId(id);
target.setExpiry(entity.getExpiry());
JsonFactory jsonFactory = new JsonFactory();
OutputStream jsonStream = new ByteArrayOutputStream();

View File

@@ -50,4 +50,14 @@ public class BasicCouchbasePersistentEntity<T>
context.setBeanResolver(new BeanFactoryResolver(applicationContext));
context.setRootObject(applicationContext);
}
public int getExpiry() {
com.couchbase.spring.core.mapping.Document annotation =
getType().getAnnotation(com.couchbase.spring.core.mapping.Document.class);
if(annotation == null) {
return 0;
}
return annotation.expiry();
}
}

View File

@@ -27,4 +27,10 @@ import org.springframework.data.mapping.PersistentEntity;
public interface CouchbasePersistentEntity<T> extends
PersistentEntity<T, CouchbasePersistentProperty> {
/**
* Returns the expiry time for the document.
*
* @return
*/
int getExpiry();
}

View File

@@ -37,5 +37,10 @@ import org.springframework.data.annotation.Persistent;
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface Document {
/**
* An optional expiry time for the document.
*/
int expiry() default 0;
}