Search in sources :

Example 11 with JDOException

use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.

the class JDOPersistenceManager method getObjectIdClass.

/**
 * Accessor for the class of the object id given the class of object.
 * @param cls The class name of the object
 * @return The class name of the object id
 */
public Class getObjectIdClass(Class cls) {
    assertIsOpen();
    if (!ec.getNucleusContext().getApiAdapter().isPersistable(cls) || !hasPersistenceInformationForClass(cls)) {
        return null;
    }
    ClassLoaderResolver clr = ec.getClassLoaderResolver();
    AbstractClassMetaData cmd = ec.getMetaDataManager().getMetaDataForClass(cls, clr);
    if (cmd.getIdentityType() == IdentityType.DATASTORE) {
        return ec.getNucleusContext().getIdentityManager().getDatastoreIdClass();
    } else if (cmd.getIdentityType() == IdentityType.APPLICATION) {
        try {
            return this.ec.getClassLoaderResolver().classForName(ec.getMetaDataManager().getMetaDataForClass(cls, clr).getObjectidClass(), null);
        } catch (ClassNotResolvedException e) {
            String msg = Localiser.msg("011009", cls.getName());
            LOGGER.error(msg);
            throw new JDOException(msg);
        }
    } else {
        if (cmd.isRequiresExtent()) {
            return ec.getNucleusContext().getIdentityManager().getDatastoreIdClass();
        }
        return SCOID.class;
    }
}
Also used : ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) JDOException(javax.jdo.JDOException)

Example 12 with JDOException

use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.

the class JDOPersistenceManager method evictAll.

/**
 * Method to evict a collection of objects from L1 cache.
 * @param pcs The objects
 * @throws JDOUserException thrown if some instances could not be evicted
 */
public void evictAll(Collection pcs) {
    assertIsOpen();
    ArrayList failures = new ArrayList();
    Iterator i = pcs.iterator();
    while (i.hasNext()) {
        try {
            jdoEvict(i.next());
        } catch (JDOException e) {
            failures.add(e);
        }
    }
    if (!failures.isEmpty()) {
        throw new JDOUserException(Localiser.msg("010036"), (Exception[]) failures.toArray(new Exception[failures.size()]));
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) JDOUserException(javax.jdo.JDOUserException) JDONullIdentityException(javax.jdo.JDONullIdentityException) TransactionNotActiveException(org.datanucleus.api.jdo.exceptions.TransactionNotActiveException) JDOException(javax.jdo.JDOException) JDOUserException(javax.jdo.JDOUserException) JDOFatalUserException(javax.jdo.JDOFatalUserException) NucleusException(org.datanucleus.exceptions.NucleusException) TransactionActiveOnCloseException(org.datanucleus.exceptions.TransactionActiveOnCloseException) JDOOptimisticVerificationException(javax.jdo.JDOOptimisticVerificationException) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) TransactionNotWritableException(org.datanucleus.api.jdo.exceptions.TransactionNotWritableException) JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) NucleusOptimisticException(org.datanucleus.exceptions.NucleusOptimisticException) JDOException(javax.jdo.JDOException)

Example 13 with JDOException

use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.

the class JDOPersistenceManagerFactory method freezeConfiguration.

/**
 * Freezes the current configuration.
 * @throws JDOException if the configuration was invalid or inconsistent in some way
 */
