abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r628529 - in /incubator/abdera/java/trunk/adapters/hibernate: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/abdera/ src/main/java/org/apache/abdera/protocol/ src/main/java/org/apache/...
Date Sun, 17 Feb 2008 19:04:11 GMT
Author: jmsnell
Date: Sun Feb 17 11:04:07 2008
New Revision: 628529

URL: http://svn.apache.org/viewvc?rev=628529&view=rev
Log:
checking in the hibernate adapter. this is NOT incorporated into the build at all yet. This
will make the code available, but users will, for now at least, have to compile the adapter
on their own

Added:
    incubator/abdera/java/trunk/adapters/hibernate/
    incubator/abdera/java/trunk/adapters/hibernate/readme
    incubator/abdera/java/trunk/adapters/hibernate/src/
    incubator/abdera/java/trunk/adapters/hibernate/src/main/
    incubator/abdera/java/trunk/adapters/hibernate/src/main/java/
    incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/
    incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/
    incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/
    incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/
    incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/
    incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/
    incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/hibernate/
    incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/hibernate/AtomEntryResultTransformer.java
    incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/hibernate/HibernateCollectionAdapter.java
    incubator/abdera/java/trunk/adapters/hibernate/src/test/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/java/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/DummyData.java
    incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/HibernateCollectionAdapterTest.java
    incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/TestSuite.java
    incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/
    incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/DummyData.hbm.xml
    incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/hibernate.cfg.xml
    incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/hibernate.properties

Added: incubator/abdera/java/trunk/adapters/hibernate/readme
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/hibernate/readme?rev=628529&view=auto
==============================================================================
--- incubator/abdera/java/trunk/adapters/hibernate/readme (added)
+++ incubator/abdera/java/trunk/adapters/hibernate/readme Sun Feb 17 11:04:07 2008
@@ -0,0 +1,4 @@
+The Hibernate adapter is not yet included in the build.
+because of licensing restrictions, we cannot depend on hibernate for the 
+build and cannot ship the jars.  So while this code is included in the
+trunk, users will need to build it manually for now.
\ No newline at end of file

Added: incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/hibernate/AtomEntryResultTransformer.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/hibernate/AtomEntryResultTransformer.java?rev=628529&view=auto
==============================================================================
--- incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/hibernate/AtomEntryResultTransformer.java
(added)
+++ incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/hibernate/AtomEntryResultTransformer.java
Sun Feb 17 11:04:07 2008
@@ -0,0 +1,73 @@
+package org.apache.abdera.protocol.server.adapters.hibernate;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.List;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.serializer.ConventionSerializationContext;
+import org.apache.abdera.ext.serializer.impl.EntrySerializer;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
+import org.apache.abdera.parser.ParseException;
+import org.apache.abdera.protocol.server.ProviderHelper;
+import org.apache.abdera.writer.StreamWriter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.transform.ResultTransformer;
+
+public class AtomEntryResultTransformer implements ResultTransformer {
+	
+	private static Log logger = LogFactory.getLog(AtomEntryResultTransformer.class);
+	
+	private String feedId;
+	private Abdera abdera;
+	private Feed feed;
+	
+	public AtomEntryResultTransformer(String feedId, Abdera abdera, Feed feed) {
+		this.feedId = feedId;
+		this.abdera = abdera;
+		this.feed = feed;
+	}
+	
+	public List transformList(List collection) {
+		return collection;
+	}
+
+	public Object transformTuple(Object[] tuple, String[] aliases) {
+		try {
+			if (tuple.length == 1) {				
+				StreamWriter sw = abdera.newStreamWriter();
+			    ByteArrayOutputStream out = new ByteArrayOutputStream();
+			    sw.setOutputStream(out).setAutoIndent(true);
+			    ConventionSerializationContext c = 
+			      new ConventionSerializationContext(sw);
+			    c.setSerializer(tuple[0].getClass(), new EntrySerializer());
+			    sw.startDocument();
+			    c.serialize(tuple[0]);
+			    sw.endDocument();
+			    
+			    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+			    Document<Entry> doc = abdera.getParser().parse(in);
+			    Entry entry = doc.getRoot();
+			    if (ProviderHelper.getEditUriFromEntry(entry) == null) {
+			    	entry.addLink(entry.getId().toString(), "edit");
+			    }
+			    entry.setId(feedId + "/" + entry.getId().toString());
+			    entry.getEditLink().setHref(entry.getId().toString());			    
+			    if (feed != null) {
+			    	feed.addEntry(entry);
+			    }
+			    return entry;				
+			} else {
+				return tuple;
+			}
+		} catch (Exception ex) {
+			logger.error("error creating an entry with the row data", ex);
+			throw new ParseException(ex);
+		}
+	}
+	
+}

