Package org.paquitosoft.lml.model.exception

Examples of org.paquitosoft.lml.model.exception.InternalErrorException


        // Create an instance of default DAO
        IDefaultDAO dao = DAOFactory.getDefaultDAO(connection);

        // Check join table name
        if (joinTableName == null) {
            throw new InternalErrorException("FindExternalRelatedEntitiesAction::execute -> The attribute you're trying to fetch '" +
                    externalAssociatedAttribute.getName() + "' does not have a 'joinTableName' annotation value.");
        }

        // Get the list type
        Class listType = LMLGlobalOperations.getCollectionType(externalAssociatedAttribute);
View Full Code Here


                result = getNextIdValue(getLastEntityIdentifier(entityType, conn), pkType); // We need to search entity's table because of the chance the table is not emtpy.
                stm = conn.prepareStatement(INSERT_COUNTER_QUERY);
                stm.setString(1, tableName);               
                ModelUtilities.insertValueInQuery(result, stm, 2);
                if (stm.executeUpdate() != 1) {
                    throw new InternalErrorException("IdentifierDAOImpl::generateIdentifier -> Insert new row failed!");
                }
            }
           
            // Update next available value
            stm = conn.prepareStatement(UPDATE_COUNTER_QUERY);
            ModelUtilities.insertValueInQuery(getNextIdValue(result, pkType), stm, 1);
            stm.setString(2, tableName);           
            if (stm.executeUpdate() != 1) {
                throw new InternalErrorException("IdentifierDAOImpl::generateIdentifier -> Update next available value failed!");
            }
           
        } catch (SQLException e) {
            throw new InternalErrorException("IdentifierDAOImpl::generateIdentifier", e);
        } catch (Exception e) {
            throw new InternalErrorException("IdentifierDAOImpl::generateIdentifier", e);
        } finally {
            closeResouces(stm, rs);
        }
       
        return result;
View Full Code Here

            ResultSet rs = stm.executeQuery();
            if (rs.next()) {
                result = ModelUtilities.getValueFromQuery(pkFields.get(0).getType(), rs, idColumnName);
            }
        } catch (SQLException e) {
            throw new InternalErrorException("IdentiiferDAOImpl::getLastEntityIdentifier -> Error while looking for the last used entity " +
                    "identifier in its table.", e);
        }
       
        return result;
    }
View Full Code Here

        if (dataSourceJndiName.length() > 0 && dataSource == null) {
            try {               
                Context ctx = new InitialContext();
                dataSource = (DataSource) ctx.lookup(dataSourceJndiName);               
            } catch (NamingException ex) {
                throw new InternalErrorException("ActionProcess::constructor -> Naming error while getting dataSource.", ex);
            }
        } else if (dataSource == null) {
            connectionPool = ConnectionPool.getInstance();
        }
    }
View Full Code Here

            // Rollback when needed
            if (action instanceof ITransactionalAction) {
                try {
                    conn.rollback();
                } catch (SQLException ex) {
                    throw new InternalErrorException("ActionProcessor::processAction -> Error while rolling back.", ex);
                }
            }           
            throw new InternalErrorException("ActionProcessor::processAction -> Error while processing action.", e);
           
        } catch (InternalErrorException e) {
           
            // Rollback when needed
            if (action instanceof ITransactionalAction) {
                try {
                    conn.rollback();
                } catch (SQLException ex) {
                    throw new InternalErrorException("ActionProcessor::processAction -> Error while rolling back.", ex);
                }
            }           
            throw e;
           
        } finally {
           
            // Commit when needed
            if (action instanceof ITransactionalAction) {
                try {
                    conn.commit();
                } catch (SQLException ex) {
                    throw new InternalErrorException("ActionProcessor::processAction -> Error while commiting.", ex);
                }
            }
           
            // Release connection
            if (conn != null) releaseConnection(conn);
View Full Code Here

        // Check wether to get a connection from a server or from the connection pool
        if (dataSource != null) {
            try {
                result = dataSource.getConnection();           
            } catch (SQLException ex) {
                throw new InternalErrorException("ActionProcess::getConnection -> SQL error while getting dataSource connection", ex);
            }
        } else {
            result = connectionPool.getConnection();           
        }
       
View Full Code Here

        // Check wether to give the connection back to dataSource or the connectionPool
        if (dataSource != null) {
            try {
                connection.close();
            } catch (SQLException ex) {
                throw new InternalErrorException("ActionProcess::releaseConnection -> SQL error while closing dataSource connection", ex);
            }
        } else {
            connectionPool.releaseConnection(connection);
        }       
    }
