labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r605462 - in /labs/fluid/slice: ./ src/main/java/org/apache/openjpa/slice/ src/main/java/org/apache/openjpa/slice/jdbc/ src/main/java/org/apache/openjpa/slice/policy/ src/test/java/org/apache/openjpa/distributed/ src/test/java/org/apache/op...
Date Wed, 19 Dec 2007 08:17:37 GMT
Author: ppoddar
Date: Wed Dec 19 00:17:31 2007
New Revision: 605462

URL: http://svn.apache.org/viewvc?rev=605462&view=rev
Log: (empty)

Added:
    labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestBasic.java
Removed:
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/policy/RandomDistributionPolicy.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/policy/RoundRobinDistributionPolicy.java
    labs/fluid/slice/src/test/java/org/apache/openjpa/distributed/
Modified:
    labs/fluid/slice/pom.xml
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributionPolicy.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedDataSource.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedPreparedStatement.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStatement.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/package.html

Modified: labs/fluid/slice/pom.xml
URL: http://svn.apache.org/viewvc/labs/fluid/slice/pom.xml?rev=605462&r1=605461&r2=605462&view=diff
==============================================================================
--- labs/fluid/slice/pom.xml (original)
+++ labs/fluid/slice/pom.xml Wed Dec 19 00:17:31 2007
@@ -77,10 +77,6 @@
             <id>apache-snapshots</id>
             <url>http://people.apache.org/repo/m2-snapshot-repository</url>
         </repository>
-        <repository>
-            <id>serp-rep</id>
-            <url>http://serp.sourceforge.net/m2repo</url>
-        </repository>
   </repositories>
     
   <dependencies>
@@ -92,13 +88,6 @@
     </dependency>
     
     <dependency>
-      <groupId>net.sourceforge.serp</groupId>
-  	  <artifactId>serp</artifactId>
-  	  <version>1.13.0</version>
-  	  <scope>compile</scope>
-    </dependency>
-        
-    <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
       <version>5.0.4</version>
@@ -253,6 +242,7 @@
                   <reportSets>
                      <reportSet>
                         <reports>