Added: incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/hibernate/HibernateCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/hibernate/HibernateCollectionAdapter.java?rev=628529&view=auto
==============================================================================
--- incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/hibernate/HibernateCollectionAdapter.java
(added)
+++ incubator/abdera/java/trunk/adapters/hibernate/src/main/java/org/apache/abdera/protocol/server/adapters/hibernate/HibernateCollectionAdapter.java
Sun Feb 17 11:04:07 2008
@@ -0,0 +1,232 @@
+package org.apache.abdera.protocol.server.adapters.hibernate;
+
+import static org.apache.abdera.protocol.server.provider.managed.FeedConfiguration.ENTRY_ELEM_NAME_AUTHOR;
+import static org.apache.abdera.protocol.server.provider.managed.FeedConfiguration.ENTRY_ELEM_NAME_CONTENT;
+import static org.apache.abdera.protocol.server.provider.managed.FeedConfiguration.ENTRY_ELEM_NAME_ID;
+import static org.apache.abdera.protocol.server.provider.managed.FeedConfiguration.ENTRY_ELEM_NAME_TITLE;
+import static org.apache.abdera.protocol.server.provider.managed.FeedConfiguration.ENTRY_ELEM_NAME_UPDATED;
+
+import java.io.Serializable;
+import java.lang.reflect.Field;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.protocol.server.provider.basic.BasicAdapter;
+import org.apache.abdera.protocol.server.provider.managed.FeedConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+
+public class HibernateCollectionAdapter extends BasicAdapter {
+
+	private static Log logger = LogFactory.getLog(HibernateCollectionAdapter.class);
+	
+	protected static Configuration hibernateConfig;
+    protected static SessionFactory sessionFactory;
+    
+    public static final String HIBERNATE_ANNOTATION_CONFIG = "hibernateAnnotationConfig";
+    public static final String HIBERNATE_CFG_PATH = "hibernateCfgPath";
+    public static final String ENTRY_MAPPING_CLASS_NAME = "entryMappingClassName";
+    
+    public HibernateCollectionAdapter(Abdera abdera, FeedConfiguration config) {
+        super(abdera, config);
+        loadHibernateConfiguration();
+    }
+    
+    private void loadHibernateConfiguration() {
+    	if (hibernateConfig == null) {
+    		if (config.hasProperty(HIBERNATE_ANNOTATION_CONFIG) &&
+    				config.getProperty(HIBERNATE_ANNOTATION_CONFIG)
+    				.toString().equalsIgnoreCase(Boolean.TRUE.toString())) {
+    			hibernateConfig = new AnnotationConfiguration();
+    		} else {
+    			hibernateConfig = new Configuration();
+    		}
+    		
+    		if (config.hasProperty(HIBERNATE_CFG_PATH)) {
+    			hibernateConfig.configure((String) config.getProperty(HIBERNATE_CFG_PATH));
+    		} else {
+    			hibernateConfig.configure();
+    		}    		
+    		rebuildSessionFactory(hibernateConfig);
+    	}    	
+    }
+    
+    protected SessionFactory getSessionFactory() {
+        String sfName = hibernateConfig.getProperty(Environment.SESSION_FACTORY_NAME);
+        if ( sfName != null) {
+            logger.debug("Looking up SessionFactory in JNDI");
+            try {
+                return (SessionFactory) new InitialContext().lookup(sfName);
+            } catch (NamingException ex) {
+                throw new RuntimeException(ex);
+            }
+        } else if (sessionFactory == null) {
+            rebuildSessionFactory(hibernateConfig);
+        }
+        return sessionFactory;
+    }
+    
+    private void rebuildSessionFactory(Configuration cfg) {
+        logger.debug("Rebuilding the SessionFactory from given Configuration");
+        if (sessionFactory != null && !sessionFactory.isClosed())
+            sessionFactory.close();
+        if (cfg.getProperty(Environment.SESSION_FACTORY_NAME) != null) {
+            logger.debug("Managing SessionFactory in JNDI");
+            cfg.buildSessionFactory();
+        } else {
+            logger.debug("Holding SessionFactory in static variable");
+            sessionFactory = cfg.buildSessionFactory();
+        }
+        hibernateConfig = cfg;
+     }        
+	
+	@Override
+	public Entry createEntry(Entry entry) throws Exception {
+		Session session = getSessionFactory().openSession();
+		Transaction tx = session.beginTransaction();
+		
+		Serializable entryId = null;
+
+		try {
+			Object mapping = collectMappingObject(entry, null);
+			entryId = session.save(mapping);
+			
+			tx.commit();
+						
+		} catch (Exception ex) {
+			tx.rollback();
+			logger.error("error creating a new entry", ex);			
+		} finally {
+			session.close();
+		}
+		
+		return getEntry(entryId);
+	}
+
+	@Override
+	public boolean deleteEntry(Object entryId) throws Exception {
+		Session session = getSessionFactory().openSession();
+		Transaction tx = session.beginTransaction();
+		
+		boolean deleted = false;
+		try {
+			Object mapping = session.load(
+					Class.forName((String) config.getProperty(ENTRY_MAPPING_CLASS_NAME)),
+					(Serializable) entryId); 
+			
+			if (mapping != null) {
+				session.delete(mapping);
+				tx.commit();
+			}
+			deleted = true;
+		} catch (HibernateException ex) {
+			tx.rollback();
+			logger.error("error deleting the entry", ex);			
+		} finally {
+			session.close();
+		}
+				
+		return deleted;
+	}
+
+	@Override
+	public Entry getEntry(Object entryId) throws Exception {
+		Session session = getSessionFactory().openSession();
+		
+		Query query = session.getNamedQuery(config.getFeedId() + "-get-entry");
+		query.setParameter("id", entryId);
+		query.setResultTransformer(new AtomEntryResultTransformer(
+				config.getServerConfiguration().getServerUri() + "/" + config.getFeedId(), getAbdera(),
null));		
+		
+		Entry entry = (Entry) query.uniqueResult();
+		
+		session.close();
+		return entry;
+	}
+
+	@Override
+	public Feed getFeed() throws Exception {		
+		Session session = getSessionFactory().openSession();
+		
+		String queryName = config.getFeedId() + "-get-feed";		
+		Query query = session.getNamedQuery(queryName);
+		
+		Feed feed = createFeed();
+		query.setResultTransformer(new AtomEntryResultTransformer(
+				config.getServerConfiguration().getServerUri() + "/" + config.getFeedId(), this.getAbdera(),
feed));
+		query.list();		
+		
+		session.close();
+		return feed;
+	}
+
+	@Override
+	public Entry updateEntry(Object entryId, Entry entry) throws Exception {
+		Session session = getSessionFactory().openSession();
+		Transaction tx = session.beginTransaction();
+		try {
+			Object forUpdate = session.load(
+					Class.forName((String) config.getProperty(ENTRY_MAPPING_CLASS_NAME)), 
+					(Serializable) entryId);
+			if (forUpdate != null) {
+				forUpdate = collectMappingObject(entry, forUpdate);
+				session.update(forUpdate);
+				tx.commit();
+			}
+		} catch (HibernateException ex) {
+			tx.rollback();
+			logger.error("error deleting the entry", ex);			
+		} finally {
+			session.close();
+		}
+				
+		return entry;
+	}
+	
+	protected Object collectMappingObject(Entry entry, Object forUpdate) throws Exception {
+		boolean create = false;
+		Class clazz = Class.forName((String) config.getProperty(ENTRY_MAPPING_CLASS_NAME));
+		if (forUpdate == null) {			
+			forUpdate = clazz.newInstance();
+			create = true;
+		}
+		
+		for (Field field : clazz.getDeclaredFields()) {
+			if (create && field.getName().equals(ENTRY_ELEM_NAME_ID)) {
+				collectField(field, clazz, forUpdate, entry.getId().toString());				
+			} else if (field.getName().equals(ENTRY_ELEM_NAME_AUTHOR)){
+				collectField(field, clazz, forUpdate, entry.getAuthor().getName());
+			} else if (field.getName().equals(ENTRY_ELEM_NAME_TITLE)) {
+				collectField(field, clazz, forUpdate, entry.getTitle());
+			} else if (field.getName().equals(ENTRY_ELEM_NAME_UPDATED)) {
+				collectField(field, clazz, forUpdate, entry.getUpdated());
+			} else if (field.getName().equals(ENTRY_ELEM_NAME_CONTENT)) {
+				collectField(field, clazz, forUpdate, entry.getContent());
+			}
+		}
+		
+		return forUpdate;
+	}
+	
+	protected void collectField(Field field, Class clazz, Object mappingObject, Object entryValue)
throws Exception {		
+		clazz.getMethod(getSetter(field.getName()), new Class[]{field.getType()})
+			.invoke(mappingObject, new Object[]{entryValue});
+	}
+	
+	protected String getSetter(String fieldName) {
+		return "set" + fieldName.substring(0,1).toUpperCase() + fieldName.substring(1);
+	}
+
+}

