Package de.iritgo.aktera.persist

Examples of de.iritgo.aktera.persist.PersistenceException


   */
  public String getFieldDecimalFormatted(String fieldName, String formatPattern) throws PersistenceException
  {
    if (! myMetaData.hasField(fieldName))
    {
      throw new PersistenceException("(" + getName() + ") No such field as " + fieldName);
    }

    Object o = getFieldData(fieldName);

    if (o == null)
View Full Code Here


    Object o = getFieldData(fieldName);

    if (o == null)
    {
      throw new PersistenceException("Field '" + fieldName + "' was null, cannot return as int");
    }

    String strVal = "";

    try
    {
      strVal = o.toString();

      if (strVal == null)
      {
        throw new PersistenceException("(" + getName() + ") Unable to get int value from field " + fieldName
                + ", value was '" + strVal + "'");
      }

      return Integer.parseInt(strVal);
    }
    catch (NumberFormatException ex)
    {
      throw new PersistenceException("(" + getName() + ") Unable to parse an integer value from field "
              + fieldName + " which contained '" + strVal + "'", ex);
    }
  } /* getFieldInt(String) */
 
View Full Code Here

        } /* for each field */
        foundKeys.add(oneKeyString.toString());
      }
      else
      {
        throw new PersistenceException("(" + getName() + ") No such record" + toString());
      }

      if (doRowLevelCheck)
      {
        checkAllowed("L");
      }

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

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

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

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

    boolean needComma = false;

    /* build an update statement - again we must call haveKeyFields */
    /* to be sure we have all of the keys */
    haveAllKeys(true, true);

    StringBuffer sqlCommand = new StringBuffer("UPDATE ");

    sqlCommand.append(myMetaData.getTableName());
    sqlCommand.append(" SET ");

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

      /* We skip any key fields in the update part (not allowed to */
      /* upate them). Also skip any virtual fields */
      if ((! myMetaData.isKeyField(oneFieldName)) && (! myMetaData.isAutoIncremented(oneFieldName)))
      {
        checkField(oneFieldName, getField(oneFieldName));

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

        if (! myMetaData.isKeyField(oneFieldName))
        {
          sqlCommand.append(myMetaData.getDBFieldName(oneFieldName));
          sqlCommand.append(" = ");
          //updated by Adam to do proper prep for update SQL
          //sqlCommand.append(quoteIfNeeded(oneFieldName, null));
          sqlCommand.append("?");
          sqlCommand.append(" ");
          needComma = true;
        }
      } /* if it's not a key field */
    }

    sqlCommand.append(buildWhereClauseBuffer(false));

    if (sqlCommand == null)
    {
      throw new PersistenceException("Internal error: (" + getName() + ") No SQL command built for this update");
    }

    PreparedStatement ps = null;
    Connection myConnection = null;

    //Statement s = null;
    try
    {
      if (currentTransaction != null)
      {
        myConnection = currentTransaction.getConnection();
      }
      else
      {
        myConnection = myDataSource.getConnection();
      }

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

      //      populate the fields for the update
      int count = 1;
      String oneFieldName = null;

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

        if ((! myMetaData.isKeyField(oneFieldName)) && (! myMetaData.isAutoIncremented(oneFieldName)))
        {
          setPreparedStatementObject(ps, count, oneFieldName);

          count++;
        }

        //}
      } /* for each field */
      //s = myConnection.createStatement();
      if (log.isDebugEnabled())
      {
        log.debug("Executing: " + sqlCommand.toString());
      }

      //int updateCount = s.executeUpdate(sqlCommand.toString());
      int updateCount = ps.executeUpdate();

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

      case Persistent.QUERY:
        return isAllowed("L");

      default:
        throw new PersistenceException("Operation " + operation + " is not understood");
    }
  }
View Full Code Here

    {
      dbMutex.acquire();
    }
    catch (InterruptedException ie)
    {
      throw new PersistenceException(ie);
    }

    if (log.isDebugEnabled())
    {
      log.debug("Acquired mutex lock for " + dbKeyName);
View Full Code Here

   */
  public synchronized void unlock() throws PersistenceException
  {
    if (dbLocks == null)
    {
      throw new PersistenceException("$keelNoDBLockMap");
    }

    String dbKeyName = getName();
    Mutex dbMutex = null;

    if ((dbMutex = (Mutex) dbLocks.get(dbKeyName)) == null)
    {
      throw new PersistenceException("DB lock mutex not found for " + dbKeyName);
    }

    dbMutex.release();

    if (log.isDebugEnabled())
View Full Code Here

    PersistentMetaData pmd = getMetaData();
    Relation r = pmd.getRelation(detailName);

    if (r == null)
    {
      throw new PersistenceException("No such relation as '" + detailName + "'");
    }

    if (r.getType() != Relation.DETAIL)
    {
      throw new PersistenceException("Relation '" + detailName + "' is not a detail relation");
    }

    String toPersistent = r.getToPersistent();
    Persistent detList = myFactory.create(toPersistent);
    String oneFieldName = null;
View Full Code Here

    PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors(newBean);

    if (props.length == 0)
    {
      throw new PersistenceException("Class '" + newBean.getClass().getName() + "' declares no fields");
    }

    PropertyDescriptor oneProp = null;
    String fieldName = null;

    for (int i = 0; i < props.length; i++)
    {
      oneProp = props[i];
      fieldName = getFieldNameIgnoreCase(oneProp.getName());

      if (myMetaData.getFieldNames().contains(fieldName))
      {
        Object oneValue = null;

        try
        {
          oneValue = PropertyUtils.getProperty(newBean, oneProp.getName());
        }
        catch (Exception ie)
        {
          throw new PersistenceException("Unable to retrieve property '" + oneProp.getName()
                  + "' from object of class '" + newBean.getClass().getName() + "'", ie);
        }

        setField(fieldName, oneValue);
      }
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.