protected void freezeConfiguration() {
    if (isConfigurable()) {
        // Check for invalid javax.jdo properties by calling JDOImplHelper method (new in JDO3.1+)
        Method m = null;
        try {
            m = JDOImplHelper.class.getDeclaredMethod("assertOnlyKnownStandardProperties", new Class[] { Map.class });
            m.invoke(null, nucleusContext.getConfiguration().getPersistenceProperties());
        } catch (InvocationTargetException ite) {
            if (ite.getCause() instanceof JDOException) {
                throw (JDOException) ite.getCause();
            }
        } catch (JDOException jdoe) {
            throw jdoe;
        } catch (Exception e) {
        // Method not present so continue
        }
        synchronized (this) {
            try {
                // Initialise the NucleusContext
                nucleusContext.initialise();
                // Set up the Level 2 Cache
                datastoreCache = new JDODataStoreCache(nucleusContext.getLevel2Cache());
                setIsNotConfigurable();
            } catch (TransactionIsolationNotSupportedException inse) {
                throw new JDOUnsupportedOptionException(inse.getMessage());
            } catch (NucleusException ne) {
                throw NucleusJDOHelper.getJDOExceptionForNucleusException(ne);
            }
        }
    }
}
Also used : TransactionIsolationNotSupportedException(org.datanucleus.exceptions.TransactionIsolationNotSupportedException) JDOImplHelper(javax.jdo.spi.JDOImplHelper) JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException) Method(java.lang.reflect.Method) NucleusException(org.datanucleus.exceptions.NucleusException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) JDOException(javax.jdo.JDOException) JDOUserException(javax.jdo.JDOUserException) InvalidObjectException(java.io.InvalidObjectException) JDOFatalUserException(javax.jdo.JDOFatalUserException) NucleusException(org.datanucleus.exceptions.NucleusException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TransactionIsolationNotSupportedException(org.datanucleus.exceptions.TransactionIsolationNotSupportedException) TransactionActiveOnCloseException(org.datanucleus.exceptions.TransactionActiveOnCloseException) IOException(java.io.IOException) JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) JDOException(javax.jdo.JDOException)

Example 14 with JDOException

use of javax.jdo.JDOException in project hive by apache.

the class HMSHandler method createDefaultDB.

/**
 * create default database if it doesn't exist.
 *
 * This is a potential contention when HiveServer2 using embedded metastore and Metastore
 * Server try to concurrently invoke createDefaultDB. If one failed, JDOException was caught
 * for one more time try, if failed again, simply ignored by warning, which meant another
 * succeeds.
 *
 * @throws MetaException
 */
private void createDefaultDB() throws MetaException {
    try {
        RawStore ms = getMS();
        createDefaultCatalog(ms, wh);
        createDefaultDB_core(ms);
    } catch (JDOException e) {
        LOG.warn("Retrying creating default database after error: " + e.getMessage(), e);
        try {
            RawStore ms = getMS();
            createDefaultCatalog(ms, wh);
            createDefaultDB_core(ms);
        } catch (InvalidObjectException | InvalidOperationException e1) {
            throw new MetaException(e1.getMessage());
        }
    } catch (InvalidObjectException | InvalidOperationException e) {
        throw new MetaException(e.getMessage());
    }
}
Also used : JDOException(javax.jdo.JDOException) ExceptionHandler.newMetaException(org.apache.hadoop.hive.metastore.ExceptionHandler.newMetaException) ExceptionHandler.throwMetaException(org.apache.hadoop.hive.metastore.ExceptionHandler.throwMetaException)

Example 15 with JDOException

use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.

the class JDOQLTypedQueryImpl method parameter.

/* (non-Javadoc)
     * @see javax.jdo.JDOQLTypedQuery#parameter(java.lang.String, java.lang.Class)
     */
