abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r620069 - in /incubator/abdera/java/trunk: ./ adapters/ adapters/jcr/ adapters/jdbc/ adapters/jdbc/src/ adapters/jdbc/src/main/ adapters/jdbc/src/main/java/ adapters/jdbc/src/main/java/org/ adapters/jdbc/src/main/java/org/apache/ adapters/j...
Date Sat, 09 Feb 2008 02:54:11 GMT
Author: jmsnell
Date: Fri Feb  8 18:54:09 2008
New Revision: 620069

URL: http://svn.apache.org/viewvc?rev=620069&view=rev
Log:
check in the jdbc adapter (https://issues.apache.org/jira/browse/ABDERA-112)

also, create a new adapters directory that can contain all of the various adapter implementations.
move the jcr adapter into that dir

I need someone with maven experience to look at the pom.xml for the jdbc adapter.
We also need to figure out test cases for the jdbc adapter, preferably using cloudscape.

Added:
    incubator/abdera/java/trunk/adapters/
    incubator/abdera/java/trunk/adapters/jcr/
      - copied from r620068, incubator/abdera/java/trunk/jcr/
    incubator/abdera/java/trunk/adapters/jdbc/
    incubator/abdera/java/trunk/adapters/jdbc/pom.xml
    incubator/abdera/java/trunk/adapters/jdbc/src/
    incubator/abdera/java/trunk/adapters/jdbc/src/main/
    incubator/abdera/java/trunk/adapters/jdbc/src/main/java/
    incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/
    incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/apache/
    incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/apache/abdera/
    incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/apache/abdera/protocol/
    incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/apache/abdera/protocol/server/
    incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/apache/abdera/protocol/server/adapters/
    incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/apache/abdera/protocol/server/adapters/jdbc/
    incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/apache/abdera/protocol/server/adapters/jdbc/JdbcCollectionAdapter.java
Removed:
    incubator/abdera/java/trunk/jcr/
Modified:
    incubator/abdera/java/trunk/pom.xml
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/CollectionAdapterConfiguration.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/FeedConfiguration.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/ManagedCollectionAdapter.java

Added: incubator/abdera/java/trunk/adapters/jdbc/pom.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/jdbc/pom.xml?rev=620069&view=auto
==============================================================================
--- incubator/abdera/java/trunk/adapters/jdbc/pom.xml (added)
+++ incubator/abdera/java/trunk/adapters/jdbc/pom.xml Fri Feb  8 18:54:09 2008
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  The ASF licenses this file to You
+  under the Apache License, Version 2.0 (the "License"); you may not
+  use this file except in compliance with the License.
+  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.  For additional information regarding
+  copyright in this work, please see the NOTICE file in the top level
+  directory of this distribution. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.apache.abdera</groupId>
+    <artifactId>abdera</artifactId>
+    <version>0.4.0-incubating-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>abdera-jdbc</artifactId>
+  <packaging>jar</packaging>
+  <name>Abdera JDBC Collection Adapter</name>
+  <version>0.4.0-incubating-SNAPSHOT</version>
+  <description>JDBC Collection Adapter</description>
+  <inceptionYear>2006</inceptionYear>
+  <url>http://incubator.apache.org/abdera</url>
+  <scm>
+    <connection>
+      scm:svn:http://svn.apache.org/repos/asf/incubator/abdera/java/trunk/jdbc/
+    </connection>
+    <developerConnection>
+      scm:svn:https://svn.apache.org/repos/asf/incubator/abdera/java/trunk/jdbc/
+    </developerConnection>
+    <url>
+      http://svn.apache.org/repos/asf/incubator/abdera/java/trunk/jdbc/
+    </url>
+  </scm>
+  
+  <dependencies>
+      
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty</artifactId>
+      <version>6.1.5</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.abdera</groupId>
+      <artifactId>abdera-server</artifactId>
+      <version>0.4.0-incubating-SNAPSHOT</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.abdera</groupId>
+      <artifactId>abdera-client</artifactId>
+      <version>0.4.0-incubating-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>com.ibatis</groupId>
+      <artifactId>ibatis-sqlmap</artifactId>
+      <version>2.3.0.667</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.ibatis</groupId>
+      <artifactId>ibatis-common</artifactId>
+      <version>2.3.0.667</version>
+    </dependency>
+    
+  </dependencies>
+</project>

Added: incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/apache/abdera/protocol/server/adapters/jdbc/JdbcCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/apache/abdera/protocol/server/adapters/jdbc/JdbcCollectionAdapter.java?rev=620069&view=auto
==============================================================================
--- incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/apache/abdera/protocol/server/adapters/jdbc/JdbcCollectionAdapter.java
(added)
+++ incubator/abdera/java/trunk/adapters/jdbc/src/main/java/org/apache/abdera/protocol/server/adapters/jdbc/JdbcCollectionAdapter.java
Fri Feb  8 18:54:09 2008
@@ -0,0 +1,240 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.server.adapters.jdbc;
+
+import java.io.ByteArrayInputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Content;
+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.abdera.protocol.server.provider.managed.ServerConfiguration;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import com.ibatis.sqlmap.client.SqlMapClient;
+import com.ibatis.sqlmap.client.SqlMapClientBuilder;
+
+public class JdbcCollectionAdapter 
+  extends BasicAdapter {
+  
+  private static final String ENTRY_AUTHOR = "feedserver";
+  private static final String ENTRY_TITLE = "jdbc entry title";
+
+
+  // this class needs to be public - so that Adapter Manager can invoke it
+  // to create an instance of this adapter
+  public JdbcCollectionAdapter(
+    Abdera abdera, 
+    FeedConfiguration config) {
+      super(abdera, config);
+  }
+
+  protected Map<String, SqlMapClient> sqlMapClients =
+      new HashMap<String, SqlMapClient>();
+
+  protected SqlMapClient getSqlMapClient() throws Exception {
+    String dataSourceId = config.getFeedConfigLocation();
+    if (sqlMapClients.containsKey(dataSourceId)) {
+      return sqlMapClients.get(dataSourceId);
+    } else {
+      SqlMapClient client = SqlMapClientBuilder.buildSqlMapClient(
+          config.getAdapterConfiguration()
+              .getAdapterConfigAsReader());
+      sqlMapClients.put(dataSourceId, client);
+      return client;
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  public Feed getFeed() throws Exception {
+    SqlMapClient client = getSqlMapClient();
+    String queryId = config.getFeedId() + "-get-feed";
+    List<Map<String, Object>> rows = client.queryForList(queryId);
+    Feed feed = createFeed();
+    ServerConfiguration serverConfig = config.getServerConfiguration();
+    feed.declareNS(serverConfig.getFeedNamespace(), serverConfig.getFeedNamespacePrefix());
+    for (Map<String, Object> row : rows)
+      createEntryFromRow(feed,row);
+    return feed;
+  }
+
+  @SuppressWarnings("unchecked")
+  public Entry getEntry(Object entryId) throws Exception {
+    String queryId = config.getFeedId() + "-get-entry";
+    SqlMapClient client = getSqlMapClient();
+    Map<String, Object> row = (Map<String, Object>)
+        client.queryForObject(queryId, entryId);
+    if (row == null) {
+      // didn't find the entry.
+      return null;
+    }
+    return createEntryFromRow(null,row);
+  }
+
+  public Entry createEntry(Entry entry) throws Exception {
+    SqlMapClient client = getSqlMapClient();
+    String queryId = config.getFeedId() + "-insert-entry";
+    Object newEntryId = client.insert(queryId, collectColumns(entry));
+    return getEntry(newEntryId);
+  }
+
+  public Entry updateEntry(Object entryId, Entry entry) throws Exception {
+    SqlMapClient client = getSqlMapClient();
+    String queryId = config.getFeedId() + "-update-entry";
+    return client.update(queryId, collectColumns(entry)) > 0
+        ? getEntry(entryId) : null;
+  }
+
+  public boolean deleteEntry(Object entryId) throws Exception {
+    String queryId = config.getFeedId() + "-delete-entry";
+    SqlMapClient client = getSqlMapClient();
+    return client.delete(queryId, entryId) > 0;
+  }
+
+  protected Entry createEntryFromRow(Feed feed, Map<String, Object> row)
+      throws Exception {
+    Entry entry = feed != null ? feed.addEntry() : abdera.newEntry();
+    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+    DocumentBuilder builder = factory.newDocumentBuilder();
+    Document doc = builder.newDocument();
+    Element entity = doc.createElement("entity");
+    doc.appendChild(entity);
+    for (String columnName : row.keySet()) {
+      if (row.get(columnName) == null) {
+        continue;
+      }
+      Object value = row.get(columnName);
+      if ("id".equals(columnName)) {
+        entry.setId(createEntryIdUri(value.toString()));
+      } else if ("title".equals(columnName)) {
+        entry.setTitle(value.toString());
+      } else if ("author".equals(columnName)) {
+        entry.addAuthor(value.toString());
+      } else if ("updated".equals(columnName) &&
+          value instanceof java.util.Date) {
+        entry.setUpdated((Date) value);
+      } else if ("link".equals(columnName)) {
+        entry.addLink(value.toString());
+      } else {
+        Element node = doc.createElement(columnName);
+        node.appendChild(doc.createTextNode(value.toString()));
+        entity.appendChild(node);
+      }
+    }
+    if (entry.getUpdated() == null) {
+      entry.setUpdated(new Date());
+    }
+    if (entry.getAuthor() == null) {
+      entry.addAuthor(ENTRY_AUTHOR);
+    }
+    if (entry.getTitle() == null) {
+      entry.setTitle(ENTRY_TITLE);
+    }
+    entry.setContent(getDocumentAsXml(doc),"text/xml");
+    addEditLinkToEntry(entry);
+    return entry;
+  }
+  public static String getDocumentAsXml(Document doc)
+      throws TransformerConfigurationException, TransformerException
+  {
+      DOMSource domSource = new DOMSource(doc);
+      TransformerFactory tf = TransformerFactory.newInstance();
+      Transformer transformer = tf.newTransformer();
+      transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+      java.io.StringWriter sw = new java.io.StringWriter();
+      StreamResult sr = new StreamResult(sw);
+      transformer.transform(domSource, sr);
+      String str = sw.toString();
+      logger.finest(str);
+      return str;
+  }
+
+
+  protected Map<String, Object> collectColumns(Entry entry)
+      throws Exception {
+    Map<String, Object> columns = new HashMap<String, Object>();
+
+    if (entry.getId() != null) {
+      columns.put(FeedConfiguration.ENTRY_ELEM_NAME_ID,
+          entry.getId().toString());
+    }
+    if (entry.getAuthor() != null) {
+      columns.put(FeedConfiguration.ENTRY_ELEM_NAME_AUTHOR,
+          entry.getAuthor().getText());
+    }
+    if (entry.getTitle() != null) {
+      columns.put(FeedConfiguration.ENTRY_ELEM_NAME_TITLE, entry.getTitle());
+    }
+    if (entry.getUpdated() != null) {
+      columns.put(FeedConfiguration.ENTRY_ELEM_NAME_UPDATED,
+          entry.getUpdated());
+    }
+
+    Content content = entry.getContentElement();
+    if (content != null) {
+      String contentStr = content.getValue();
+      parseContent(contentStr, columns);
+    }
+
+    return columns;
+  }
+
+  static void parseContent(String str, Map<String, Object> columns)
+      throws Exception {
+    ByteArrayInputStream inStr = new ByteArrayInputStream(str.getBytes());
+    XMLInputFactory factory = XMLInputFactory.newInstance();
+    XMLStreamReader parser = factory.createXMLStreamReader(inStr);
+
+    while (true) {
+      int event = parser.next();
+      if (event == XMLStreamConstants.END_DOCUMENT) {
+         parser.close();
+         break;
+      }
+      if (event == XMLStreamConstants.START_ELEMENT) {
+        String name = parser.getLocalName();
+        int eventType =  parser.next();
+        if (eventType == XMLStreamConstants.CHARACTERS) {
+          String value = parser.getText();
+          columns.put(name, value);
+        }
+      }
+    }
+  }
+  
+}

Modified: incubator/abdera/java/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/pom.xml?rev=620069&r1=620068&r2=620069&view=diff
==============================================================================
--- incubator/abdera/java/trunk/pom.xml (original)
+++ incubator/abdera/java/trunk/pom.xml Fri Feb  8 18:54:09 2008
@@ -285,7 +285,8 @@
     <module>security</module>
     <module>server</module>
     <module>client</module>
-    <module>jcr</module>
+    <module>adapters/jcr</module>
+    <!--module>adapters/jdbc</module-->
     <module>extensions/gdata</module>
     <module>extensions/geo</module>
     <module>extensions/json</module>

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/CollectionAdapterConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/CollectionAdapterConfiguration.java?rev=620069&r1=620068&r2=620069&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/CollectionAdapterConfiguration.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/CollectionAdapterConfiguration.java
Fri Feb  8 18:54:09 2008
@@ -19,6 +19,8 @@
 
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
 
 public class CollectionAdapterConfiguration 
   extends Configuration {
@@ -32,10 +34,19 @@
       this.serverConfiguration = serverConfiguration;
   }
 
-  FileInputStream getConfigAsFileInputStream() 
+  public FileInputStream getConfigAsFileInputStream() 
     throws IOException {
       String filePath
         = serverConfiguration.getAdapterConfigLocation() + fileLocation;
       return Configuration.loadFileAsInputStream(filePath);
+  }
+  
+  public Reader getAdapterConfigAsReader() 
+    throws IOException {
+      return new InputStreamReader(getConfigAsFileInputStream());
+  }
+  
+  public ServerConfiguration getServerConfiguration() {
+    return serverConfiguration;
   }
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/FeedConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/FeedConfiguration.java?rev=620069&r1=620068&r2=620069&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/FeedConfiguration.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/FeedConfiguration.java
Fri Feb  8 18:54:09 2008
@@ -166,4 +166,8 @@
   public String getTitle(RequestContext request) {
     return getFeedTitle();
   }
+  
+  public ServerConfiguration getServerConfiguration() {
+    return adapterConfiguration.getServerConfiguration();
+  }
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/ManagedCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/ManagedCollectionAdapter.java?rev=620069&r1=620068&r2=620069&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/ManagedCollectionAdapter.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/managed/ManagedCollectionAdapter.java
Fri Feb  8 18:54:09 2008
@@ -19,6 +19,8 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.context.ResponseContextException;
 import org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter;
 
 public abstract class ManagedCollectionAdapter
@@ -41,5 +43,17 @@
   
   public FeedConfiguration getConfiguration() {
     return this.config;
+  }
+  
+  public String getAuthor() throws ResponseContextException {
+    return config.getFeedAuthor();
+  }
+
+  public String getId(RequestContext request) {
+    return config.getFeedId();
+  }
+
+  public String getTitle(RequestContext request) {
+    return config.getFeedTitle();
   }
 }



Mime
View raw message