Package de.iritgo.aktera.persist

Examples of de.iritgo.aktera.persist.PersistenceException


      {
        if (withAuto)
        {
          if (throwException)
          {
            throw new PersistenceException("$keelNullNotAllowed|" + myMetaData.getDescription(oneFieldName));
          }

          return false;
        }

        if (! myMetaData.isAutoIncremented(oneFieldName))
        {
          if (throwException)
          {
            throw new PersistenceException("$keelNullNotAllowed|" + myMetaData.getDescription(oneFieldName));
          }

          return false;
        }
      }
View Full Code Here


      cce.printStackTrace();
      //Screen is not always logged, esepcially on MS, so record in
      // application log for later analysis.
      log.error(msg, cce);
      throw new PersistenceException(msg, cce);
    }
    catch (NumberFormatException ne)
    {
      String msg = "Error on field " + fieldName + ". Cannot parse value '" + getFieldString(fieldName) + "'"
              + " into type " + myMetaData.getType(fieldName);

      throw new PersistenceException(msg, ne);
    }

    if (log.isDebugEnabled())
    {
      log.debug("Set Field #/FieldName/Value" + index + '/' + fieldName + '/' + this.getFieldData(fieldName));
View Full Code Here

        return rs.getDouble(1);
      }
    }
    catch (SQLException se)
    {
      throw new PersistenceException(se);
    }
    finally
    {
      cleanUp(myConnection, s, rs, null);
    }
View Full Code Here

      setField(fieldName, myIdGenerator.getNextIntegerId());
    }
    catch (IdException ie)
    {
      log.error("Unable to auto-increment field", ie);
      throw new PersistenceException("$keelFieldNoAutoInc|" + myMetaData.getDescription(fieldName), ie);
    }
  }
View Full Code Here

        }
      }
    }
    catch (Exception e)
    {
      throw new PersistenceException(e);
    }
    finally
    {
      try
      {
        myConnection.close();
      }
      catch (SQLException se)
      {
        throw new PersistenceException("Unable to close/release connection", se);
      }
    }
  }