public <P> Expression<P> parameter(String name, Class<P> type) {
    assertIsOpen();
    discardCompiled();
    ExpressionImpl paramExpr = null;
    if (type == Boolean.class || type == boolean.class) {
        paramExpr = new BooleanExpressionImpl(type, name, ExpressionType.PARAMETER);
    } else if (type == Byte.class || type == byte.class) {
        paramExpr = new ByteExpressionImpl(type, name, ExpressionType.PARAMETER);
    } else if (type == Character.class || type == char.class) {
        paramExpr = new CharacterExpressionImpl(type, name, ExpressionType.PARAMETER);
    } else if (type == Double.class || type == double.class) {
        paramExpr = new NumericExpressionImpl(type, name, ExpressionType.PARAMETER);
    } else if (type == Float.class || type == float.class) {
        paramExpr = new NumericExpressionImpl(type, name, ExpressionType.PARAMETER);
    } else if (type == Integer.class || type == int.class) {
        paramExpr = new NumericExpressionImpl(type, name, ExpressionType.PARAMETER);
    } else if (type == Long.class || type == long.class) {
        paramExpr = new NumericExpressionImpl(type, name, ExpressionType.PARAMETER);
    } else if (type == Short.class || type == short.class) {
        paramExpr = new NumericExpressionImpl(type, name, ExpressionType.PARAMETER);
    } else if (type == String.class) {
        paramExpr = new StringExpressionImpl((Class<String>) type, name, ExpressionType.PARAMETER);
    } else if (Time.class.isAssignableFrom(type)) {
        paramExpr = new TimeExpressionImpl((Class<Time>) type, name, ExpressionType.PARAMETER);
    } else if (Date.class.isAssignableFrom(type)) {
        paramExpr = new DateExpressionImpl((Class<Date>) type, name, ExpressionType.PARAMETER);
    } else if (java.util.Date.class.isAssignableFrom(type)) {
        paramExpr = new DateTimeExpressionImpl((Class<java.util.Date>) type, name, ExpressionType.PARAMETER);
    } else if (ec.getApiAdapter().isPersistable(type)) {
        // Persistable class
        String typeName = type.getName();
        int pos = typeName.lastIndexOf('.');
        String qName = typeName.substring(0, pos + 1) + getQueryClassNameForClassName(typeName.substring(pos + 1));
        try {
            Class qClass = ec.getClassLoaderResolver().classForName(qName);
            Constructor ctr = qClass.getConstructor(new Class[] { Class.class, String.class, ExpressionType.class });
            Object candObj = ctr.newInstance(new Object[] { type, name, ExpressionType.PARAMETER });
            paramExpr = (ExpressionImpl) candObj;
        } catch (NoSuchMethodException nsme) {
            throw new JDOException("Class " + typeName + " has a Query class but has no constructor for parameters");
        } catch (IllegalAccessException iae) {
            throw new JDOException("Class " + typeName + " has a Query class but has no constructor for parameters");
        } catch (InvocationTargetException ite) {
            throw new JDOException("Class " + typeName + " has a Query class but has no constructor for parameters");
        } catch (InstantiationException ie) {
            throw new JDOException("Class " + typeName + " has a Query class but has no constructor for parameters");
        }
    } else {
        paramExpr = new ObjectExpressionImpl(type, name, ExpressionType.PARAMETER);
    }
    if (parameterExprByName == null) {
        parameterExprByName = new ConcurrentHashMap<>();
    }
    parameterExprByName.put(name, paramExpr);
    return paramExpr;
}
Also used : Time(java.sql.Time) Constructor(java.lang.reflect.Constructor) Date(java.sql.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) JDOException(javax.jdo.JDOException)

Aggregations

JDOException (javax.jdo.JDOException)32 PersistenceManager (javax.jdo.PersistenceManager)14 Transaction (javax.jdo.Transaction)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 Query (javax.jdo.Query)7 Iterator (java.util.Iterator)6 JDOUserException (javax.jdo.JDOUserException)6 NucleusException (org.datanucleus.exceptions.NucleusException)6 JDOUnsupportedOptionException (javax.jdo.JDOUnsupportedOptionException)5 Constructor (java.lang.reflect.Constructor)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 JDOFatalUserException (javax.jdo.JDOFatalUserException)4 PersistableExpression (javax.jdo.query.PersistableExpression)4 Collection (java.util.Collection)3 ClassNotResolvedException (org.datanucleus.exceptions.ClassNotResolvedException)3 Person (org.jpox.samples.models.company.Person)3 Method (java.lang.reflect.Method)2 Date (java.sql.Date)2 SQLException (java.sql.SQLException)2