Search in sources :

Example 91 with JDOUserException

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

the class TypeMetadataImpl method newPropertyMetadata.

/* (non-Javadoc)
     * @see javax.jdo.metadata.ComponentMetadata#newPropertyMetadata(java.lang.reflect.Method)
     */
public PropertyMetadata newPropertyMetadata(Method method) {
    String methodName = method.getName();
    String name = null;
    if (methodName.startsWith("set")) {
        name = methodName.substring(3);
    } else if (methodName.startsWith("get")) {
        name = methodName.substring(3);
    } else if (methodName.startsWith("is")) {
        name = methodName.substring(2);
    } else {
        throw new JDOUserException("Method " + methodName + " is not a Java-bean method");
    }
    String propertyName = name.substring(0, 1).toLowerCase() + name.substring(1);
    PropertyMetaData internalPmd = getInternal().newPropertyMetadata(propertyName);
    PropertyMetadataImpl pmd = new PropertyMetadataImpl(internalPmd);
    pmd.parent = this;
    return pmd;
}
Also used : PropertyMetaData(org.datanucleus.metadata.PropertyMetaData) JDOUserException(javax.jdo.JDOUserException)

Example 92 with JDOUserException

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

the class JDOPersistenceManager method refreshAll.

/**
 * Method to do a refresh of a collection of objects.
 * @param pcs The Objects
 * @throws JDOUserException thrown if instances could not be refreshed.
 */
public void refreshAll(Collection pcs) {
    assertIsOpen();
    ArrayList failures = new ArrayList();
    Iterator iter = pcs.iterator();
    while (iter.hasNext()) {
        try {
            jdoRefresh(iter.next());
        } catch (JDOException e) {
            failures.add(e);
        }
    }
    if (!failures.isEmpty()) {
        throw new JDOUserException(Localiser.msg("010037"), (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 93 with JDOUserException

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

the class JDOPersistenceManager method makeNontransactionalAll.

/**
 * Method to make nontransactional a collection of objects.
 * @param pcs The objects.
 * @throws JDOUserException thrown if objects could not be made nontransactional
 */
public void makeNontransactionalAll(Collection pcs) {
    assertIsOpen();
    assertActiveTransaction();
    ArrayList failures = new ArrayList();
    Iterator i = pcs.iterator();
    while (i.hasNext()) {
        try {
            jdoMakeNontransactional(i.next());
        } catch (RuntimeException e) {
            failures.add(e);
        }
    }
    if (!failures.isEmpty()) {
        throw new JDOUserException(Localiser.msg("010043"), (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)

Example 94 with JDOUserException

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

the class JDOPersistenceManager method makeTransientAll.

/**
 * Method to make transient a collection of objects.
 * @param pcs The objects
 * @param useFetchPlan Whether to use the fetch plan when making transient
 * @throws JDOUserException thrown if objects could not be made transient.
 */
public void makeTransientAll(Collection pcs, boolean useFetchPlan) {
    assertIsOpen();
    ArrayList failures = new ArrayList();
    Iterator i = pcs.iterator();
    FetchPlanState state = null;
    if (useFetchPlan) {
        // Create a state object to carry the processing state info
        state = new FetchPlanState();
    }
    while (i.hasNext()) {
        try {
            jdoMakeTransient(i.next(), state);
        } catch (RuntimeException e) {
            failures.add(e);
        }
    }
    if (!failures.isEmpty()) {
        throw new JDOUserException(Localiser.msg("010041"), (Exception[]) failures.toArray(new Exception[failures.size()]));
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) FetchPlanState(org.datanucleus.FetchPlanState) 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)

Example 95 with JDOUserException

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

the class JDOPersistenceManager method makePersistentAll.

/**
 * JDO method to make persistent a collection of objects.
 * Throws a JDOUserException if objects could not be made persistent.
 * @param pcs The objects to persist
 * @return The persistent objects
 */
public <T> Collection<T> makePersistentAll(Collection<T> pcs) {
    assertIsOpen();
    assertWritable();
    try {
        Object[] persistedPcs = ec.persistObjects(pcs.toArray());
        Collection persisted = new ArrayList();
        for (int i = 0; i < persistedPcs.length; i++) {
            persisted.add(persistedPcs[i]);
        }
        return persisted;
    } catch (NucleusUserException nue) {
        Throwable[] failures = nue.getNestedExceptions();
        throw new JDOUserException(Localiser.msg("010039"), failures);
    }
}
Also used : NucleusUserException(org.datanucleus.exceptions.NucleusUserException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) JDOUserException(javax.jdo.JDOUserException)

Aggregations

JDOUserException (javax.jdo.JDOUserException)191 PersistenceManager (javax.jdo.PersistenceManager)163 Transaction (javax.jdo.Transaction)161 Query (javax.jdo.Query)94 Iterator (java.util.Iterator)54 Collection (java.util.Collection)45 Employee (org.jpox.samples.models.company.Employee)35 List (java.util.List)33 HashSet (java.util.HashSet)30 ArrayList (java.util.ArrayList)22 Extent (javax.jdo.Extent)22 JDOException (javax.jdo.JDOException)15 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)15 CollectionHolder (org.jpox.samples.types.container.CollectionHolder)15 Map (java.util.Map)13 MapHolder (org.jpox.samples.types.container.MapHolder)13 JDOFatalUserException (javax.jdo.JDOFatalUserException)12 NucleusException (org.datanucleus.exceptions.NucleusException)10 TransactionActiveOnCloseException (org.datanucleus.exceptions.TransactionActiveOnCloseException)10 Person (org.jpox.samples.models.company.Person)10