You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by pp...@apache.org on 2008/01/25 21:32:01 UTC

svn commit: r615334 - in /labs/fluid/slice/src: main/java/org/apache/openjpa/slice/ main/java/org/apache/openjpa/slice/jdbc/ main/java/org/apache/openjpa/slice/transaction/ main/resources/org/apache/openjpa/slice/jdbc/ test/java/test/org/apache/openjpa...

Author: ppoddar
Date: Fri Jan 25 12:31:59 2008
New Revision: 615334

URL: http://svn.apache.org/viewvc?rev=615334&view=rev
Log:
Configuable Transaction Manager, Names and Master

Added:
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/Slice.java
Modified:
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributedBrokerImpl.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributedConfiguration.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributionPolicy.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfiguration.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfigurationImpl.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreManager.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/SliceStoreManager.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/transaction/DistributedTransactionManager.java
    labs/fluid/slice/src/main/java/org/apache/openjpa/slice/transaction/NaiveTransactionManager.java
    labs/fluid/slice/src/main/resources/org/apache/openjpa/slice/jdbc/localizer.properties
    labs/fluid/slice/src/test/java/test/org/apache/openjpa/persistence/SingleEMFTestCase.java
    labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/TestBasic.java
    labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/TestConfiguration.java
    labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/policy/EvenOddDistributionPolicy.java
    labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/policy/UserDistributionPolicy.java
    labs/fluid/slice/src/test/resources/META-INF/persistence.xml

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributedBrokerImpl.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributedBrokerImpl.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributedBrokerImpl.java (original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributedBrokerImpl.java Fri Jan 25 12:31:59 2008
@@ -72,11 +72,11 @@
 				(DistributedConfiguration) getConfiguration();
 		String slice =
 				(conf.getDistributionPolicyInstance().distribute(pc, conf
-						.getSliceNames(), this));
-		if (!conf.getSliceNames().contains(slice))
+						.getActiveSliceNames(), this));
+		if (!conf.getActiveSliceNames().contains(slice))
 			throw new UserException(_loc.get("bad-policy-slice", new Object[] {
 					conf.getDistributionPolicyInstance().getClass().getName(),
-					slice, pc, conf.getSliceNames() }));
+					slice, pc, conf.getActiveSliceNames() }));
 		return slice;
 	}
 }

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributedConfiguration.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributedConfiguration.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributedConfiguration.java (original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/DistributedConfiguration.java Fri Jan 25 12:31:59 2008
@@ -36,18 +36,39 @@
  */
 public interface DistributedConfiguration extends OpenJPAConfiguration {
 	/**
-	 * Gets the name of the available slices. This list is determined by the
-	 * configuration properties.
-	 * A configuration property <code>slice.XYZ</code> will be registered as
-	 * a slice named <code>XYZ</code>. 
+	 * Gets the active slice identifiers. This list is determined by the
+	 * configuration properties either by explicit listing in 
+	 * <code>slice.Names</code> property or by scanning <code>slice.*.*</code>
+	 * properties.
+	 * <br> 
+	 * The ordering of the slice identifiers is determined when they are
+	 * specified explicitly in <code>slice.Names</code> property or 
+	 * ordered alphabetically when found by scanning the properties.
+	 * <br>
+	 * This list always returns the identifiers that are <em>active</em>, slices
+	 * that can not be connected to are not included in this list.
 	 */
-	List<String> getSliceNames();
+	List<String> getActiveSliceNames();
 	
 	/**
-	 * Gets the configuration for a given slice.
-	 * 
+	 * Gets the available slice identifiers irrespective of their status.
+	 * @return
 	 */
-	OpenJPAConfiguration getSlice(String sliceName);
+    List<String> getAvailableSliceNames();
+
+	
+	/**
+	 * Gets the slices of given status.
+	 * @param statuses list of status flags. If null, returns all slices 
+	 * irrespective of status;
+	 */
+	List<Slice> getSlices(Slice.Status...statuses);
+	
+	/**
+	 * Gets the Slice for a given name.
+	 * Exception is raised if the given slice is not configured.
+	 */
+	Slice getSlice(String sliceName);
 	
 	/**
 	 * Gets the policy that governs how new instances will be distributed across

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=615334&r1=615333&r2=615334&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 Fri Jan 25 12:31:59 2008
@@ -18,12 +18,12 @@
  */
 package org.apache.openjpa.slice;
 
-import java.util.Set;
+import java.util.List;
 
 
 /**
- * Policy to select one of the physical datastore referred as <em>slice</em>
- * in which a persistent instance will be stored.
+ * Policy to select one of the physical databases referred as <em>slice</em>
+ * in which a given persistent instance will be stored.
  *  
  * @author Pinaki Poddar 
  *
@@ -38,7 +38,7 @@
 	 * 
 	 * @return identifier of the slice. This name must match one of the
 	 * configured slice names. 
-	 * @see DistributedConfiguration#getSliceNames()
+	 * @see DistributedConfiguration#getActiveSliceNames()
 	 */
-	String distribute(Object pc, Set<String> slices, Object context);
+	String distribute(Object pc, List<String> slices, Object context);
 }

Added: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/Slice.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/Slice.java?rev=615334&view=auto
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/Slice.java (added)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/Slice.java Fri Jan 25 12:31:59 2008
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.    
+ */
+package org.apache.openjpa.slice;
+
+import org.apache.openjpa.conf.OpenJPAConfiguration;
+
+/**
+ * Represents a database slice.
+ * 
+ * @author Pinaki Poddar 
+ *
+ */
+public class Slice implements Comparable<Slice> {
+    public enum Status {NOT_INITIALIZED, ACTIVE, INACTIVE, EXCLUDED}; 
+    
+    private final String name;
+    private transient final OpenJPAConfiguration conf;
+    private transient Status status;
+    
+    public Slice(String name, OpenJPAConfiguration conf) {
+        this.name = name;
+        this.conf = conf;
+        this.status = Status.NOT_INITIALIZED;
+    }
+    
+    public String getName() {
+        return name;
+    }
+    
+    public OpenJPAConfiguration getConfiguration() {
+        return conf;
+    }
+    
+    public Status getStatus() {
+        return status;
+    }
+    
+    public void setStatus(Status status) {
+        this.status = status;
+    }
+    
+    public boolean isActive() {
+        return status == Status.ACTIVE;
+    }
+    
+    public String toString() {
+        return name;
+    }
+    
+    public int compareTo(Slice other) {
+        return name.compareTo(other.name);
+    }
+    
+    @Override
+    public boolean equals(Object other) {
+        if (this == other) return true;
+        if (other == null) return false;
+        if (other instanceof Slice) {
+            return name.equals(((Slice)other).getName());
+        }
+        return false;
+    }
+    
+    @Override
+    public int hashCode() {
+        return name.hashCode();
+    }
+}

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfiguration.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfiguration.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfiguration.java (original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfiguration.java Fri Jan 25 12:31:59 2008
@@ -18,8 +18,11 @@
  */
 package org.apache.openjpa.slice.jdbc;
 
+import javax.transaction.TransactionManager;
+
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.slice.DistributedConfiguration;
+import org.apache.openjpa.slice.Slice;
 
 /**
  * A distributed configuration that is a ordered collection of 
@@ -29,5 +32,19 @@
  *
  */
 public interface DistributedJDBCConfiguration extends JDBCConfiguration, 
-	Iterable<JDBCConfiguration>, DistributedConfiguration {
+	DistributedConfiguration {
+    /**
+     * Gets the master slice.
+     */
+    Slice getMaster();
+    
+    /**
+     * Gets the TransactionManager instance being used.
+     */
+    TransactionManager getTransactionManagerInstance();
+    
+    /**
+     * Gets the alias for TransactionManager being used.
+     */
+    String getTransactionManager();
 }

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfigurationImpl.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfigurationImpl.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfigurationImpl.java (original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfigurationImpl.java Fri Jan 25 12:31:59 2008
@@ -21,33 +21,37 @@
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
 
 import javax.sql.DataSource;
 import javax.sql.XADataSource;
+import javax.transaction.TransactionManager;
 
+import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
+import org.apache.openjpa.jdbc.kernel.UpdateManager;
 import org.apache.openjpa.jdbc.schema.DataSourceFactory;
 import org.apache.openjpa.lib.conf.BooleanValue;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.lib.conf.ObjectValue;
 import org.apache.openjpa.lib.conf.PluginValue;
 import org.apache.openjpa.lib.conf.StringListValue;
 import org.apache.openjpa.lib.conf.StringValue;
 import org.apache.openjpa.lib.jdbc.DecoratingDataSource;
 import org.apache.openjpa.lib.jdbc.DelegatingDataSource;
 import org.apache.openjpa.lib.log.Log;
+import org.apache.openjpa.lib.log.LogFactory;
+import org.apache.openjpa.lib.log.LogFactoryImpl;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.slice.DistributedBrokerImpl;
 import org.apache.openjpa.slice.DistributionPolicy;
+import org.apache.openjpa.slice.Slice;
+import org.apache.openjpa.slice.SliceVersion;
+import org.apache.openjpa.slice.transaction.NaiveTransactionManager;
 import org.apache.openjpa.util.UserException;
 
 /**
@@ -59,14 +63,15 @@
 public class DistributedJDBCConfigurationImpl extends JDBCConfigurationImpl
         implements DistributedJDBCConfiguration {
 
-    private final List<JDBCConfiguration> _sliceConfigs =
-            new ArrayList<JDBCConfiguration>();
-    private final List<String> _sliceNames = new ArrayList<String>();
+    private final List<Slice> _slices = new ArrayList<Slice>();
+    private List<String> _activeSliceNames = new ArrayList<String>();
+    private Slice _master;
+    
     private DecoratingDataSource virtualDataSource;
-
     protected BooleanValue lenient;
     protected StringValue master;
     protected StringListValue names;
+    protected ObjectValue txnMgr;
     protected PluginValue distributionPolicyPlugin;
 
     private static Localizer _loc =
@@ -80,39 +85,92 @@
      */
     public DistributedJDBCConfigurationImpl(ConfigurationProvider cp) {
         super(true, false);
+        Map p = cp.getProperties();
+        String pUnit = getPersistenceUnitName(p);
+        setDiagnosticContext(pUnit);
+        Log log = getConfigurationLog();
+        log.info(_loc.get("config-init", SliceVersion.VERSION));
+        
         brokerPlugin.setString(DistributedBrokerImpl.class.getName());
         distributionPolicyPlugin = addPlugin("DistributionPolicy", true);
         distributionPolicyPlugin.setDynamic(true);
         lenient = addBoolean("Lenient");
         master = addString("Master");
         names = addStringList("Names");
-        setSlices(cp.getProperties());
+        txnMgr = addPlugin("TransactionManager", true);
+        txnMgr.setAlias("naive", "org.apache.openjpa.slice.transaction.NaiveTransactionManager");
+        txnMgr.setAlias("xa", "org.apache.openjpa.slice.transaction.DistributedTransactionManager");
+        txnMgr.setAlias("jndi", "org.apache.openjpa.slice.transaction.LookUpTransactionManager");
+        txnMgr.setDefault("naive");
+        txnMgr.setString("naive");
+        setSlices(p);
+    }
+    
+    private String getPersistenceUnitName(Map p) {
+        Object unit = p.get(PREFIX_OPENJPA+id.getProperty());
+        return (unit == null) ? "?" : unit.toString();
+    }
+    
+    private void setDiagnosticContext(String unit) {
+        LogFactory logFactory = getLogFactory();
+        if (logFactory instanceof LogFactoryImpl) {
+            ((LogFactoryImpl)logFactory).setDiagnosticContext(unit);
+        }
     }
 
     /**
-     * Iterator for underlying slice configurations.
+     * Gets the name of the active slices.
      */
-    public Iterator<JDBCConfiguration> iterator() {
-        return _sliceConfigs.iterator();
+    public List<String> getActiveSliceNames() {
+        if (_activeSliceNames.isEmpty()) {
+            for (Slice slice:_slices)
+                if (slice.isActive())
+                    _activeSliceNames.add(slice.getName());
+        }
+        return _activeSliceNames;
     }
-
+    
+    /**
+     * Gets the name of the available slices.
+     */
+    public List<String> getAvailableSliceNames() {
+        List<String> result = new ArrayList<String>();
+        for (Slice slice:_slices)
+            result.add(slice.getName());
+        return result;
+    }
+    
+    /**
+     * Gets the slices of given status. Null returns all irrespective of status.
+     */
+    public List<Slice> getSlices(Slice.Status...statuses) {
+        if (statuses == null)
+            return Collections.unmodifiableList(_slices);
+        List<Slice> result = new ArrayList<Slice>();
+        for (Slice slice:_slices) {
+            for (Slice.Status status:statuses)
+                if (slice.getStatus().equals(status))
+                    result.add(slice);
+        }
+        return result;
+    }
+    
     /**
-     * Gets the name of the configured slices.
+     * Gets the master slice. 
      */
-    public List<String> getSliceNames() {
-        return _sliceNames;
+    public Slice getMaster() {
+        return _master;
     }
 
     /**
      * Get the configuration for given slice.
      */
-    public JDBCConfiguration getSlice(String slice) {
-        int i = _sliceNames.indexOf(slice);
-        if (i == -1)
-            throw new UserException(_loc.get("slice-not-found", slice,
-                    _sliceNames));
-        JDBCConfiguration result = _sliceConfigs.get(i);
-        return result;
+    public Slice getSlice(String name) {
+        for (Slice slice:_slices)
+            if (slice.getName().equals(name))
+                return slice;
+        throw new UserException(_loc.get("slice-not-found", name,
+                    getActiveSliceNames()));
     }
 
     public DistributionPolicy getDistributionPolicyInstance() {
@@ -146,9 +204,8 @@
         List<DataSource> dataSources = new ArrayList<DataSource>();
         boolean isLenient = lenient.get();
         boolean isXA = true;
-        List<String> badSlices = new ArrayList<String>();
-        for (String slice : _sliceNames) {
-            JDBCConfiguration conf = getSlice(slice);
+        for (Slice slice : _slices) {
+            JDBCConfiguration conf = (JDBCConfiguration)slice.getConfiguration();
             Log log = conf.getConfigurationLog();
             String url = getConnectionInfo(conf);
             if (log.isInfoEnabled())
@@ -156,28 +213,21 @@
             try {
                 DataSource ds = DataSourceFactory.newDataSource(conf, false);
                 DecoratingDataSource dds = new DecoratingDataSource(ds);
-                ds =
-                        DataSourceFactory.installDBDictionary(conf
-                                .getDBDictionaryInstance(), dds, conf, false);
-                if (verifyDataSource(isLenient, badSlices, slice, ds)) {
+                ds = DataSourceFactory.installDBDictionary(
+                        conf.getDBDictionaryInstance(), dds, conf, false);
+                if (verifyDataSource(slice, ds)) {
                     dataSources.add(ds);
                     isXA &= isXACompliant(ds);
                 }
-            } catch (Exception ex) {
-                handleBadConnection(isLenient, badSlices, slice, ex);
+            } catch (Throwable ex) {
+                handleBadConnection(isLenient, slice, ex);
             }
         }
-        removeBadSlices(badSlices);
         DistributedDataSource result = new DistributedDataSource(dataSources);
-        Log log = getConfigurationLog();
-        if (isXA)
-            log.info(_loc.get("slice-xa-enabled", getSliceNames()));
-        else
-            log.warn(_loc.get("slice-xa-disabled", getSliceNames()));
         return result;
     }
 
-    String getConnectionInfo(JDBCConfiguration conf) {
+    String getConnectionInfo(OpenJPAConfiguration conf) {
         String result = conf.getConnectionURL();
         if (result == null) {
             result = conf.getConnectionDriverName();
@@ -190,27 +240,27 @@
 
     boolean isXACompliant(DataSource ds) {
         if (ds instanceof DelegatingDataSource)
-            return ((DelegatingDataSource) ds).getInnermostDelegate() instanceof XADataSource;
+            return ((DelegatingDataSource) ds).getInnermostDelegate() 
+               instanceof XADataSource;
         return ds instanceof XADataSource;
     }
 
     /**
      * Verify that a connection can be established to the given slice. If
-     * connection can not be established then process the bad slice in
-     * {@link #handleBadConnection(boolean, List, JDBCConfiguration)} method.
+     * connection can not be established then slice is set to INACTIVE state.
      */
-    private boolean verifyDataSource(boolean isLenient, List<String> badSlices,
-            String badSlice, DataSource ds) {
+    private boolean verifyDataSource(Slice slice, DataSource ds) {
         Connection con = null;
         try {
             con = ds.getConnection();
+            slice.setStatus(Slice.Status.ACTIVE);
             if (con == null) {
-                handleBadConnection(isLenient, badSlices, badSlice, null);
+                slice.setStatus(Slice.Status.INACTIVE);
                 return false;
             }
             return true;
         } catch (SQLException ex) {
-            handleBadConnection(isLenient, badSlices, badSlice, ex);
+            slice.setStatus(Slice.Status.INACTIVE);
             return false;
         } finally {
             if (con != null)
@@ -223,28 +273,12 @@
     }
 
     /**
-     * Remove the given set of bad slices.
-     * 
-     */
-    private void removeBadSlices(List<String> badSlices) {
-        if (badSlices == null)
-            return;
-        for (String bad : badSlices) {
-            int i = _sliceNames.indexOf(bad);
-            if (i == -1)
-                continue;
-            _sliceNames.remove(i);
-            _sliceConfigs.remove(i);
-        }
-    }
-
-    /**
      * Either throw a user exception or add the configuration to the given list,
      * based on <code>isLenient</code>.
      */
-    private void handleBadConnection(boolean isLenient, List<String> badSlices,
-            String slice, Throwable ex) {
-        JDBCConfiguration conf = getSlice(slice);
+    private void handleBadConnection(boolean isLenient, Slice slice,
+            Throwable ex) {
+        OpenJPAConfiguration conf = slice.getConfiguration();
         String url = conf.getConnectionURL();
         Log log = getLog(LOG_RUNTIME);
         if (isLenient) {
@@ -254,7 +288,6 @@
             } else {
                 log.warn(_loc.get("slice-connect-warn", slice, url));
             }
-            badSlices.add(slice);
         } else if (ex != null) {
             throw new UserException(_loc.get("slice-connect-known-error",
                     slice, url, ex), ex.getCause());
@@ -264,23 +297,22 @@
     }
 
     /**
-     * Create JDBCConfigurations for slices from the given properties.
+     * Create individual slices with configurations from the given properties.
      */
     void setSlices(Map original) {
-        findSlices(original);
+        List<String> sliceNames = findSlices(original);
         Log log = getConfigurationLog();
-        if (_sliceNames.isEmpty()) {
+        if (sliceNames.isEmpty()) {
             throw new UserException(_loc.get("slice-none-configured"));
-        } else if (log != null && log.isInfoEnabled()) {
-            log.info(_loc.get("slice-available", _sliceNames));
-        }
-        for (String key : _sliceNames) {
-            JDBCConfiguration slice = new JDBCConfigurationImpl();
-            slice.fromProperties(createSliceProperties(original, key));
-            slice.setId(PREFIX_SLICE + key);
-            _sliceConfigs.add(slice);
-            if (log != null && log.isInfoEnabled())
-                log.info(_loc.get("slice-configuration", key, slice
+        } 
+        for (String key : sliceNames) {
+            JDBCConfiguration child = new JDBCConfigurationImpl();
+            child.fromProperties(createSliceProperties(original, key));
+            child.setId(PREFIX_SLICE + key);
+            Slice slice = new Slice(key, child);
+            _slices.add(slice);
+            if (log.isTraceEnabled())
+                log.trace(_loc.get("slice-configuration", key, child
                         .toProperties(false)));
         }
         setMaster();
@@ -294,25 +326,41 @@
      * identifier and <code>abc</code> is openjpa property name. The slices
      * are then ordered alphabetically.
      */
-    private void findSlices(Map p) {
+    private List<String> findSlices(Map p) {
+        List<String> sliceNames = new ArrayList<String>();
+        
         Log log = getConfigurationLog();
-        String[] sliceNames = names.get();
-        if (sliceNames == null || sliceNames.length == 0) {
+        String key = PREFIX_SLICE+names.getProperty();
+        boolean explicit = p.containsKey(key);
+        if (explicit) {
+            String[] values = p.get(key).toString().split("\\,");
+            for (String name:values)
+                if (!sliceNames.contains(name.trim()))
+                    sliceNames.add(name.trim());
+        } else {
             if (log.isWarnEnabled())
                 log.warn(_loc.get("no-slice-names"));
-        } else {
-            for (String name:sliceNames)
-                _sliceNames.add(name);
+            sliceNames = scanForSliceNames(p);
+            Collections.sort(sliceNames);
+        }
+        if (log.isInfoEnabled()) {
+            log.info(_loc.get("slice-available", sliceNames));
         }
+        return sliceNames;
+    }
+    
+    private List<String> scanForSliceNames(Map p) {
+        List<String> sliceNames = new ArrayList<String>();
         for (Object o : p.keySet()) {
             String key = o.toString();
             if (key.startsWith(PREFIX_SLICE) && key.split("\\.").length > 2) {
                 String sliceName =
-                        chopTail(chopHead(o.toString(), PREFIX_SLICE), ".");
-                _sliceNames.add(sliceName);
+                    chopTail(chopHead(o.toString(), PREFIX_SLICE), ".");
+                if (!sliceNames.contains(sliceName))
+                    sliceNames.add(sliceName);
             }
         }
-        Collections.sort(_sliceNames);
+        return sliceNames;
     }
 
     static String chopHead(String s, String head) {
@@ -370,23 +418,35 @@
      */
     private void setMaster() {
         String masterSlice = master.get();
+        Log log = getConfigurationLog();
+        List<Slice> activeSlices = getSlices(null);
         if (masterSlice == null || masterSlice.length() == 0) {
-            Log log = getConfigurationLog();
+            _master = activeSlices.get(0);
             if (log.isWarnEnabled())
-                log.warn(_loc.get("no-master-slice"));
+                log.warn(_loc.get("no-master-slice", _master));
             return;
         }
-        int i = _sliceNames.indexOf(masterSlice);
-        if (i == -1)
-            throw new UserException(_loc.get("bad-master", master, _sliceNames));
+        for (Slice slice:activeSlices)
+            if (slice.getName().equals(masterSlice))
+                _master = slice;
+        if (_master == null) {
+            _master = activeSlices.get(0);
+        }
+    }
+    
+    public String getTransactionManager() {
+        return updateManagerPlugin.getString();
+    }
 
-        if (i == 0)
-            return;
-        JDBCConfiguration masterConf = _sliceConfigs.get(i);
-        _sliceNames.set(i, _sliceNames.get(0));
-        _sliceNames.set(0, masterSlice);
-        _sliceConfigs.set(i, _sliceConfigs.get(0));
-        _sliceConfigs.set(0, masterConf);
+    public void setUpdateManager(TransactionManager txnManager) {
+        txnMgr.set(txnManager);
+    }
 
+    public TransactionManager getTransactionManagerInstance() {
+        if (txnMgr.get() == null) {
+            txnMgr.instantiate(TransactionManager.class, this);
+        }
+        return (TransactionManager) txnMgr.get();
     }
+
 }

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreManager.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreManager.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreManager.java (original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreManager.java Fri Jan 25 12:31:59 2008
@@ -31,6 +31,7 @@
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 
+import javax.naming.ConfigurationException;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 
@@ -81,6 +82,7 @@
     private boolean isXA;
     private TransactionManager _tm;
     private final DistributedJDBCConfiguration _conf;
+    private Log _log;
     private static final Localizer _loc =
             Localizer.forPackage(DistributedStoreManager.class);
     private static ExecutorService threadPool = Executors.newCachedThreadPool();
@@ -94,12 +96,15 @@
      * get Sequence based entity identifiers.
      */
     public DistributedStoreManager(DistributedJDBCConfiguration conf) {
+        super();
         _conf = conf;
+        _log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
         _slices = new ArrayList<SliceStoreManager>();
-        for (String name : conf.getSliceNames()) {
-            SliceStoreManager slice = new SliceStoreManager(name);
+        for (String name : conf.getActiveSliceNames()) {
+            SliceStoreManager slice = new SliceStoreManager(conf.getSlice(name));
             _slices.add(slice);
-            _master = (_master == null) ? slice : _master;
+            if (slice.getName().equals(conf.getMaster().getName()))
+                _master = slice;
         }
     }
 
@@ -132,11 +137,11 @@
         PersistenceCapable pc = sm.getPersistenceCapable();
         String slice =
                 _conf.getDistributionPolicyInstance().distribute(pc,
-                        _conf.getSliceNames(), getContext());
-        if (!_conf.getSliceNames().contains(slice)) {
+                        _conf.getActiveSliceNames(), getContext());
+        if (!_conf.getActiveSliceNames().contains(slice)) {
             throw new UserException(_loc.get("bad-policy-slice", new Object[] {
                     _conf.getDistributionPolicyInstance().getClass().getName(),
-                    slice, sm.getPersistenceCapable(), _conf.getSliceNames() }));
+                    slice, sm.getPersistenceCapable(), _conf.getActiveSliceNames() }));
         }
         sm.setImplData(slice, true);
         return slice;
@@ -157,8 +162,9 @@
             JDBCStore store = ((ResultSetResult) result).getStore();
             for (SliceStoreManager slice : _slices) {
                 if (slice == store) {
-                    sm.setImplData(slice.getName(), true);
-                    return slice.getName();
+                    String sliceId = slice.getName();
+                    sm.setImplData(sliceId, true);
+                    return sliceId;
                 }
             }
         }
@@ -346,7 +352,7 @@
         // not a part of Query result load. Look into the slices till found
         for (SliceStoreManager slice : _slices) {
             if (slice.initialize(sm, state, fetch, edata)) {
-                sm.setImplData(slice, true);
+                sm.setImplData(slice.getName(), true);
                 return true;
             }
         }
@@ -424,12 +430,13 @@
      */
     public void setContext(StoreContext ctx) {
         super.setContext(ctx);
-        Iterator<JDBCConfiguration> confs = _conf.iterator();
         isXA = true;
-        for (SliceStoreManager slice : _slices) {
-            slice.setContext(ctx, confs.next());
-            isXA &= slice.isXAEnabled();
+        for (SliceStoreManager store : _slices) {
+            store.setContext(ctx, 
+                    (JDBCConfiguration)store.getSlice().getConfiguration());
+            isXA &= store.isXAEnabled();
         }
+        _tm = getTransactionManager();
     }
 
     private SliceStoreManager lookup(String name) {
@@ -444,12 +451,19 @@
     }
 
     protected TransactionManager getTransactionManager() {
-        //TODO: This method requires to be smarter to get an appropriate
-        // transaction manager. Currently it uses either of the two native
-        // transaction manager based on XA-compliance of all the resources.
-        if (_tm == null)
-            _tm = (isXA) ? new DistributedTransactionManager()
-                         : new NaiveTransactionManager();
+        if (_tm == null) {
+            _tm = getConfiguration().getTransactionManagerInstance();
+            String alias = getConfiguration().getTransactionManager();
+            boolean is2pc = !(_tm instanceof NaiveTransactionManager);
+            if (isXA) { 
+                if (!is2pc) { 
+                    _log.warn(_loc.get("resource-xa-tm-not-2pc", alias));
+                    isXA = false;
+                }
+            } else if (is2pc) {
+                throw new UserException(_loc.get("resource-not-xa-tm-2pc", alias));
+            } 
+        }
         return _tm;
     }
 

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=615334&r1=615333&r2=615334&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 Fri Jan 25 12:31:59 2008
@@ -129,7 +129,7 @@
         	boolean isAscending = ascending.length > 0;
         	boolean isUnique    = q.getContext().isUnique();
         	if (isUnique) {
-        	    return new MergedResultObjectProvider(tmp);
+        	    return new UniqueResultObjectProvider(tmp, q);
         	}
         	if (isAscending) {
         	    return new OrderingMergedResultObjectProvider(tmp, ascending, 

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/SliceStoreManager.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/SliceStoreManager.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/SliceStoreManager.java (original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/SliceStoreManager.java Fri Jan 25 12:31:59 2008
@@ -28,6 +28,7 @@
 import org.apache.openjpa.jdbc.kernel.JDBCStoreManager;
 import org.apache.openjpa.lib.jdbc.DelegatingDataSource;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.slice.Slice;
 import org.apache.openjpa.util.InternalException;
 
 /**
@@ -39,7 +40,7 @@
  *
  */
 public class SliceStoreManager extends JDBCStoreManager {
-	private final String _name;
+	private final Slice _slice;
 	private Boolean isXAEnabled;
 	private XAConnection xcon;
 	
@@ -49,15 +50,19 @@
 	/**
 	 * Construct with immutable logical name of the slice. 
 	 */
-	public SliceStoreManager(String name) {
-		_name = name;
+	public SliceStoreManager(Slice slice) {
+		_slice = slice;
 	}
 	
 	/**
-	 * Gets the name of the slice.
+	 * Gets the slice for which this receiver is working.
 	 */
+	public Slice getSlice() {
+	    return _slice;
+	}
+	
 	public String getName() {
-		return _name;
+	    return _slice.getName();
 	}
 	
 	/**
@@ -104,9 +109,5 @@
 				((DelegatingDataSource)parent).getInnermostDelegate() 
 				: parent;
 		return real;
-	}
-	
-	public String toString() {
-		return _name;
 	}
 }

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java (original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/jdbc/UniqueResultObjectProvider.java Fri Jan 25 12:31:59 2008
@@ -1,30 +1,33 @@
 package org.apache.openjpa.slice.jdbc;
 
-import java.sql.ResultSet;
-
-import org.apache.openjpa.jdbc.sql.Result;
-import org.apache.openjpa.jdbc.sql.ResultSetResult;
+import org.apache.openjpa.kernel.StoreQuery;
 import org.apache.openjpa.lib.rop.ResultObjectProvider;
+import org.apache.openjpa.util.InternalException;
 
 public class UniqueResultObjectProvider implements ResultObjectProvider {
     private final ResultObjectProvider[] _rops;
+    private final StoreQuery _query;
     private Object _single;
+    private boolean _opened;
 
-    public UniqueResultObjectProvider(ResultObjectProvider[] rops) {
+    public UniqueResultObjectProvider(ResultObjectProvider[] rops, StoreQuery q) {
         _rops = rops;
+        _query = q;
     }
     
     public boolean absolute(int pos) throws Exception {
-        // TODO Auto-generated method stub
         return false;
     }
 
     public void close() throws Exception {
         for (ResultObjectProvider rop:_rops)
             rop.close();
+        _opened = false;
     }
 
     public Object getResultObject() throws Exception {
+        if (!_opened)
+            throw new InternalException(this + " not-open");
         return _single;
     }
 
@@ -33,20 +36,24 @@
     }
 
     public boolean next() throws Exception {
-        ResultSetResult result = (ResultSetResult)_rops[0].getResultObject();
-        ResultSet rs = result.getResultSet();
-        rs.
-        return false;
+        if (!_opened) {
+            open();
+        }
+            
+        if (_single != null)
+            return false;
+        _rops[0].next();
+        _single = _rops[0].getResultObject();
+        return true;
     }
 
     public void open() throws Exception {
-        // TODO Auto-generated method stub
-
+        for (ResultObjectProvider rop:_rops)
+            rop.open();
+        _opened = true;
     }
 
     public void reset() throws Exception {
-        // TODO Auto-generated method stub
-
     }
 
     public int size() throws Exception {
@@ -54,6 +61,6 @@
     }
 
     public boolean supportsRandomAccess() {
-         return true;
+         return false;
     }
 }

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/transaction/DistributedTransactionManager.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/transaction/DistributedTransactionManager.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/transaction/DistributedTransactionManager.java (original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/transaction/DistributedTransactionManager.java Fri Jan 25 12:31:59 2008
@@ -22,7 +22,6 @@
 import static javax.transaction.xa.XAResource.TMNOFLAGS;
 import static javax.transaction.xa.XAResource.TMSUCCESS;
 
-import java.util.HashSet;
 import java.util.Set;
 
 import javax.transaction.HeuristicMixedException;

Modified: labs/fluid/slice/src/main/java/org/apache/openjpa/slice/transaction/NaiveTransactionManager.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/java/org/apache/openjpa/slice/transaction/NaiveTransactionManager.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/main/java/org/apache/openjpa/slice/transaction/NaiveTransactionManager.java (original)
+++ labs/fluid/slice/src/main/java/org/apache/openjpa/slice/transaction/NaiveTransactionManager.java Fri Jan 25 12:31:59 2008
@@ -31,6 +31,7 @@
         DistributedNaiveTransaction txn = getTransaction(false);
         Set<SliceStoreManager> slices = txn.getEnlistedResources();
         for (SliceStoreManager slice : slices) {
+            slice.getConnection();
             slice.begin();
         }
     }

Modified: labs/fluid/slice/src/main/resources/org/apache/openjpa/slice/jdbc/localizer.properties
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/main/resources/org/apache/openjpa/slice/jdbc/localizer.properties?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/main/resources/org/apache/openjpa/slice/jdbc/localizer.properties (original)
+++ labs/fluid/slice/src/main/resources/org/apache/openjpa/slice/jdbc/localizer.properties Fri Jan 25 12:31:59 2008
@@ -14,11 +14,10 @@
 slice-connect: Connecting to slice "{0}" at URL "{1}"
 slice-connect-warn: Failed to connect to slice "{0}". Slice "{0}" will be \
 	ignored as configuration is set as lenient.
-slice-connect-known-warn: Failed to connect to slice "{0}" due to "{2}. \
+slice-connect-known-warn: Failed to connect to due to "{2}. \
 	Slice "{0}" will be ignored as configuration is set as lenient.
-slice-connect-error: Failed to connect to slice "{0}" at URL "{1}"
-slice-connect-known-error: Failed to connect to slice "{0}" at URL "{1} due to \
-	{2}"
+slice-connect-error: Failed to connect to URL "{1}"
+slice-connect-known-error: Failed to connect to URL "{1} due to {2}
 bad-policy-slice:Distribution policy "{0}" has returned invalid slice \
 	"{1}" for "{2}". The valid slices are {3}. This error may happen \
 	when one or more of the originally configured slices are unavailable \
@@ -26,16 +25,24 @@
 slice-xa-enabled: All slices "{0}" is XA-complaint and hence store transaction \
 	will use a two-phase commit protocol even if the persistent unit is \
 	configured for non-JTA transaction.
-slice-xa-disabled: Not all slices "{0}" is XA-complaint and hence store \
+slice-xa-disabled: Not all active slices "{0}" is XA-complaint and hence store \
 	transaction will not use a two-phase commit protocol. If persistent unit \
 	is configured for JTA transaction then the slices will participate in \
-	global transaction but otherwise the atomic nature of commit across all \ 
+	global transaction but otherwise the atomic nature of commit across all \
 	slices is not guaranteed.  
 two-phase: "{3}".{0}"(xid=[{4}]] Connection={1} XAConnection={2} 
 factory-init: Starting {0}
+config-init: Configuring Slice {0}
 no-slice-names: Slice identifiers are not listed in [slice.Names] property. \
 	The configuration will be scanned to determine slice identifiers.
 no-master-slice: No master slice has been configured explicitly in \
-	[slice.Master] property. The first slice in the list of configured slices \
-	will be used as master. 
-	 
\ No newline at end of file
+	[slice.Master] property. The first slice "{0}" in the list of configured \
+	slices will be used as master. 
+resource-xa-tm-not-2pc: All slices is using XA-complaint driver but the \
+	configured "{0}" transaction manager is not capable of enlisting XA-aware \
+	resources. See slice.TransactionManager property documentation to  \
+	configure XA-aware Transaction Manager capable for two-phase commit.
+resource-not-xa-tm-2pc: One or more slices is not using XA-complaint driver \
+	but the configured "{0}" transaction manager can only enlist XA-aware \
+	resource. 
+		  	 
\ No newline at end of file

Modified: labs/fluid/slice/src/test/java/test/org/apache/openjpa/persistence/SingleEMFTestCase.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/java/test/org/apache/openjpa/persistence/SingleEMFTestCase.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/test/java/test/org/apache/openjpa/persistence/SingleEMFTestCase.java (original)
+++ labs/fluid/slice/src/test/java/test/org/apache/openjpa/persistence/SingleEMFTestCase.java Fri Jan 25 12:31:59 2008
@@ -24,7 +24,7 @@
 public abstract class SingleEMFTestCase
     extends PersistenceTestCase {
 
-    protected OpenJPAEntityManagerFactorySPI emf;
+    protected static OpenJPAEntityManagerFactorySPI emf;
 
     /**
      * Call {@link #setUp(Object...)} with no arguments so that the emf

Modified: labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/TestBasic.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/TestBasic.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/TestBasic.java (original)
+++ labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/TestBasic.java Fri Jan 25 12:31:59 2008
@@ -107,14 +107,16 @@
 		em.clear();
 		
 		em = emf.createEntityManager();
-		List<Person> persons = em.createQuery("SELECT p FROM Person p WHERE p.name=?1 ORDER BY p.address.city").
+		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());
+			assertNotNull(pc.getCity());
+			assertNotNull(pc.getOwner().getName());
 		}
 		for (Person pc:persons) {
-			System.err.println(pc.getName() + ":" + pc.getAddress().getCity());
+		    assertNotNull(pc.getName());
+		    assertNotNull(pc.getAddress().getCity());
 		}
 	}
 	

Modified: labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/TestConfiguration.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/TestConfiguration.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/TestConfiguration.java (original)
+++ labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/TestConfiguration.java Fri Jan 25 12:31:59 2008
@@ -9,24 +9,28 @@
 import org.apache.openjpa.slice.DistributedBrokerImpl;
 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.transaction.NaiveTransactionManager;
 
 import test.org.apache.openjpa.persistence.SingleEMFTestCase;
 
 public class TestConfiguration extends SingleEMFTestCase {
 	/**
 	 * Tests that user-level configurations are set.
+	 * 
 	 */
 	public void testConfig() {
 		assertTrue(emf.getConfiguration() instanceof DistributedConfiguration);
-		DistributedConfiguration conf = (DistributedConfiguration)emf.getConfiguration();
-		List<String> slices = conf.getSliceNames();
+		DistributedJDBCConfiguration conf = (DistributedJDBCConfiguration)emf.getConfiguration();
+		List<String> slices = conf.getAvailableSliceNames();
 		assertTrue(slices.size()>1);
 		assertTrue(slices.contains("One"));
         assertTrue(slices.contains("Two"));
         assertTrue(slices.contains("Three"));
-		assertEquals("jdbc:mysql://localhost/slice1", conf.getSlice("One").getConnectionURL());
-        assertEquals("jdbc:mysql://localhost/slice2", conf.getSlice("Two").getConnectionURL());
-        assertEquals("jdbc:mysql://localhost/slice3", conf.getSlice("Three").getConnectionURL());
+		assertEquals("jdbc:mysql://localhost/slice1", conf.getSlice("One").getConfiguration().getConnectionURL());
+        assertEquals("jdbc:mysql://localhost/slice2", conf.getSlice("Two").getConfiguration().getConnectionURL());
+        assertEquals("jdbc:mysql://localhost/slice3", conf.getSlice("Three").getConfiguration().getConnectionURL());
+        assertTrue(conf.getTransactionManagerInstance() instanceof NaiveTransactionManager);
 		BrokerFactory bf = ((EntityManagerFactoryImpl)emf).getBrokerFactory();
 		Broker broker = bf.newBroker();
 		assertEquals(DistributedJDBCBrokerFactory.class, bf.getClass());
@@ -36,7 +40,7 @@
 		
 		emf.createEntityManager();
 		
-        slices = conf.getSliceNames();
+        slices = conf.getActiveSliceNames();
         assertTrue(slices.size()>1);
         assertTrue(slices.contains("One"));
         assertTrue(slices.contains("Two"));

Modified: labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/policy/EvenOddDistributionPolicy.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/policy/EvenOddDistributionPolicy.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/policy/EvenOddDistributionPolicy.java (original)
+++ labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/policy/EvenOddDistributionPolicy.java Fri Jan 25 12:31:59 2008
@@ -1,13 +1,13 @@
 package test.org.apache.openjpa.slice.policy;
 
-import java.util.Set;
+import java.util.List;
 
 import org.apache.openjpa.slice.DistributionPolicy;
 
 import test.domain.PObject;
 
 public class EvenOddDistributionPolicy implements DistributionPolicy {
-    public String distribute(Object pc, Set<String> slices, Object context) {
+    public String distribute(Object pc, List<String> slices, Object context) {
         if (pc instanceof PObject) {
             int v = ((PObject)pc).getValue();
             return (v%2 == 0) ? "Even" : "Odd";

Modified: labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/policy/UserDistributionPolicy.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/policy/UserDistributionPolicy.java?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/policy/UserDistributionPolicy.java (original)
+++ labs/fluid/slice/src/test/java/test/org/apache/openjpa/slice/policy/UserDistributionPolicy.java Fri Jan 25 12:31:59 2008
@@ -18,11 +18,11 @@
  */
 package test.org.apache.openjpa.slice.policy;
 
+import java.util.List;
 import java.util.Set;
 
 import org.apache.openjpa.slice.DistributionPolicy;
 
-import test.domain.Address;
 import test.domain.PObject;
 import test.domain.Person;
 
@@ -46,7 +46,7 @@
 	 * the same slice as its owner Person. 
 	 * 
 	 */
-	public String distribute(Object pc, Set<String> slices, Object context) {
+	public String distribute(Object pc, List<String> slices, Object context) {
 		assertValidSlices(slices);
 		if (pc instanceof PObject)
 			return distribute((PObject)pc);
@@ -56,7 +56,7 @@
 		throw new RuntimeException("No policy for " + pc.getClass());
 	}
 	
-	void assertValidSlices(Set<String> slices) {
+	void assertValidSlices(List<String> slices) {
 		if (slices.contains("One") && slices.contains("Two"))
 			return;
 		throw new RuntimeException("This policy assumes two slices named " +

Modified: labs/fluid/slice/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/resources/META-INF/persistence.xml?rev=615334&r1=615333&r2=615334&view=diff
==============================================================================
--- labs/fluid/slice/src/test/resources/META-INF/persistence.xml (original)
+++ labs/fluid/slice/src/test/resources/META-INF/persistence.xml Fri Jan 25 12:31:59 2008
@@ -7,12 +7,15 @@
    <persistence-unit name="per-slice">
       <properties>
          <property name="openjpa.BrokerFactory" value="slice"/>
+         <property name="slice.Names" value="One,Two, Three"/>
          <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
          <property name="slice.One.ConnectionURL" value="jdbc:mysql://localhost/slice1"/>
          <property name="slice.Two.ConnectionURL" value="jdbc:mysql://localhost/slice2"/>
          <property name="slice.Three.ConnectionURL" value="jdbc:mysql://localhost/slice3"/>
          <property name="slice.DistributionPolicy" value="test.org.apache.openjpa.slice.policy.UserDistributionPolicy"/>
          <property name="slice.Lenient" value="true"/>
+         <property name="slice.TransactionManager" value="naive"/>
+         <property name="openjpa.Log" value="DefaultLevel=WARN, Enhance=TRACE"/>
       </properties>
    </persistence-unit>
 
@@ -21,13 +24,20 @@
       <properties>
          <property name="openjpa.BrokerFactory" value="slice"/>
          <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
+
+         <property name="slice.Names" value="One,Two"/>
+         <property name="slice.DistributionPolicy" value="test.org.apache.openjpa.slice.policy.UserDistributionPolicy"/>
+         <property name="slice.TransactionManager" value="xa"/>
+         
          <property name="slice.One.ConnectionDriverName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"/>
          <property name="slice.One.ConnectionProperties" value="url=jdbc:mysql://localhost/slice1"/>
          <property name="slice.Two.ConnectionDriverName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"/>
          <property name="slice.Two.ConnectionProperties" value="url=jdbc:mysql://localhost/slice2"/>
-         <property name="slice.DistributionPolicy" value="test.org.apache.openjpa.slice.policy.UserDistributionPolicy"/>
+         
+         
          <property name="openjpa.TransactionMode" value="local"/>
          <property name="openjpa.Multithreaded" value="false"/>
+         <property name="openjpa.Log" value="DefaultLevel=WARN, Enhance=TRACE"/>
       </properties>
    </persistence-unit>
    
@@ -41,6 +51,8 @@
 		<properties>
             <property name="openjpa.BrokerFactory" value="slice"/>
             <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
+            <property name="slice.Names" value="One,Two"/>
+            <property name="slice.Master" value="Two"/>
             <property name="slice.One.ConnectionURL" value="jdbc:mysql://localhost/slice1"/>
             <property name="slice.Two.ConnectionURL" value="jdbc:mysql://localhost/slice2"/>
             <property name="openjpa.ConnectionUserName" value="root"/>
@@ -54,6 +66,7 @@
    	        <property name="openjpa.Log" value="DefaultLevel=WARN, Enhance=TRACE"/>
    	        <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
             <property name="openjpa.jdbc.MappingDefaults" value="DefaultMissingInfo=true"/>
+            
       	</properties>
    </persistence-unit>
    
@@ -71,8 +84,9 @@
             
             <property name="openjpa.Connection2URL" value="jdbc:mysql://localhost/slice1"/>
             <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
-            <property name="openjpa.Log" value="DefaultLevel=INFO, Enhance=TRACE"/>
+            <property name="openjpa.Log" value="DefaultLevel=WARN, Enhance=TRACE"/>
             <property name="openjpa.jdbc.MappingDefaults" value="DefaultMissingInfo=true"/>
+            <property name="openjpa.Log" value="DefaultLevel=WARN, Enhance=TRACE"/>
         </properties>
    </persistence-unit>
    



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