Search in sources :

Example 1 with JDOUserException

use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.

the class JDOCodeGenerator method generate.

/**
 * @see CMPGenerator#generate(IASEjbCMPEntityDescriptor, File, File)
 */
public void generate(IASEjbCMPEntityDescriptor ejbcmp, File srcout, File classout) throws GeneratorException {
    String beanName = ejbcmp.getName();
    // StringBuffer to store validation exception messages if there are any.
    // If there are no validation exceptions, the reference will be null.
    StringBuffer validateex = null;
    boolean debug = logger.isLoggable(Logger.FINE);
    if (debug)
        // NOI18N
        logger.fine("gen file in " + srcout.getAbsolutePath());
    // We need to create a new ArrayList because model validation
    // returns an unmodifiable list.  This may be a place to look
    // for a performance improvement later for the case of empty
    // or singleton collection (extra copies).
    Collection c = new ArrayList(validateModel(ejbcmp));
    // if the mapping info is not present, throw the exception and
    // stop the generation process
    GeneratorException mappingMissingEx = getMappingMissingException(c);
    if (mappingMissingEx != null)
        throw mappingMissingEx;
    c.addAll(validateSupported(ejbcmp));
    JDOConcreteBeanGenerator cmpGenerator = getCMPGenerator(ejbcmp);
    MethodHelper mh = new MethodHelper(ejbcmp);
    c.addAll(cmpGenerator.validate(mh, beanName));
    if (!c.isEmpty()) {
        // Validation failed the test. We will try to display all the
        // exceptions in a concatenated message and a GeneratorException
        // is thrown.
        validateex = new StringBuffer();
        Iterator iter = c.iterator();
        while (iter.hasNext()) {
            Exception ex = (Exception) iter.next();
            if (debug)
                // NOI18N
                logger.log(Logger.FINE, "validation exception: ", ex);
            // NOI18N
            validateex.append(ex.getMessage()).append('\n');
        }
        if (!ignoreValidationResults)
            throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
            "CMG.ExceptionInValidate", beanName, bundle, validateex.toString());
    }
    try {
        Collection<File> newfiles = null;
        if (!ejbcmp.isEJB20())
            ejbcmp.setQueryParser(jdoqlParamDeclParser);
        // IMPORTANT:
        // Concrete impl class generation must happen before generation of
        // PC class as cmpGenerator will override cascadeDelete (DeleteAction)
        // property if it is set, and generatePC() saves .mapping file.
        newfiles = cmpGenerator.generate(mh, beanName, appName, srcout, classout);
        files.addAll(newfiles);
        newfiles = generatePC(ejbcmp, srcout, classout);
        files.addAll(newfiles);
        if (validateex != null)
            throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
            "CMG.ExceptionInValidate", beanName, bundle, validateex.toString());
    } catch (JDOUserException e) {
        // messages if there are any.
        throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
        "CMG.ExceptionInGenerate", beanName, bundle, e, validateex);
    } catch (EJBQLException e) {
        // validation messages if there are any.
        throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
        "CMG.ExceptionInGenerate", beanName, bundle, e, validateex);
    } catch (IOException e) {
        // validation messages if there are any.
        throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
        "CMG.IOExceptionInGenerate", beanName, bundle, e, validateex);
    }
}
Also used : ArrayList(java.util.ArrayList) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) IOException(java.io.IOException) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) ModelException(com.sun.jdo.api.persistence.model.ModelException) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) SQLException(java.sql.SQLException) DBException(org.netbeans.modules.dbschema.DBException) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) Schema2BeansException(org.netbeans.modules.schema2beans.Schema2BeansException) IOException(java.io.IOException) GeneratorException(com.sun.jdo.spi.persistence.support.ejb.codegen.GeneratorException) ConversionException(com.sun.jdo.api.persistence.mapping.ejb.ConversionException) Iterator(java.util.Iterator) Collection(java.util.Collection) GeneratorException(com.sun.jdo.spi.persistence.support.ejb.codegen.GeneratorException) File(java.io.File)

Example 2 with JDOUserException

use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.

the class JDOEJB11HelperImpl method writeSerializableObjectToByteArray.

/**
 * Serializes serializableObject into a byte array
 * @param serializableObject Instance of a Serializable Object
 * @return serializableObject serialized into a byte array
 */
public byte[] writeSerializableObjectToByteArray(Serializable serializableObject) {
    byte[] byteArray = null;
    if (serializableObject != null) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(bos);
            oos.writeObject(serializableObject);
            byteArray = bos.toByteArray();
        } catch (java.io.IOException e) {
            String clsName = serializableObject.getClass().getName();
            throw new JDOUserException(I18NHelper.getMessage(messages, "EXC_IOWriteSerializableObject", clsName), // NOI18N
            e);
        }
    }
    return byteArray;
}
Also used : java.io(java.io) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 3 with JDOUserException