Added: incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/DummyData.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/DummyData.java?rev=628529&view=auto
==============================================================================
--- incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/DummyData.java
(added)
+++ incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/DummyData.java
Sun Feb 17 11:04:07 2008
@@ -0,0 +1,46 @@
+package org.apache.abdera.protocol.server.adapters.hibernate;
+
+import java.util.Date;
+
+
+public class DummyData {
+	
+	public DummyData(){}
+	
+	private String id;
+	private String author;
+	private String title;
+	private String content;
+	private Date updated;
+		
+	public String getId() {
+		return id;
+	}
+	public void setId(String id) {
+		this.id = id;
+	}	
+	public String getAuthor() {
+		return author;
+	}
+	public void setAuthor(String author) {
+		this.author = author;
+	}
+	public String getTitle() {
+		return title;
+	}
+	public void setTitle(String title) {
+		this.title = title;
+	}
+	public String getContent() {
+		return content;
+	}
+	public void setContent(String content) {
+		this.content = content;
+	}
+	public Date getUpdated() {
+		return updated;
+	}
+	public void setUpdated(Date updated) {
+		this.updated = updated;
+	}
+}

Added: incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/HibernateCollectionAdapterTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/HibernateCollectionAdapterTest.java?rev=628529&view=auto
==============================================================================
--- incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/HibernateCollectionAdapterTest.java
(added)
+++ incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/HibernateCollectionAdapterTest.java
Sun Feb 17 11:04:07 2008
@@ -0,0 +1,119 @@
+package org.apache.abdera.protocol.server.adapters.hibernate;
+
+import java.util.Date;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.protocol.Response.ResponseType;
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.server.ServiceManager;
+import org.apache.abdera.protocol.server.provider.basic.BasicProvider;
+import org.apache.abdera.protocol.server.servlet.AbderaServlet;
+import org.apache.abdera.util.Constants;
+import org.apache.abdera.util.MimeTypeHelper;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+
+import static org.junit.Assert.*;
+
+public class HibernateCollectionAdapterTest {
+
+	private static Server server;
+	private static Abdera abdera = Abdera.getInstance();
+	private static AbderaClient client = new AbderaClient();
+	  
+	@BeforeClass
+	public static void setUp() throws Exception {		
+		if (server == null) {
+			server = new Server(9002);
+			Context context = new Context(server, "/", Context.SESSIONS);
+			ServletHolder servletHolder = new ServletHolder(new AbderaServlet());
+			servletHolder.setInitParameter(ServiceManager.PROVIDER, BasicProvider.class.getName());
+			context.addServlet(servletHolder, "/*");
+			server.start();
+	    }
+	}
+	
+	@AfterClass
+	public static void tearDown() throws Exception {		
+		server.stop();
+	}
+	
+	@Test
+	public void testGetFeed() {
+		ClientResponse resp = client.get("http://localhost:9002/hibernate");
+		assertNotNull(resp);
+		assertEquals(ResponseType.SUCCESS, resp.getType());
+	    assertTrue(MimeTypeHelper.isMatch(resp.getContentType().toString(), Constants.ATOM_MEDIA_TYPE));
+	    Document<Feed> doc = resp.getDocument();
+	    Feed feed = doc.getRoot();
+	    assertEquals("http://localhost:9002/hibernate", feed.getId().toString());	    
+	    assertEquals("david", feed.getAuthor().getName());
+	    assertEquals(0, feed.getEntries().size());
+	    resp.release();	    
+	}
+	
+	@Test
+	public void testCreateEntry() {		
+		Entry entry = abdera.newEntry();
+		entry.setId("foo");
+		entry.setTitle("test entry");
+		entry.setContent("Test Content");
+		entry.addLink("http://example.org");
+		entry.setUpdated(new Date());
+		entry.addAuthor("david");
+		ClientResponse resp = client.post("http://localhost:9002/hibernate", entry);
+		assertNotNull(resp);
+		assertEquals(ResponseType.SUCCESS, resp.getType());
+		assertEquals(201, resp.getStatus());
+		assertEquals("http://localhost:9002/hibernate/foo", resp.getLocation().toString());
+		resp = client.get("http://localhost:9002/hibernate");
+		Document<Feed> feed_doc = resp.getDocument();
+		Feed feed = feed_doc.getRoot();
+		assertEquals(feed.getEntries().size(), 1);
+		resp.release();
+	}
+	
+	@Test
+	public void testUpdateEntry() {		
+		ClientResponse resp = client.get("http://localhost:9002/hibernate/foo");
+	    Document<Entry> doc = resp.getDocument();
+	    Entry entry = (Entry) doc.getRoot().clone();
+	    entry.setTitle("This is the modified title");
+	    resp.release();
+	    resp = client.put("http://localhost:9002/hibernate/foo", entry);
+	    assertEquals(ResponseType.SUCCESS, resp.getType());
+	    assertEquals(200, resp.getStatus());
+	    resp.release();
+	    resp = client.get("http://localhost:9002/hibernate/foo");
+	    doc = resp.getDocument();
+	    entry = doc.getRoot();
+	    assertEquals("This is the modified title", entry.getTitle());
+	    resp.release();
+	    resp = client.get("http://localhost:9002/hibernate");
+	    Document<Feed> feed_doc = resp.getDocument();
+	    Feed feed = feed_doc.getRoot();
+	    assertEquals(1, feed.getEntries().size());
+	    resp.release();
+	}
+	
+	@Test
+	public void testDeleteEntry() {		
+		ClientResponse resp = client.delete("http://localhost:9002/hibernate/foo");
+		assertEquals(ResponseType.SUCCESS, resp.getType());
+		resp.release();
+		resp = client.get("http://localhost:9002/hibernate");
+		Document<Feed> feed_doc = resp.getDocument();
+		Feed feed = feed_doc.getRoot();
+		assertEquals(0, feed.getEntries().size());
+		resp.release();
+	}
+
+}

