Package org.apache.openjpa.lib.util

Examples of org.apache.openjpa.lib.util.Options


        return InstrumentationLevel.FACTORY;
    }

    @Override
    public void initialize() {
        Options opts = new Options();
        if (getOptions() != null) {
            opts = Configurations.parseProperties(getOptions());
        }
       
        String cacheName = opts.getProperty("name",null);
        OpenJPAConfiguration conf = (OpenJPAConfiguration)getProvider().getConfiguration();
        DataCacheManager dcm = conf.getDataCacheManagerInstance();
        DataCache dc = null;
        if (cacheName == null || cacheName.trim().length() == 0) {
            dc = dcm.getSystemDataCache();
View Full Code Here


        if (_conf.isInitializeEagerly()) {
            newBroker(_conf.getConnectionUserName(), _conf.getConnectionPassword(),
                _conf.isConnectionFactoryModeManaged(), _conf.getConnectionRetainModeConstant(), false).close();
        }
        // Don't catch any exceptions here because we want to fail-fast if something bad happens when we're preloading.
        Options o = Configurations.parseProperties(Configurations.getProperties(_conf.getMetaDataRepository()));
        if (MetaDataRepository.needsPreload(o) == true) {
            MetaDataRepository mdr = _conf.getMetaDataRepositoryInstance();
            mdr.setValidate(MetaDataRepository.VALIDATE_RUNTIME, true);
            mdr.setResolve(MetaDataRepository.MODE_MAPPING_INIT, true);
View Full Code Here

    extends AbstractCachedEMFTestCase {

    public void testExplicitEnhancementWithClassNotInFirstPU()
        throws ClassNotFoundException {
        OpenJPAConfiguration conf = new OpenJPAConfigurationImpl();
        Configurations.populateConfiguration(conf, new Options());
        MetaDataRepository repos = conf.getMetaDataRepositoryInstance();
        ClassLoader loader = AccessController
            .doPrivileged(J2DoPrivHelper.newTemporaryClassLoaderAction(
                getClass().getClassLoader()));
        Project project = new Project();
View Full Code Here

    }

    public void testEnhancementOfSecondPUWithClassNotInFirstPU()
        throws IOException {
        OpenJPAConfiguration conf = new OpenJPAConfigurationImpl();
        Options opts = new Options();
        opts.setProperty("p",
            "META-INF/persistence.xml#second-persistence-unit");
        Configurations.populateConfiguration(conf, opts);
        MetaDataRepository repos = conf.getMetaDataRepositoryInstance();
        ClassLoader loader = AccessController
            .doPrivileged(J2DoPrivHelper.newTemporaryClassLoaderAction(
View Full Code Here

    }

    public void testEnhancementOfAllPUsWithinAResource()
        throws IOException {
        OpenJPAConfiguration conf = new OpenJPAConfigurationImpl();
        Options opts = new Options();
        opts.setProperty("p", "META-INF/persistence.xml");
        Configurations.populateConfiguration(conf, opts);
        MetaDataRepository repos = conf.getMetaDataRepositoryInstance();
        ClassLoader loader = AccessController
            .doPrivileged(J2DoPrivHelper.newTemporaryClassLoaderAction(
                getClass().getClassLoader()));
        Project project = new Project();

        // make sure that the classes is not already enhanced for some reason
        assertNotPC(loader, project,
            "org.apache.openjpa.enhance.UnenhancedBootstrapInstance");
        assertNotPC(loader, project,
            "org.apache.openjpa.enhance.UnenhancedBootstrapInstance2");

        // build up a writer that just stores to a list so that we don't
        // mutate the disk.
        final List<String> written = new ArrayList<String>();
        BytecodeWriter writer = new BytecodeWriter() {

            public void write(BCClass type) throws IOException {
                assertTrue(Arrays.asList(type.getInterfaceNames()).contains(
                    PersistenceCapable.class.getName()));
                written.add(type.getName());
            }
        };

        opts = new Options();
        // Use a restricted mdr.  This mdr will not hand out metadata for excluded
        // types.  These are types that have known issues and should not be enhanced.
        // This test tries to enhance all persistent types in the classpath and that
        // can be problematic for tests which include entities that this test should
        // not attempt to enhance.
        opts.setProperty("MetaDataRepository",
            "org.apache.openjpa.enhance.RestrictedMetaDataRepository(excludedTypes=" +
            "org.apache.openjpa.persistence.jdbc.annotations.UnenhancedMixedAccess)");
        opts.put(PCEnhancer.class.getName() + "#bytecodeWriter", writer);
        PCEnhancer.run(null, opts);

        // ensure that we do process the classes listed in the PUs
        assertTrue(written.contains(
            "org.apache.openjpa.enhance.UnenhancedBootstrapInstance"));
View Full Code Here

            _fieldValues = null;
            return;
        }

        // parse string into options; this takes care of proper trimming etc
        Options values = Configurations.parseProperties(_extString);
        if (values.isEmpty())
            throw new MetaDataException(_loc.get("no-external-values", this,
                _extString));

        Map extValues = new HashMap((int) (values.size() * 1.33 + 1));
        Map fieldValues = new HashMap((int) (values.size() * 1.33 + 1));
        Map.Entry entry;
        Object extValue, fieldValue;
        for (Iterator itr = values.entrySet().iterator(); itr.hasNext();) {
            entry = (Map.Entry) itr.next();
            fieldValue = transform((String) entry.getKey(),
                getDeclaredTypeCode());
            extValue = transform((String) entry.getValue(), getTypeCode());

View Full Code Here

    public static void configureInstance(Object obj, Configuration conf,
        Properties properties, String configurationName) {
        if (obj == null)
            return;

        Options opts;
        if (properties instanceof Options)
            opts = (Options) properties;
        else {
            opts = new Options();
            if (properties != null)
                opts.putAll(properties);
        }

        Configurable configurable = null;
        if (conf != null && obj instanceof Configurable)
            configurable = (Configurable) obj;

        if (configurable != null) {
            configurable.setConfiguration(conf);
            configurable.startConfiguration();
        }
        Options invalidEntries = opts.setInto(obj);
        if (obj instanceof GenericConfigurable)
            ((GenericConfigurable) obj).setInto(invalidEntries);

    if (!invalidEntries.isEmpty() && configurationName != null) {
      Localizer.Message msg = null;
            String first = (String) invalidEntries.keySet().iterator().next();
      if (invalidEntries.keySet().size() == 1 &&
        first.indexOf('.') == -1) {
                // if there's just one misspelling and this is not a
        // path traversal, check for near misses.
                Collection<String> options = findOptionsFor(obj.getClass());
                String close = StringDistance.getClosestLevenshteinDistance
          (first, options, 0.75f);
        if (close != null)
                    msg = _loc.get("invalid-config-param-hint", new Object[]{
                            configurationName, obj.getClass(), first, close,
                options, });
      }

            if (msg == null) {
                msg = _loc.get("invalid-config-params", new String[]{
                    configurationName, obj.getClass().getName(),
                    invalidEntries.keySet().toString(),
                    findOptionsFor(obj.getClass()).toString(), });
            }
            throw new ParseException(msg);
        }
        if (configurable != null)
View Full Code Here

    /**
     * Parse a set of properties from a comma-separated string.
     */
    public static Options parseProperties(String properties) {
        Options opts = new Options();
        properties = StringUtils.trimToNull(properties);
        if (properties == null)
            return opts;

        try {
            String[] props = Strings.split(properties, ",", 0);
            int idx;
            char quote;
            String prop;
            String val;
            for (int i = 0; i < props.length; i++) {
                idx = props[i].indexOf('=');
                if (idx == -1) {
                    // if the key is not assigned to any value, set the
                    // value to the same thing as the key, and continue.
                    // This permits GenericConfigurable instances to
                    // behave meaningfully. We might consider setting the
                    // value to some well-known "value was not set, but
                    // key is present" string so that instances getting
                    // values injected can differentiate between a mentioned
                    // property and one set to a particular value.
                    prop = props[i];
                    val = prop;
                } else {
                    prop = props[i].substring(0, idx).trim();
                    val = props[i].substring(idx + 1).trim();
                }

                // if the value is quoted, read until the end quote
                if (((val.startsWith("\"") && val.endsWith("\""))
                    || (val.startsWith("'") && val.endsWith("'")))
                    && val.length() > 1)
                    val = val.substring(1, val.length() - 1);
                else if (val.startsWith("\"") || val.startsWith("'")) {
                    quote = val.charAt(0);
                    StringBuilder buf = new StringBuilder(val.substring(1));
                    int quotIdx;
                    while (++i < props.length) {
                        buf.append(",");

                        quotIdx = props[i].indexOf(quote);
                        if (quotIdx != -1) {
                            buf.append(props[i].substring(0, quotIdx));
                            if (quotIdx + 1 < props[i].length())
                                buf.append(props[i].substring(quotIdx + 1));
                            break;
                        } else
                            buf.append(props[i]);
                    }
                    val = buf.toString();
                }
                opts.put(prop, val);
            }
            return opts;
        } catch (RuntimeException re) {
            throw new ParseException(_loc.get("prop-parse", properties), re);
        }
View Full Code Here

        boolean ret = true;
        if (anchors.size() == 0) {
            ret = launchRunnable(opts, runnable);
        } else {
            for(String s : anchors ) {
                Options clonedOptions = (Options) opts.clone();
                clonedOptions.setProperty("properties", s);
                ret &= launchRunnable(clonedOptions, runnable);
            }
        }
        return ret;
    }
View Full Code Here

     * explicitly declares the persistence-capable interface, it will
     * not be enhanced. Thus, it is safe to invoke the enhancer on classes
     * that are already enhanced.
     */
    public static void main(String[] args) {
        Options opts = new Options();
        args = opts.setFromCmdLine(args);
        if (!run(args, opts))
            System.err.println(_loc.get("enhance-usage"));
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.lib.util.Options

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.