use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.

the class ArrayList method addAll.

/**
 * Inserts all of the elements in in the specified Collection into this
 * ArrayList at the specified position.  Shifts the element currently at
 * that position (if any) and any subsequent elements to the right
 * (increases their indices).  The new elements will appear in the ArrayList
 * in the order that they are returned by the specified Collection's
 * iterator.
 *
 * @param index index at which to insert first element
 *              from the specified collection.
 * @param c elements to be inserted into this ArrayList.
 * @exception IndexOutOfBoundsException index out of range (index
 *            &lt; 0 || index &gt; size()).
 * @see java.util.ArrayList
 */
public boolean addAll(int index, Collection c) {
    if (allowNulls == false && c.contains(null)) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "sco.nulls_not_allowed"));
    }
    java.util.Vector errc = new java.util.Vector();
    if (elementType != null) {
        // iterate the collection and make a list of wrong elements.
        Iterator i = c.iterator();
        while (i.hasNext()) {
            Object o = i.next();
            if (!elementType.isAssignableFrom(o.getClass()))
                errc.add(o);
        }
    }
    if (errc != null && errc.size() > 0) {
        throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
        elementType.getName()), new ClassCastException(), errc.toArray());
    }
    // Mark the field as dirty
    StateManager stateManager = this.makeDirty();
    removed.removeAll(c);
    added.addAll(c);
    boolean modified = super.addAll(index, c);
    // Apply updates
    this.applyUpdates(stateManager, modified);
    return modified;
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) Iterator(java.util.Iterator) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 4 with JDOUserException

use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.

the class ArrayList method addAll.

/**
 * Appends all of the elements in the specified Collection to the end of
 * this ArrayList, in the order that they are returned by the specified
 * Collection's Iterator.
 *
 * @param c elements to be inserted into this ArrayList.
 * @exception IndexOutOfBoundsException index out of range (index
 *            &lt; 0 || index &gt; size()).
 * @see java.util.ArrayList
 */
public boolean addAll(Collection c) {
    if (allowNulls == false && c.contains(null)) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "sco.nulls_not_allowed"));
    }
    java.util.Vector errc = new java.util.Vector();
    if (elementType != null) {
        // iterate the collection and make a list of wrong elements.
        Iterator i = c.iterator();
        while (i.hasNext()) {
            Object o = i.next();
            if (!elementType.isAssignableFrom(o.getClass()))
                errc.add(o);
        }
    }
    if (errc != null && errc.size() > 0) {
        throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
        elementType.getName()), new ClassCastException(), errc.toArray());
    }
    // Mark the field as dirty
    StateManager stateManager = this.makeDirty();
    removed.removeAll(c);
    added.addAll(c);
    boolean modified = super.addAll(c);
    // Apply updates
    this.applyUpdates(stateManager, modified);
    return modified;
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) Iterator(java.util.Iterator) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Example 5 with JDOUserException

use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.

the class ArrayList method add.

/**
 * Inserts the specified element at the specified position in this ArrayList.
 *
 * @param index index at which the specified element is to be inserted.
 * @param element element to be inserted.
 * @exception IndexOutOfBoundsException index is out of range
 *            (index &lt; 0 || index &gt; size()).
 * @see java.util.ArrayList
 */
public void add(int index, Object element) {
    if (allowNulls == false && element == null) {
        throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
        "sco.nulls_not_allowed"));
    }
    if (elementType == null || elementType.isAssignableFrom(element.getClass())) {
        // Mark the field as dirty
        StateManager stateManager = this.makeDirty();
        super.add(index, element);
        if (removed.remove(element) == false)
            added.add(element);
        // Apply updates
        this.applyUpdates(stateManager, true);
    } else {
        throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
        elementType.getName()), new ClassCastException(), new Object[] { element });
    }
}
Also used : StateManager(com.sun.jdo.spi.persistence.support.sqlstore.StateManager) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException)

Aggregations

JDOUserException (com.sun.jdo.api.persistence.support.JDOUserException)20 StateManager (com.sun.jdo.spi.persistence.support.sqlstore.StateManager)14 Iterator (java.util.Iterator)6 PersistenceManager (com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager)2 ArrayList (java.util.ArrayList)2 ConversionException (com.sun.jdo.api.persistence.mapping.ejb.ConversionException)1 ModelException (com.sun.jdo.api.persistence.model.ModelException)1 JDODataStoreException (com.sun.jdo.api.persistence.support.JDODataStoreException)1 JDOException (com.sun.jdo.api.persistence.support.JDOException)1 JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)1 JDOUnsupportedOptionException (com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException)1 GeneratorException (com.sun.jdo.spi.persistence.support.ejb.codegen.GeneratorException)1 EJBQLException (com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException)1 com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint (com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint)1 java.io (java.io)1 File (java.io.File)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 DBException (org.netbeans.modules.dbschema.DBException)1