Added: incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/TestSuite.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/TestSuite.java?rev=628529&view=auto
==============================================================================
--- incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/TestSuite.java
(added)
+++ incubator/abdera/java/trunk/adapters/hibernate/src/test/java/org/apache/abdera/protocol/server/adapters/hibernate/TestSuite.java
Sun Feb 17 11:04:07 2008
@@ -0,0 +1,12 @@
+package org.apache.abdera.protocol.server.adapters.hibernate;
+
+import org.junit.internal.runners.TextListener;
+import org.junit.runner.JUnitCore;
+
+public class TestSuite {
+	public static void main(String[] args) {
+	    JUnitCore runner = new JUnitCore();
+	    runner.addListener(new TextListener(System.out));
+	    runner.run(HibernateCollectionAdapterTest.class);
+	  }
+}

Added: incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/DummyData.hbm.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/DummyData.hbm.xml?rev=628529&view=auto
==============================================================================
--- incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/DummyData.hbm.xml
(added)
+++ incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/DummyData.hbm.xml
Sun Feb 17 11:04:07 2008
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+
+<hibernate-mapping package="com.oos.data.objects">
+	
+    <class name="org.apache.abdera.protocol.server.adapters.hibernate.DummyData" table="dummyData">
+        <id name="id" type="string" />
+        	    
+	    <property name="author" type="string"/>
+	    <property name="title" type="string"/>	    
+	    <property name="content" type="string"/>	    
+	    <property name="updated" type="timestamp"/>	    
+    </class>
+    
+    <query name="hibernate-get-feed">from DummyData</query>    
+    <query name="hibernate-get-entry">from DummyData where id = :id</query>
+    
+</hibernate-mapping>

