A factory to construct tuples. This class is abstract so that users can override the tuple factory if they desire to provide their own that returns their implementation of a tuple. If the property pig.data.tuple.factory.name is set to a class name and pig.data.tuple.factory.jar is set to a URL poi
| 36 | * will create an instance of {@link DefaultTupleFactory}. |
| 37 | */ |
| 38 | @InterfaceAudience.Public |
| 39 | @InterfaceStability.Stable |
| 40 | public abstract class TupleFactory implements TupleMaker<Tuple> { |
| 41 | private static TupleFactory gSelf = null; |
| 42 | |
| 43 | /** |
| 44 | * Get a reference to the singleton factory. |
| 45 | * @return The TupleFactory to use to construct tuples. |
| 46 | */ |
| 47 | public static TupleFactory getInstance() { |
| 48 | if (gSelf == null) { |
| 49 | String factoryName = |
| 50 | System.getProperty("pig.data.tuple.factory.name"); |
| 51 | String factoryJar = |
| 52 | System.getProperty("pig.data.tuple.factory.jar"); |
| 53 | if (factoryName != null && factoryJar != null) { |
| 54 | try { |
| 55 | URL[] urls = new URL[1]; |
| 56 | urls[0] = new URL(factoryJar); |
| 57 | ClassLoader loader = new URLClassLoader(urls, |
| 58 | TupleFactory.class.getClassLoader()); |
| 59 | Class c = Class.forName(factoryName, true, loader); |
| 60 | Object o = c.newInstance(); |
| 61 | if (!(o instanceof TupleFactory)) { |
| 62 | throw new RuntimeException("Provided factory " + |
| 63 | factoryName + " does not extend TupleFactory!"); |
| 64 | } |
| 65 | gSelf = (TupleFactory)o; |
| 66 | } catch (Exception e) { |
| 67 | if (e instanceof RuntimeException) { |
| 68 | // We just threw this |
| 69 | RuntimeException re = (RuntimeException)e; |
| 70 | throw re; |
| 71 | } |
| 72 | throw new RuntimeException("Unable to instantiate " |
| 73 | + "tuple factory " + factoryName, e); |
| 74 | } |
| 75 | } else if (factoryName != null) { |
| 76 | try { |
| 77 | Class c = Class.forName(factoryName); |
| 78 | Object o = c.newInstance(); |
| 79 | if (!(o instanceof TupleFactory)) { |
| 80 | throw new RuntimeException("Provided factory " + |
| 81 | factoryName + " does not extend TupleFactory!"); |
| 82 | } |
| 83 | gSelf = (TupleFactory)o; |
| 84 | } catch (Exception e) { |
| 85 | if (e instanceof RuntimeException) { |
| 86 | // We just threw this |
| 87 | RuntimeException re = (RuntimeException)e; |
| 88 | throw re; |
| 89 | } |
| 90 | throw new RuntimeException("Unable to instantiate " |
| 91 | + "tuple factory " + factoryName, e); |
| 92 | } |
| 93 | } else { |
| 94 | gSelf = new BinSedesTupleFactory(); |
| 95 | } |
nothing calls this directly
no outgoing calls
no test coverage detected