Package com.volantis.synergetics.descriptorstore.impl

Examples of com.volantis.synergetics.descriptorstore.impl.DefaultResourceDescriptor


    // javadoc inherited
    public ResourceDescriptor getDescriptor(String externalID)
        throws ResourceDescriptorStoreException {

        DefaultResourceDescriptor result = null;
        PersistenceManager pm = getPersistenceManager();
        pm.getFetchPlan().setMaxFetchDepth(-1);
        pm.getFetchPlan().setFetchSize(FetchPlan.FETCH_SIZE_GREEDY);
        pm.setDetachAllOnCommit(true);
        final Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            // run the query
            final Query query = pm.newQuery(DefaultResourceDescriptor.class,
                                            "externalID == ID");
            query.declareImports("import java.lang.String");
            query.declareParameters("String ID");
            query.setUnique(true);
            result = (DefaultResourceDescriptor) query.execute(externalID);
            if (null == result) {
                throw new ResourceDescriptorStoreException(
                    "cs-external-id-not-found", externalID);
            } else {
                // update the last access time.
                result.setLastAccess(new Date());
            }
            tx.commit();
        } catch (ResourceDescriptorStoreException rde) {
            LOGGER.warn(rde);
            throw rde;
View Full Code Here


    // javadoc inherited
    public ResourceDescriptor createDescriptor(
            String resourceType,Parameters configParams, ParameterNames names,
            final long initialTimeToLive) {
        DefaultResourceDescriptor result = null;
        int hash = DefaultResourceDescriptor.computeDBHash(
            resourceType, configParams);
        PersistenceManager pm = getPersistenceManager();
        pm.getFetchPlan().setMaxFetchDepth(-1);
        pm.getFetchPlan().setFetchSize(FetchPlan.FETCH_SIZE_GREEDY);
        pm.setDetachAllOnCommit(true);
        final Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            // run the query
            final Query query = pm.newQuery(DefaultResourceDescriptor.class,
                                            "hash == hashcode");
            query.declareParameters("int hashcode");

            List hashMatches = (List) query.execute(new Integer(hash));
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Found " + hashMatches.size() +
                             " matches for hashcode " + hash);
            }
            Iterator it = hashMatches.iterator();
            boolean finished = false;
            while (it.hasNext() && !finished) {
                DefaultResourceDescriptor gi = (DefaultResourceDescriptor) it.next();
                // here we check that the important bits of the retrieved entry
                // are equal to the requested information
                if (resourceType.equals(gi.getResourceType()) &&
                    gi.getInputParameters().equals(
                        gi.getInputParameters())) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Found exact match for hash " + hash);
                    }
                    result = gi;
                    finished = true;
                }
            }

            // there is a minor concurrency issue here where more then one
            // ResourceDefinition objects could be created for the same
            // resource. It is a small hole and causes an inefficiency in the
            // amount of data stored but does not break anything.
            if (null == result) {
               result = new DefaultResourceDescriptor(resourceType,
                   (DefaultParameters) configParams,
                   (DefaultParameterNames) names);
                result.computeDBHash();
                result.setExternalID(ExternalIDGenerator.getNextID());
                result.setTimeToLive(initialTimeToLive);
View Full Code Here

    }

    // javadoc inherited.
    public void updateDescriptor(ResourceDescriptor descriptor) {
        PersistenceManager pm = getPersistenceManager();
        DefaultResourceDescriptor configItem = (DefaultResourceDescriptor) descriptor;
        pm.getFetchPlan().setMaxFetchDepth(-1);
        pm.getFetchPlan().setFetchSize(FetchPlan.FETCH_SIZE_GREEDY);
        pm.setDetachAllOnCommit(true);
        final Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("updating descriptor " + configItem.getExternalID());
            }
            configItem.setLastAccess(new Date());
            configItem.computeDBHash();
            pm.makePersistent(descriptor);
            tx.commit();
        } catch (Throwable t) {
            // make sure its logged
            LOGGER.error(t);
View Full Code Here

            final Query query = pm.newQuery(DefaultResourceDescriptor.class,
                                            "externalID == ID");
            query.declareImports("import java.lang.String");
            query.declareParameters("String ID");
            query.setUnique(true);
            final DefaultResourceDescriptor descriptor =
                (DefaultResourceDescriptor) query.execute(externalId);
            if (null == descriptor) {
                throw new ResourceDescriptorStoreException(
                    "cs-external-id-not-found", externalId);
            }
            final long oldTtl = descriptor.getTimeToLive();
            if (timeToLive > oldTtl) {
                descriptor.setTimeToLive(timeToLive);
            }
            tx.commit();
        } catch (ResourceDescriptorStoreException rde) {
            LOGGER.warn(rde);
            throw rde;
View Full Code Here

TOP

Related Classes of com.volantis.synergetics.descriptorstore.impl.DefaultResourceDescriptor

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.