+                           <report>javadoc</report>
                            <report>dependencies</report>
                            <report>project-team</report>
                            <report>mailing-list</report>

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributionPolicy.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributionPolicy.java?rev=605462&r1=605461&r2=605462&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributionPolicy.java (original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributionPolicy.java Wed Dec
19 00:17:31 2007
@@ -31,7 +31,7 @@
 	 * Gets the index of the database where a given instance will be stored.
 	 *  
 	 * @param pc The newly persistent or to-be-merged object. 
-	 * @param stores the list of Connection URLs in the same order as specified 
+	 * @param urls the list of Connection URLs in the same order as specified 
 	 * in the configuration.
 	 * 
 	 * @return an index in the given list. It is an error to return a value 

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedDataSource.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedDataSource.java?rev=605462&r1=605461&r2=605462&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedDataSource.java
(original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedDataSource.java
Wed Dec 19 00:17:31 2007
@@ -29,6 +29,12 @@
 
 import org.apache.openjpa.lib.jdbc.DecoratingDataSource;
 
+/**
+ * A virtual datasource that contains many physical datasources.
+ * 
+ * @author Pinaki Poddar 
+ *
+ */
 public class DistributedDataSource extends DecoratingDataSource implements
 		Iterable<DataSource> {
 	private List<DataSource> real = new ArrayList<DataSource>();

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedPreparedStatement.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedPreparedStatement.java?rev=605462&r1=605461&r2=605462&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedPreparedStatement.java
(original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedPreparedStatement.java
Wed Dec 19 00:17:31 2007
@@ -25,7 +25,6 @@
 import java.sql.Array;
 import java.sql.Blob;
 import java.sql.Clob;
-import java.sql.Connection;
 import java.sql.Date;
 import java.sql.ParameterMetaData;
 import java.sql.PreparedStatement;
@@ -33,11 +32,16 @@
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
-import java.sql.SQLWarning;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.util.Calendar;
 
+/**
+ * A virtual PreparedStaement that delegates to a set of actual PreparedStatements.
+ * 
+ * @author Pinaki Poddar 
+ *
+ */
 public class DistributedPreparedStatement extends DistributedTemplate<PreparedStatement>
 		implements PreparedStatement {
 

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStatement.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStatement.java?rev=605462&r1=605461&r2=605462&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStatement.java
(original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStatement.java
Wed Dec 19 00:17:31 2007
@@ -18,226 +18,16 @@
  */
 package org.apache.openjpa.slice.jdbc;
 
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.SQLWarning;
 import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
 
+/**
+ * A virtual Statement that delegates to many actual Statements.
+ * 
+ * @author Pinaki Poddar 
+ *
+ */
 public class DistributedStatement extends DistributedTemplate<Statement>  {
 	public DistributedStatement(DistributedConnection c) {
 		super(c);
 	}
-	
-//	public void add(Statement s) {
-//		try {
-//			if (!con.contains(s.getConnection()))
-//				throw new IllegalArgumentException(s + " has different connection");
-//			stmts.add(s);
-//		} catch (SQLException e) {
-//			e.printStackTrace();
-//		}
-//	}
-//	
-//	public void addBatch(String sql) throws SQLException {
-//		for (Statement s:stmts)
-//			s.addBatch(sql);
-//	}
-//
-//	public void cancel() throws SQLException {
-//		for (Statement s:stmts)
-//			s.cancel();
-//	}
-//
-//	public void clearBatch() throws SQLException {
-//		for (Statement s:stmts)
-//			s.clearBatch();
-//	}
-//
-//	public void clearWarnings() throws SQLException {
-//		for (Statement s:stmts)
-//			s.clearWarnings();
-//	}
-//
-//	public void close() throws SQLException {
-//		for (Statement s:stmts)
-//			s.close();
-//	}
-//
-//	public boolean execute(String arg0) throws SQLException {
-//		boolean ret = true;
-//		for (Statement s:stmts)
-//			ret = s.execute(arg0) & ret;
-//		return ret;
-//	}
-//
-//	public boolean execute(String arg0, int arg1) throws SQLException {
-//		boolean ret = true;
-//		for (Statement s:stmts)
-//			ret = s.execute(arg0, arg1) & ret;
-//		return ret;
-//	}
-//
-//	public boolean execute(String arg0, int[] arg1) throws SQLException {
-//		boolean ret = true;
-//		for (Statement s:stmts)
-//			ret = s.execute(arg0, arg1) & ret;
-//		return ret;
-//	}
-//
-//	public boolean execute(String arg0, String[] arg1) throws SQLException {
-//		boolean ret = true;
-//		for (Statement s:stmts)
-//			ret = s.execute(arg0, arg1) & ret;
-//		return ret;
-//	}
-//
-//	public int[] executeBatch() throws SQLException {
-//		int[] ret = new int[0];
-//		for (Statement s:stmts) {
-//			int[] tmp = s.executeBatch();
-//			ret = new int[ret.length + tmp.length];
-//			System.arraycopy(tmp, 0, ret, ret.length-tmp.length, tmp.length);
-//		}
-//		return ret;
-//	}
-//
-//	public ResultSet executeQuery(String arg0) throws SQLException {
-//		MultiResultSet rs = new MultiResultSet();
-//		for (Statement s:stmts)
-//			rs.add(s.executeQuery(arg0));
-//		return rs;
-//	}
-//
-//	public int executeUpdate(String arg0) throws SQLException {
-//		int ret = 0;
-//		for (Statement s:stmts)
-//			ret += s.executeUpdate(arg0);
-//		return ret;
-//	}
-//
-//	public int executeUpdate(String arg0, int arg1) throws SQLException {
-//		int ret = 0;
-//		for (Statement s:stmts)
-//			ret += s.executeUpdate(arg0, arg1);
-//		return ret;
-//	}
-//
-//	public int executeUpdate(String arg0, int[] arg1) throws SQLException {
-//		int ret = 0;
-//		for (Statement s:stmts)
-//			ret += s.executeUpdate(arg0, arg1);
-//		return ret;
-//	}
-//
-//	public int executeUpdate(String arg0, String[] arg1) throws SQLException {
-//		int ret = 0;
-//		for (Statement s:stmts)
-//			ret += s.executeUpdate(arg0, arg1);
-//		return ret;
-//	}
-//
-//	public Connection getConnection() throws SQLException {
-//		return con;
-//	}
-//
-//	public int getFetchDirection() throws SQLException {
-//		
-//		return 0;
-//	}
-//
-//	public int getFetchSize() throws SQLException {
-//		return stmts.get(0).getFetchSize();
-//	}
-//
-//	public ResultSet getGeneratedKeys() throws SQLException {
-//		throw new UnsupportedOperationException();
-//	}
-//
-//	public int getMaxFieldSize() throws SQLException {
-//		return stmts.get(0).getMaxFieldSize();
-//	}
-//
-//	public int getMaxRows() throws SQLException {
-//		return stmts.get(0).getMaxRows();
-//	}
-//
-//	public boolean getMoreResults() throws SQLException {
-//		// TODO Auto-generated method stub
-//		return false;
-//	}
-//
-//	public boolean getMoreResults(int arg0) throws SQLException {
-//		// TODO Auto-generated method stub
-//		return false;
-//	}
-//
-//	public int getQueryTimeout() throws SQLException {
-//		return stmts.get(0).getQueryTimeout();
-//	}
-//
-//	public ResultSet getResultSet() throws SQLException {
-//		MultiResultSet rs = new MultiResultSet();
-//		for (Statement s:stmts)
-//			rs.add(s.getResultSet());
-//		return rs;
-//	}
-//
-//	public int getResultSetConcurrency() throws SQLException {
-//		return stmts.get(0).getResultSetConcurrency();
-//	}
-//
-//	public int getResultSetHoldability() throws SQLException {
-//		return stmts.get(0).getResultSetHoldability();
-//	}
-//
-//	public int getResultSetType() throws SQLException {
-//		return stmts.get(0).getResultSetType();
-//	}
-//
-//	public int getUpdateCount() throws SQLException {
-//		return stmts.get(0).getUpdateCount();
-//	}
-//
-//	public SQLWarning getWarnings() throws SQLException {
-//		// TODO Auto-generated method stub
-//		return null;
-//	}
-//
-//	public void setCursorName(String name) throws SQLException {
-//		for (Statement s:stmts)
-//			s.setCursorName(name);
-//	}
-//
-//	public void setEscapeProcessing(boolean flag) throws SQLException {
-//		for (Statement s:stmts)
-//			s.setEscapeProcessing(flag);
-//	}
-//
-//	public void setFetchDirection(int dir) throws SQLException {
-//		for (Statement s:stmts)
-//			s.setFetchDirection(dir);
-//	}
-//
-//	public void setFetchSize(int size) throws SQLException {
-//		for (Statement s:stmts)
-//			s.setFetchSize(size);
-//	}
-//
-//	public void setMaxFieldSize(int size) throws SQLException {
-//		for (Statement s:stmts)
-//			s.setMaxFieldSize(size);
-//	}
-//
-//	public void setMaxRows(int n) throws SQLException {
-//		for (Statement s:stmts)
-//			s.setMaxFieldSize(n);
-//	}
-//	
-//	public void setQueryTimeout(int n) throws SQLException {
-//		for (Statement s:stmts)
-//			s.setMaxFieldSize(n);
-//	}
 }

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java?rev=605462&r1=605461&r2=605462&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
(original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
Wed Dec 19 00:17:31 2007
@@ -67,7 +67,12 @@
     		q.setContext(ctx); 
     }
 
-	
+	/**
+	 * Executes queries on multiple databases.
+	 * 
+	 * @author Pinaki Poddar 
+	 *
+	 */
 	public static class ParallelExecutor extends 
 		ExpressionStoreQuery.DataStoreExecutor {
 		private List<Executor> executors = new ArrayList<Executor>();

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/package.html
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/package.html?rev=605462&r1=605461&r2=605462&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/package.html (original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/package.html Wed Dec 19 00:17:31
2007
@@ -1,4 +1,8 @@
+<HTML>
+<BODY>
 Extended OpenJPA Interfaces for distributed databases.
 
 This package contains interface definitions for distribution policy and
 distributed configuration.
+</BODY>
+</HTML>
\ No newline at end of file

Added: labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestBasic.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestBasic.java?rev=605462&view=auto
==============================================================================
--- labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestBasic.java (added)
+++ labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestBasic.java Wed Dec 19 00:17:31
2007
@@ -0,0 +1,163 @@
+package org.apache.openjpa.slice;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Persistence;
+
+import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.persistence.EntityManagerImpl;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.slice.DistributedConfiguration;
+import org.apache.openjpa.slice.jdbc.DistributedJDBCBrokerFactory;
+import org.apache.openjpa.slice.jdbc.DistributedJDBCConfiguration;
+import org.apache.openjpa.slice.jdbc.DistributedJDBCConfigurationImpl;
+
+import domain.Address;
+import domain.PObject;
+import domain.Person;
+
+import junit.framework.TestCase;
+
+public class TestBasic extends SingleEMFTestCase {
+	private static String persistenceUnitName = "slice";
+
+	public void setUp() throws Exception {
+		super.setUp(PObject.class, Person.class, Address.class);
+	}
+	
+	public void tearDown() throws Exception {
+		// do not invoke super -- it deletes the data
+	}
+	
+	/**
+	 * Tests that user-level configurations are set.
+	 */
+	public void testConfig() {
+		assertTrue(emf.getConfiguration() instanceof DistributedConfiguration);
+		DistributedConfiguration conf = (DistributedConfiguration)emf.getConfiguration();
+		assertTrue(conf.getConnectionURLs().length>1);
+		String brokerFactory = conf.getBrokerFactory();
+		assertTrue(brokerFactory.equals("slice") || 
+				   brokerFactory.equals(DistributedJDBCBrokerFactory.class.getName()));
+		assertNotNull(conf.getDistributionPolicyInstance());
+	}
+	
+	PObject persist() {
+		EntityManager em = emf.createEntityManager();
+		int value = (int)(System.currentTimeMillis()%100);
+		PObject pc = new PObject();
+		em.getTransaction().begin();
+		em.persist(pc);
+		pc.setValue(value);
+		em.getTransaction().commit();
+		em.clear();
+		return pc;
+	}
+
+	
+	/**
+	 * Stores and finds the same object.
+	 */
+	public void testFind() {
+		PObject pc = persist();
+		int value = pc.getValue();
+		
+		EntityManager em = emf.createEntityManager();
+		em.getTransaction().begin();
+		PObject pc2 = em.find(PObject.class, pc.getId());
+		assertNotNull(pc2);
+		assertNotEquals(pc, pc2);
+		assertEquals(pc.getId(), pc2.getId());
+		assertEquals(value, pc2.getValue());
+	}
+	
+	public void testPersistIndependentObjects() {
+		int before = count(PObject.class);
+		EntityManager em = emf.createEntityManager();
+		int N = 2;
+		long start = System.currentTimeMillis();
+		em.getTransaction().begin();
+		for (int i=0; i<N; i++)
+			em.persist(new PObject(start++));
+		em.getTransaction().commit();
+		em.clear();
+		int after = count(PObject.class);
+		assertEquals(before+N, after);
+	}
+	
+	public void testPersistConnectedObjectGraph() {
+		Person p1 = new Person("A");
+		Person p2 = new Person("B");
+		Person p3 = new Person("C");
+		Address a1 = new Address("Rome", 12345);
+		Address a2 = new Address("San Francisco", 23456);
+		Address a3 = new Address("New York", 34567);
+		p1.setAddress(a1);
+		p2.setAddress(a2);
+		p3.setAddress(a3);
+		
+		EntityManager em = emf.createEntityManager();
+		em.getTransaction().begin();
+		em.persist(p1);
+		em.persist(p2);
+		em.persist(p3);
+		em.getTransaction().commit();
+		
+		em.clear();
+		
+		em = emf.createEntityManager();
+		List<Person> persons = em.createQuery("SELECT p FROM Person p WHERE p.name=?1").
+			setParameter(1, "A").getResultList();
+		List<Address> addresses = em.createQuery("SELECT a FROM Address a").getResultList();
+		for (Address pc:addresses) {
+			System.err.println(pc.getCity() + ":" + pc.getOwner().getName());
+		}
+		for (Person pc:persons) {
+			System.err.println(pc.getName() + ":" + pc.getAddress().getCity());
+		}
+	}
+	
+	/**
+	 * Merge only works if the distribution policy assigns the correct slice
+	 * from which the instance was fetched.
+	 */
+	public void testMerge() {
+		PObject pc = persist();
+		int value = pc.getValue();
+		pc.setValue(value+1);
+		assertNotNull(pc);
+		EntityManager em = emf.createEntityManager();
+		em.getTransaction().begin();
+		PObject pc2 = em.merge(pc);
+		em.getTransaction().commit();
+		em.clear();
+		
+		assertNotNull(pc2);
+		assertNotEquals(pc, pc2);
+		assertEquals(pc.getId(), pc2.getId());
+		assertEquals(value+1, pc2.getValue());
+	}
+	
+	/**
+	 * Count number of instances of given type.
+	 * @return
+	 */
+	int count(Class type) {
+		return count("SELECT p FROM " + type.getSimpleName() + " p");
+	}
+	
+	int count(String query) {
+		EntityManager em = emf.createEntityManager();
+		return em.createQuery(query).getResultList().size();
+	}
+	
+    protected String getPersistenceUnitName() {
+        return persistenceUnitName;
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message