Package org.datanucleus

Examples of org.datanucleus.PersistenceConfiguration$PropertyMapping


                {
                    // Obtain a new connection
                    // Note : it may be worthwhile to use the PM's connection here however where a Sequence doesnt yet
                    // exist the connection would then be effectively dead until the end of the tx
                    // The way around this would be to find a way of checking for existence of the sequence
                    PersistenceConfiguration conf = ec.getNucleusContext().getPersistenceConfiguration();
                    int isolationLevel = TransactionUtils.getTransactionIsolationLevelForName(
                        conf.getStringProperty("datanucleus.valuegeneration.transactionIsolation"));
                    this.mconn = ((RDBMSStoreManager)storeManager).getConnection(isolationLevel);
                    return mconn;
                }

                public void releaseConnection()
View Full Code Here


    public static void prepareStatementForExecution(PreparedStatement ps, Query query, boolean applyTimeout)
    throws SQLException
    {
        NucleusContext nucleusCtx = query.getExecutionContext().getNucleusContext();
        MappedStoreManager storeMgr = (MappedStoreManager)nucleusCtx.getStoreManager();
        PersistenceConfiguration conf = nucleusCtx.getPersistenceConfiguration();

        if (applyTimeout)
        {
            Integer timeout = query.getDatastoreReadTimeoutMillis();
            if (timeout != null && timeout > 0)
            {
                ps.setQueryTimeout(timeout/1000);
            }
        }

        // Apply any fetch size
        int fetchSize = 0;
        if (query.getFetchPlan().getFetchSize() > 0)
        {
            // FetchPlan has a size set so use that
            fetchSize = query.getFetchPlan().getFetchSize();
        }
        if (storeMgr.getDatastoreAdapter().supportsQueryFetchSize(fetchSize))
        {
            ps.setFetchSize(fetchSize);
        }

        // Apply any fetch direction
        String fetchDir = conf.getStringProperty(JDOQLQuery.EXTENSION_RDBMS_FETCH_DIRECTION);
        Object fetchDirExt = query.getExtension(JDOQLQuery.EXTENSION_RDBMS_FETCH_DIRECTION);
        if (fetchDirExt != null)
        {
            fetchDir = (String)fetchDirExt;
            if (!fetchDir.equals("forward") && !fetchDir.equals("reverse") && !fetchDir.equals("unknown"))
View Full Code Here

            // Stored procedures, others
            type = OTHER;
            unique = true;
        }

        PersistenceConfiguration conf = ec.getNucleusContext().getPersistenceConfiguration();
        if (ec.getApiAdapter().getName().equalsIgnoreCase("JDO") &&
            !conf.getBooleanProperty("datanucleus.query.sql.allowAll"))
        {
            // JDO spec [14.7] : SQL queries must start with SELECT/select
            if (!firstToken.equals("SELECT") && !firstToken.startsWith("select"))
            {
                throw new NucleusUserException(LOCALISER.msg("059002", inputSQL));
View Full Code Here

     * Method to find and initialise the query cache, for caching query compilations.
     */
    protected void initialiseQueryCaches()
    {
        // Instantiate the query compilation cache (generic)
        PersistenceConfiguration conf = nucleusCtx.getPersistenceConfiguration();
        String cacheType = conf.getStringProperty("datanucleus.cache.queryCompilation.type");
        if (cacheType != null && !cacheType.equalsIgnoreCase("none"))
        {
            String cacheClassName = nucleusCtx.getPluginManager().getAttributeValueForExtension(
                "org.datanucleus.cache_query_compilation", "name", cacheType, "class-name");
            if (cacheClassName == null)
            {
                // Plugin of this name not found
                throw new NucleusUserException(LOCALISER.msg("021500", cacheType)).setFatal();
            }

            try
            {
                // Create an instance of the Query Cache
                queryCompilationCache = (QueryCompilationCache)nucleusCtx.getPluginManager().createExecutableExtension(
                    "org.datanucleus.cache_query_compilation", "name", cacheType, "class-name",
                    new Class[] {NucleusContext.class}, new Object[] {nucleusCtx});
                if (NucleusLogger.CACHE.isDebugEnabled())
                {
                    NucleusLogger.CACHE.debug(LOCALISER.msg("021502", cacheClassName));
                }
            }
            catch (Exception e)
            {
                // Class name for this Query cache plugin is not found!
                throw new NucleusUserException(LOCALISER.msg("021501", cacheType, cacheClassName), e).setFatal();
            }
        }

        // Instantiate the query compilation cache (datastore)
        cacheType = conf.getStringProperty("datanucleus.cache.queryCompilationDatastore.type");
        if (cacheType != null && !cacheType.equalsIgnoreCase("none"))
        {
            String cacheClassName = nucleusCtx.getPluginManager().getAttributeValueForExtension(
                "org.datanucleus.cache_query_compilation_store", "name", cacheType, "class-name");
            if (cacheClassName == null)
            {
                // Plugin of this name not found
                throw new NucleusUserException(LOCALISER.msg("021500", cacheType)).setFatal();
            }

            try
            {
                // Create an instance of the Query Cache
                queryCompilationCacheDatastore =
                    (QueryDatastoreCompilationCache)nucleusCtx.getPluginManager().createExecutableExtension(
                    "org.datanucleus.cache_query_compilation_store", "name", cacheType, "class-name",
                    new Class[] {NucleusContext.class}, new Object[] {nucleusCtx});
                if (NucleusLogger.CACHE.isDebugEnabled())
                {
                    NucleusLogger.CACHE.debug(LOCALISER.msg("021502", cacheClassName));
                }
            }
            catch (Exception e)
            {
                // Class name for this Query cache plugin is not found!
                throw new NucleusUserException(LOCALISER.msg("021501", cacheType, cacheClassName), e).setFatal();
            }
        }

        // Instantiate the query results cache
        cacheType = conf.getStringProperty("datanucleus.cache.queryResults.type");
        if (cacheType != null && !cacheType.equalsIgnoreCase("none"))
        {
            String cacheClassName = nucleusCtx.getPluginManager().getAttributeValueForExtension(
                "org.datanucleus.cache_query_result", "name", cacheType, "class-name");
            if (cacheClassName == null)
View Full Code Here

    /** Name of the cache to use. */
    protected String cacheName;

    public AbstractLevel2Cache(NucleusContext nucleusCtx)
    {
        PersistenceConfiguration conf = nucleusCtx.getPersistenceConfiguration();
        maxSize = conf.getIntProperty("datanucleus.cache.level2.maxSize");
        clearAtClose = conf.getBooleanProperty("datanucleus.cache.level2.clearAtClose", true);

        cacheName = conf.getStringProperty("datanucleus.cache.level2.cacheName");
        if (cacheName == null)
        {
            NucleusLogger.CACHE.warn("No 'datanucleus.cache.level2.cacheName' specified so using name of 'dataNucleus'");
            cacheName = "dataNucleus";
        }
View Full Code Here

            }
        }

        // Initialise the context for this API
        NucleusContext nucleusCtx = new NucleusContext(api, startupProps);
        PersistenceConfiguration propConfig = nucleusCtx.getPersistenceConfiguration();

        // Generate list of properties for SchemaTool usage
        Map props = new HashMap();
        PersistenceUnitMetaData pumd = null;
        if (persistenceUnitName != null)
        {
            // Obtain any props defined for the persistence-unit
            props.put("javax.jdo.option.persistenceunitname", persistenceUnitName);
            pumd = nucleusCtx.getMetaDataManager().getMetaDataForPersistenceUnit(persistenceUnitName);
            if (pumd != null)
            {
                // Add the properties for the unit
                if (pumd.getProperties() != null)
                {
                    props.putAll(pumd.getProperties());
                }
            }
            else
            {
                throw new NucleusUserException("SchemaTool has been specified to use persistence-unit with name " +
                    persistenceUnitName + " but none was found with that name");
            }

            if (api.equalsIgnoreCase("JPA"))
            {
                pumd.clearJarFiles(); // Don't use JARs when in J2SE for JPA
            }
        }
        else if (userProps != null)
        {
            // Properties specified by the user in a file
            for (Object key : userProps.keySet())
            {
                String propName = (String)key;
                props.put(propName.toLowerCase(Locale.ENGLISH), userProps.get(propName));
            }
        }
        else
        {
            // Properties specified via System properties (only support particular ones, and in correct case)
            String[] propNames =
            {
                    "datanucleus.ConnectionURL",
                    "datanucleus.ConnectionDriverName",
                    "datanucleus.ConnectionUserName",
                    "datanucleus.ConnectionPassword",
                    "datanucleus.Mapping",
                    "javax.jdo.option.ConnectionURL",
                    "javax.jdo.option.ConnectionDriverName",
                    "javax.jdo.option.ConnectionUserName",
                    "javax.jdo.option.ConnectionPassword",
                    "javax.jdo.option.Mapping"
            };
            for (int i=0;i<propNames.length;i++)
            {
                if (System.getProperty(propNames[i]) != null)
                {
                    props.put(propNames[i].toLowerCase(Locale.ENGLISH), System.getProperty(propNames[i]));
                }
            }
        }

        props.put("datanucleus.autostartmechanism", "None"); // Interferes with usage

        // Tag on the mandatory props that we must have for each mode
        if (mode == SCHEMATOOL_CREATE_MODE)
        {
            if (ddlFile != null)
            {
                // the tables must not be created in the DB, so do not validate (DDL is being output to a file)
                props.put("datanucleus.validateconstraints", "false");
                props.put("datanucleus.validatecolumns", "false");
                props.put("datanucleus.validatetables", "false");
            }
            props.remove("datanucleus.autocreateschema"); // use tables/columns/constraints settings
            if (!props.containsKey("datanucleus.autocreatetables"))
            {
                props.put("datanucleus.autocreatetables", "true");
            }
            if (!props.containsKey("datanucleus.autocreatecolumns"))
            {
                props.put("datanucleus.autocreatecolumns", "true");
            }
            if (!props.containsKey("datanucleus.autocreateconstraints"))
            {
                props.put("datanucleus.autocreateconstraints", "true");
            }
            props.put("datanucleus.fixeddatastore", "false");
            props.put("datanucleus.readonlydatastore", "false");
            props.put("datanucleus.rdbms.checkexisttablesorviews", "true");
        }
        else if (mode == SCHEMATOOL_DELETE_MODE)
        {
            props.put("datanucleus.fixeddatastore", "false");
            props.put("datanucleus.readonlydatastore", "false");
        }
        else if (mode == SCHEMATOOL_VALIDATE_MODE)
        {
            props.put("datanucleus.autocreateschema", "false");
            props.put("datanucleus.autocreatetables", "false");
            props.put("datanucleus.autocreateconstraints", "false");
            props.put("datanucleus.autocreatecolumns", "false");
            props.put("datanucleus.validatetables", "true");
            props.put("datanucleus.validatecolumns", "true");
            props.put("datanucleus.validateconstraints", "true");
        }

        // Apply remaining persistence properties
        propConfig.setPersistenceProperties(props);

        if (pumd != null)
        {
            // Initialise the MetaDataManager with all files/classes for this persistence-unit
            // This is done now that all persistence properties are set (including the persistence-unit props)
            nucleusCtx.getMetaDataManager().loadPersistenceUnit(pumd, null);
        }

        // Initialise the NucleusContext for use
        nucleusCtx.initialise();

        if (verbose)
        {
            String msg = LOCALISER.msg(false, "014020");
            LOGGER.info(msg);
            System.out.println(msg);

            // TODO Some persistence properties will be stored against the StoreManager
            Map<String,Object> pmfProps = propConfig.getPersistenceProperties();
            Set<String> keys = pmfProps.keySet();
            List<String> keyNames = new ArrayList<String>(keys);
            Collections.sort(keyNames);
            Iterator keyNamesIter = keyNames.iterator();
            while (keyNamesIter.hasNext())
View Full Code Here

     * @return null if validation mode is none or validation mode is auto and an error occurs.
     * @throws PersistenceException if an error occurred and validation mode is callback
     */
    public static CallbackHandler newInstance(ExecutionContext ec)
    {
        PersistenceConfiguration conf = ec.getNucleusContext().getPersistenceConfiguration();
        if (conf.hasPropertyNotNull("javax.persistence.validation.mode"))
        {
            if (conf.getStringProperty("javax.persistence.validation.mode").equalsIgnoreCase("none"))
            {
                return null;
            }
        }
        try
        {
            Class cls = ec.getClassLoaderResolver().classForName("org.datanucleus.api.jpa.beanvalidation.BeanValidatorHandler");
            Constructor constructor = cls.getConstructor(new Class[]{ExecutionContext.class});
            return (CallbackHandler) constructor.newInstance(new Object[]{ec});
        }
        catch (Throwable ex) //throwable used to catch linkage errors
        {
            if (conf.hasPropertyNotNull("javax.persistence.validation.mode"))
            {
                if (conf.getStringProperty("javax.persistence.validation.mode").equalsIgnoreCase("callback"))
                {
                    throw new PersistenceException(ex.getMessage(), ex);
                }
            }
            // TODO log
View Full Code Here

        locationDefinition = ALL_JDO_LOCATIONS;

        // Do we want to use the JDO class initialisation listener ?
        boolean useMetadataListener = false;
        PersistenceConfiguration conf = ctxt.getPersistenceConfiguration();
        if (conf.getStringProperty("datanucleus.PersistenceUnitName") == null &&
            ctxt.getType() == NucleusContext.ContextType.PERSISTENCE &&
            conf.getBooleanProperty("datanucleus.metadata.autoregistration"))
        {
            useMetadataListener = true;
        }

        // Log the current configuration
View Full Code Here

     */
    private Object throwException(RuntimeException re)
    {
        if (re instanceof PersistenceException)
        {
            PersistenceConfiguration conf = om.getNucleusContext().getPersistenceConfiguration();
            if (tx.isActive())
            {
                boolean markForRollback = conf.getBooleanProperty("datanucleus.jpa.txnMarkForRollbackOnException");
                if (markForRollback)
                {
                    // The JPA spec says that all PersistenceExceptions thrown should mark the transaction for
                    // rollback. Seems stupid to me. e.g you try to find an object with a particular id and it
                    // doesn't exist so you then have to rollback the txn and start again. FFS.
View Full Code Here

            }
        }

        // Initialise the context for JPA
        NucleusContext nucleusCtx = new NucleusContext("JPA", startupProps);
        PersistenceConfiguration propConfig = nucleusCtx.getPersistenceConfiguration();

        // Apply remaining persistence properties
        Map ctxProps = new HashMap();
        ctxProps.putAll(props);

        if (!props.containsKey("datanucleus.transactiontype") &&
            !props.containsKey("javax.jdo.option.transactiontype"))
        {
            // Default to RESOURCE_LOCAL txns
            ctxProps.put("datanucleus.transactiontype", TransactionType.RESOURCE_LOCAL.toString());
        }
        else
        {
            // let TransactionType.JTA imply ResourceType.JTA
            String transactionType = props.get("datanucleus.transactiontype") != null ?
                    (String)props.get("datanucleus.transactiontype") : (String)props.get("javax.jdo.option.transactiontype");
            if (TransactionType.JTA.toString().equalsIgnoreCase(transactionType))
            {
                ctxProps.put(ConnectionFactory.DATANUCLEUS_CONNECTION_RESOURCE_TYPE.toLowerCase(Locale.ENGLISH),
                    ConnectionResourceType.JTA.toString());
                ctxProps.put(ConnectionFactory.DATANUCLEUS_CONNECTION2_RESOURCE_TYPE.toLowerCase(Locale.ENGLISH),
                    ConnectionResourceType.JTA.toString());
            }
        }
        propConfig.setPersistenceProperties(ctxProps);

        // Load up the MetaData implied by this "persistence-unit"
        nucleusCtx.getMetaDataManager().loadPersistenceUnit(unitMetaData, null);
        nucleusCtx.initialise();

        // Load up any persistence-unit classes into the StoreManager
        boolean loadClasses = propConfig.getBooleanProperty("datanucleus.persistenceunitloadclasses");
        if (loadClasses)
        {
            // Load all classes into StoreManager so it knows about them
            Collection<String> loadedClasses = nucleusCtx.getMetaDataManager().getClassesWithMetaData();
            nucleusCtx.getStoreManager().addClasses(loadedClasses.toArray(new String[loadedClasses.size()]), nucleusCtx.getClassLoaderResolver(null));
View Full Code Here

TOP

Related Classes of org.datanucleus.PersistenceConfiguration$PropertyMapping

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.