View Full Code Here

    this.currentErrors.clear();
    currentErrors.putAll(validateAll());

    if (currentErrors.size() > 0)
    {
      throw new PersistenceException("Field validation errors in persistent '" + myMetaData.getName() + "': ",
              getErrors());
    }

    /*
     * Go through all the fields, setting to their default values if they
     * are null
     */
    String oneFieldName = null;
    Object oneFieldValue = null;

    for (Iterator i = myMetaData.getFieldNames().iterator(); i.hasNext();)
    {
      oneFieldName = (String) i.next();
      oneFieldValue = getField(oneFieldName);

      if (getField(oneFieldName) == null)
      {
        setField(oneFieldName, myMetaData.getDefaultValue(oneFieldName));
      }
      else if (oneFieldValue.toString().equals(""))
      {
        setField(oneFieldName, myMetaData.getDefaultValue(oneFieldName));
      }
    }

    boolean needComma = false;

    haveAllKeys(false, true);

    if (getHelper() != null)
    {
      getHelper().beforeAdd(this);
    }

    SuperString sqlCommand = new SuperString(96);

    sqlCommand.append("INSERT INTO ");
    sqlCommand.append(myMetaData.getTableName());
    sqlCommand.append(" (");

    SuperString valuesCommand = new SuperString(64);

    valuesCommand.append(") VALUES (");

    boolean needCommaValues = false;

    String identityFieldName = null;

    for (Iterator i = myMetaData.getFieldNames().iterator(); i.hasNext();)
    {
      oneFieldName = (String) i.next();

      checkField(oneFieldName, getFieldString(oneFieldName));

      if ("identity".equals(myMetaData.getAutoIncremented(oneFieldName)))
      {
        identityFieldName = oneFieldName;

        continue;
      }

      if (needComma)
      {
        sqlCommand.append(", ");
      }

      sqlCommand.append(myMetaData.getDBFieldName(oneFieldName));
      needComma = true;

      if (needCommaValues)
      {
        valuesCommand.append(", ");
      }

      if (myMetaData.isAutoIncremented(oneFieldName))
      {
        /*
         * If identityFieldName is not null, we've already used the one
         * (and only) identity for this table
         */
        if ((identityFieldName == null) && myMetaData.isKeyField(oneFieldName)
                && myMetaData.getDatabaseType().isIdentitySupported()
                && (myMetaData.getIdGenerator(oneFieldName) == null))
        {
          // Native auto-inc is supported using "IDENTITY" type
          // syntax
          identityFieldName = oneFieldName;
          valuesCommand.append(myMetaData.getDatabaseType().getInsertIdentitySyntax());
        }
        else
        {
          setAutoIncrement(oneFieldName);
          valuesCommand.append("?");
        }
      }
      else
      {
        valuesCommand.append("?");
      }

      needCommaValues = true;
    } /* for each field */
    //Now we merge the values of the parallel loops
    sqlCommand.append(valuesCommand);
    sqlCommand.append(")");

    try
    {
      Connection myConnection = null;
      PreparedStatement ps = null;
      Statement s = null;
      ResultSet rs = null;

      try
      {
        if (currentTransaction != null)
        {
          myConnection = currentTransaction.getConnection();
        }
        else
        {
          try
          {
            myConnection = myDataSource.getConnection();
          }
          catch (ConcurrentModificationException cme)
          {
            addError(cme);
            throw new PersistenceException("Unable to prepare statement", cme, getErrors());
          }
        }

        ps = myConnection.prepareStatement(sqlCommand.toString());

        // Lock the DB table so we can retrieve the identity field
        // in a concurrent-safe fashion
        this.lock();

        // populate the fields for the update
        int count = 1;

        for (Iterator i = myMetaData.getFieldNames().iterator(); i.hasNext();)
        {
          oneFieldName = (String) i.next();

          if ("identity".equals(myMetaData.getAutoIncremented(oneFieldName)))
          {
            continue;
          }

          //ACR: Changed to properly set based on types. Still some
          // work
          //to do for blobs....
          this.setPreparedStatementObject(ps, count, oneFieldName);
          count++;

          //}
        } /* for each field */
        if (log.isDebugEnabled())
        {
          log.debug("Executing: " + sqlCommand.toString() + "(" + ps.toString() + ") on " + toString());
        }

        int updateCount = ps.executeUpdate();

        if ((updateCount == 0) && (getCheckZeroUpdate()))
        {
          throw new PersistenceException("No records updated", getErrors());
        }

        ps.close();
        ps = null;

        if (identityFieldName != null)
        {
          s = myConnection.createStatement();
          rs = s.executeQuery(myMetaData.getDatabaseType().getRetrieveIdentitySyntax(myMetaData,
                  identityFieldName));

          if (rs.next())
          {
            String identityValue = rs.getString(1);

            setField(identityFieldName, identityValue);
            rs.close();
            rs = null;
            s.close();
            s = null;
          }
          else
          {
            throw new PersistenceException("No value returned for identity field: " + identityFieldName,
                    getErrors());
          }
        }
      }
      catch (ClassCastException cce)
      {
        addError(cce);
        throw new PersistenceException("Unable to add record to database" + toString() + ":" + cce.getMessage()
                + " (" + sqlCommand + ")", getErrors());
      }
      catch (PersistenceException de)
      {
        addError(de);
        throw new PersistenceException("Unable to add record to database" + toString() + ":" + de.getMessage()
                + " (" + sqlCommand + ")", getErrors());
      }
      finally
      {
        //unlock the DB table
        this.unlock();
        cleanUp(myConnection, s, rs, ps);
      }

      setStatus(Persistent.CURRENT);

      if (getHelper() != null)
      {
        getHelper().afterAdd(this);
      }
    }
    catch (SQLException se)
    {
      addError(se);
      throw new PersistenceException(se, getErrors());
    }
  } /* add() */
 
View Full Code Here

      rs.close();
      rs = null;
    }
    catch (Exception de)
    {
      throw new PersistenceException(de);
    }
    finally
    {
      cleanUp(myConnection, s, rs, null);
    }
View Full Code Here

      s = null;

      if ((updateCount == 0) && (getCheckZeroUpdate()))
      {
        log.error("No record(s) deleted for SQL '" + sqlCommand.toString() + "'");
        throw new PersistenceException("No record(s) deleted.");
      }
    }
    catch (SQLException se)
    {
      throw new PersistenceException(se);
    }
    finally
    {
      cleanUp(myConnection, s, null, null);
    }
View Full Code Here

    {
      throw de;
    }
    catch (SQLException se)
    {
      throw new PersistenceException(se);
    }
    finally
    {
      cleanUp(myConnection, s, null, null);
    }
View Full Code Here

      return true;
    }
    catch (SQLException se)
    {
      addError(se);
      throw new PersistenceException(se.getMessage() + " - " + toString());
    }
    finally
    {
      cleanUp(myConnection, s, rs, null);
    }
View Full Code Here

TOP

Related Classes of de.iritgo.aktera.persist.PersistenceException

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.