Added: incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/hibernate.cfg.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/hibernate.cfg.xml?rev=628529&view=auto
==============================================================================
--- incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/hibernate.cfg.xml
(added)
+++ incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/hibernate.cfg.xml
Sun Feb 17 11:04:07 2008
@@ -0,0 +1,26 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<hibernate-configuration>
+
+	<session-factory>
+	
+		<property name="dialect">org.hibernate.dialect.MySQLDialect</property>		
+		<property name="hibernate.bytecode.use_reflection_optimizer">true</property>
+		
+        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
+        <property name="connection.url">jdbc:mysql://localhost:3306/hibernateAdapterDb</property>
+        <property name="connection.username">root</property>
+        <property name="connection.password"></property>
+        <property name="connection.pool_size">3</property>
+         
+		<property name="hbm2ddl.auto">create</property>
+		 
+		<property name="max_fetch_depth">3</property>
+		<property name="current_session_context_class">thread</property>
+		
+		<mapping resource="abdera/adapter/DummyData.hbm.xml" />		
+				
+	</session-factory>
+
+</hibernate-configuration>

Added: incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/hibernate.properties
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/hibernate.properties?rev=628529&view=auto
==============================================================================
--- incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/hibernate.properties
(added)
+++ incubator/abdera/java/trunk/adapters/hibernate/src/test/resources/abdera/adapter/hibernate.properties
Sun Feb 17 11:04:07 2008
@@ -0,0 +1,8 @@
+adapterClassName=org.apache.abdera.protocol.server.adapters.hibernate.HibernateCollectionAdapter
+hibernateCfgPath=abdera/adapter/hibernate.cfg.xml
+entryMappingClassName=org.apache.abdera.protocol.server.adapters.hibernate.DummyData
+
+subUri=hibernate
+configFile=dummyFileLocation
+author=david
+title=Hibernate Adapter Feed
\ No newline at end of file



Mime
View raw message