View Full Code Here

                } catch (DataNotFoundException e) {
                    if (AssociationType.REQUIRED.equals(f.getAnnotation(PersistentAttribute.class).readAssociationType())) {
                        throw e;
                    }
                } catch (ReflectionException e) {
                    throw new InternalErrorException("ReadEntityAction::fillEntity", e);
                } catch (IllegalAccessException e) {
                    throw new InternalErrorException("ReadEntityAction::fillEntity", e);
                }
            }

            for (Field f : associatedLists) {
                f.setAccessible(true);
                try {
                    // Get the query
                    String query = ModelUtilities.generateFindRelatedEntitiesQuery(f);
                   
                    // Get the entity identifier/s
                    Object id = ModelUtilities.getEntityIdentifier(entity);
                   
                    // If pk is a compund key we must extract each value (they are sorted by name)
                    if (id.equals(entity)) {
                        List<Field> pkFields = ModelUtilities.getEntityIdentifierFields(entity.getClass());
                        Object[] pkFieldValues = new Object[pkFields.size()];
                        for (int i = 0; i < pkFields.size(); i++) {
                            pkFields.get(i).setAccessible(true);
                            pkFieldValues[i] = pkFields.get(i).get(entity);
                        }
                        id = pkFieldValues;
                    }

                    // The action depends on the type of association (1-N or N-M)
                    INonTransactionalAction action = null;
                    AssociatedEntityList ann = f.getAnnotation(AssociatedEntityList.class);
                    if (ann != null && ann.joinTableName().length() > 0) {
                        action = new FindExternalRelatedEntitiesAction(entity, f, ann.joinTableName(), detailLevel - 1);
                    } else {
                        action = new FindEntitiesAction(query, LMLGlobalOperations.getCollectionType(f), detailLevel - 1, id);
                    }

                    // Search the collection and set it into the related attribute
                    f.set(entity, action.execute(connection));
                   
                } catch (DataNotFoundException exception) {
                    if (AssociationType.REQUIRED.equals(f.getAnnotation(AssociatedEntityList.class).readAssociationType())) {
                        throw exception;
                    }
                } catch (ReflectionException e) {
                    throw new InternalErrorException("ReadEntityAction::fillEntity", e);
                } catch (IllegalAccessException e) {
                    throw new InternalErrorException("ReadEntityAction::fillEntity", e);
                }

            }
           
        }
View Full Code Here

                if (pkFields.size() == 1) {
                    pkFields.get(0).setAccessible(true);
                    pkFields.get(0).set(entity, id);
                } else {
                    // A compound key cannot be auto-generated
                    throw new InternalErrorException("DefaultDAOImpl::insert -> A compound key cannot be auto-generated. (" + entity + ")");
                }
            }
           
            // Get the query
            String query = ModelUtilities.getQueryForInsert(entity.getClass());
            String[] fieldNames = query.substring(query.indexOf('(') + 1, query.indexOf(')')).split(",");

            // Prepare query
            stm = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
           
            // Fill query
            for (int i = 0; i < fieldNames.length; i++) {
                logger.log(Level.INFO, "Value we set into insert query: " + fieldNames[i] + " -- " +
                        ModelUtilities.getFieldValue(fieldNames[i], entity));
                ModelUtilities.insertValueInQuery(ModelUtilities.getFieldValue(fieldNames[i], entity), stm, (i + 1));
            }

            // Execute insert query
            int i = stm.executeUpdate();

            // If database generated PK, we need to get it
            if (entityId == null && !entity.getClass().getAnnotation(PersistentEntity.class).generateKey()) {
                ResultSet pkRs = stm.getGeneratedKeys();
                if (pkRs != null) {
                    if (pkRs.next()) {
                        List<Field> pkFields = ModelUtilities.getEntityIdentifierFields(entity.getClass());
                        if (pkFields.size() == 1) {
                            Field pkField = pkFields.get(0);
                            pkField.setAccessible(true);
//                            ResultSetMetaData rsmd = pkRs.getMetaData();
                            pkField.set(entity, ModelUtilities.getValueFromQuery(pkField.getType(), pkRs, 1));
                        } else {
                            // A compound key cannot be auto-generated
                            throw new InternalErrorException("DefaultDAOImpl::insert -> A compound key cannot be auto-generated. (" + entity + ")");
                        }
                    } else {
                        throw new InternalErrorException("ERROR: COULD NOT RETRIEVE PK GENERATED BY DATBASE.");
                    }
                } else {
                    throw new AutogeneratedKeysReturnNotSupportedException();
                }
            }           
           
            // We must have inserted exactly one row
            if (i != 1) {
                    throw new InternalErrorException("ERROR: INSERT METHOD FAILED. " + i + " records have been inserted. (" + entity + ")");
            }

        } catch (SQLException e) {
            logger.log(Level.SEVERE, "SQL Exception while inserting: " + e.getMessage(), e);
            throw new InternalErrorException("Database Exception while inserting.... (" + entity + ")", e);
        } catch (IllegalAccessException e) {
            logger.log(Level.SEVERE, "Reflection exception while inserting (" + entity + "): " + e.getMessage(), e);
            throw new ReflectionException(e);
        } finally {
                closeResouces(stm, null);
View Full Code Here

                throw new DataNotFoundException("Entity: " + entityClass + " with id: " + entityId.toString() + " has not been found");
            }

        } catch (SQLException e) {
            logger.log(Level.SEVERE, "SQL Exception while inserting: " + e.getMessage(), e);
            throw new InternalErrorException("Database Exception....", e);
        } catch (IllegalAccessException e) {
            logger.log(Level.SEVERE, "Reflection exception while inserting: " + e.getMessage(), e);
            throw new ReflectionException("DefaultDAO::read\n", e);
        } catch (IllegalArgumentException e) {
            logger.log(Level.SEVERE, "Reflection exception while inserting: " + e.getMessage(), e);
View Full Code Here

TOP

Related Classes of org.paquitosoft.lml.model.exception.InternalErrorException

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.