It looks like MySQL 4.1.2a isn't handling multi-delete statements in this
form (from StandardRDBMSAdapter. clearBinding(Connection, Uri)): 
        "delete BINDING from BINDING c, URI u where c.URI_ID = u.URI_ID and
u.URI_STRING = ?"

However, if you issue the following (notice the use of the 'BINDING' table
alias, 'c'):
        "delete c from BINDING c, URI u where c.URI_ID = u.URI_ID and
u.URI_STRING = ?"

Then it gets executed correctly. A solution would be to replace all
multi-delete statements in the first form with their equivalents in the
second, by subclassing and overriding any method containing such statements.
Since the domain configuration file lets you specify a store adapter class,
this approach turns out to be very straightforward. I'm attaching an adapter
class extending Slide's MySqlRDBMSAdapter that overrides methods using these
multi-delete statements. It has been tested and works just fine.

-Alejandro
/*
 * Project: wf-data
 * File:    MySqlAdapter.java
 * Created: 29/06/2004
 */
package mx.connecto.repository.sld;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.apache.slide.common.Service;
import org.apache.slide.common.ServiceAccessException;
import org.apache.slide.common.Uri;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionNumber;
import org.apache.slide.store.impl.rdbms.MySqlRDBMSAdapter;
import org.apache.slide.structure.ObjectNode;
import org.apache.slide.structure.ObjectNotFoundException;
import org.apache.slide.util.logger.Logger;

/**
 * <br/>Project: wf-data
 * <br/>Created: 29/06/2004
 * @author Alejandro Gu�zar
 * @version $Revision$ $Date$
 */
public class MySqlAdapter extends MySqlRDBMSAdapter {

  /**
   * @param service
   * @param logger
   */
  public MySqlAdapter(Service service, Logger logger) {
    super(service, logger);
  }
  
  /* (non-Javadoc)
   * @see org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeObject(
   *  java.sql.Connection, org.apache.slide.common.Uri, 
   *  org.apache.slide.structure.ObjectNode)
   */
  public void removeObject(Connection connection, Uri uri, ObjectNode object)
      throws ServiceAccessException, ObjectNotFoundException {
    PreparedStatement statement = null;
    try {
      clearBinding(connection, uri);
      
      // delete links
      try {
        statement =
          connection.prepareStatement(
          "delete l from LINKS l, URI u where l.URI_ID = u.URI_ID and u.URI_STRING = ?");
        statement.setString(1, uri.toString());
        statement.executeUpdate();
      } finally {
        close(statement);
      }
      // delete version history
      // FIXME: Is this true??? Should the version history be removed if the object is removed???
      try {
        statement =
          connection.prepareStatement(
          "delete vh from VERSION_HISTORY vh, URI u where vh.URI_ID = u.URI_ID and u.URI_STRING = ?");
        statement.setString(1, uri.toString());
        statement.executeUpdate();
      } 
      finally {
        close(statement);
      }
      // delete version
      try {
        statement =
          connection.prepareStatement(
          "delete v from VERSION v, URI u where v.URI_ID = u.URI_ID and u.URI_STRING = ?");
        statement.setString(1, uri.toString());
        statement.executeUpdate();
      } 
      finally {
        close(statement);
      }
      // delete the object itself
      try {
        statement =
          connection.prepareStatement(
          "delete o from OBJECT o, URI u where o.URI_ID = u.URI_ID and u.URI_STRING = ?");
        statement.setString(1, uri.toString());
        statement.executeUpdate();
      } 
      finally {
        close(statement);
      }
      // finally delete the uri
      try {
        statement = connection.prepareStatement("delete from URI where URI_STRING = ?");
        statement.setString(1, uri.toString());
        statement.executeUpdate();
      } 
      finally {
        close(statement);
      }
    } 
    catch (SQLException e) {
      throw createException(e, uri.toString());
    }
  }
  
  /* (non-Javadoc)
   * @see org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeRevisionContent(
   *  java.sql.Connection, org.apache.slide.common.Uri, 
   *  org.apache.slide.content.NodeRevisionDescriptor)
   */
  public void removeRevisionContent(Connection connection, Uri uri,
      NodeRevisionDescriptor revisionDescriptor) throws ServiceAccessException {
    try {
      PreparedStatement statement = null;
      try {
        statement =
          connection.prepareStatement(
          "delete vc from VERSION_CONTENT vc, VERSION_HISTORY vh, URI u where vc.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID=u.URI_ID AND u.URI_STRING=?");
        statement.setString(1, revisionDescriptor.getRevisionNumber().toString());
        statement.setString(2, uri.toString());
        statement.executeUpdate();
      }
      finally {
        close(statement);
      }
    }
    catch (SQLException e) {
      throw createException(e, uri.toString());
    }
  }
  
  /* (non-Javadoc)
   * @see org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeRevisionDescriptor(
   *  java.sql.Connection, org.apache.slide.common.Uri, 
   *  org.apache.slide.content.NodeRevisionNumber)
   */
  public void removeRevisionDescriptor(Connection connection, Uri uri,
      NodeRevisionNumber revisionNumber) throws ServiceAccessException {
    PreparedStatement statement = null;
    try {
      try {
        statement =
          connection.prepareStatement(
          "delete vl from VERSION_LABELS vl, VERSION_HISTORY vh, URI u where vl.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID = u.URI_ID AND u.URI_STRING = ?");
        statement.setString(1, revisionNumber.toString());
        statement.setString(2, uri.toString());
        statement.executeUpdate();
      } 
      finally {
        close(statement);
      }
      try {
        statement =
          connection.prepareStatement(
          "delete p from PROPERTIES p, VERSION_HISTORY vh, URI u where p.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID = u.URI_ID AND u.URI_STRING = ?");
        statement.setString(1, revisionNumber.toString());
        statement.setString(2, uri.toString());
        statement.executeUpdate();
      } 
      finally {
        close(statement);
      }
    } 
    catch (SQLException e) {
      throw createException(e, uri.toString());
    }
  }
  
  /* (non-Javadoc)
   * @see org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeRevisionDescriptors(
   *  java.sql.Connection, org.apache.slide.common.Uri)
   */
  public void removeRevisionDescriptors(Connection connection, Uri uri)
      throws ServiceAccessException {
    PreparedStatement statement = null;
    try {
      statement =
        connection.prepareStatement(
        "delete vp from VERSION_PREDS vp, VERSION_HISTORY vh, URI u where vp.VERSION_ID = vh.VERSION_ID and vh.URI_ID = u.URI_ID and u.URI_STRING = ?");
      statement.setString(1, uri.toString());
      statement.executeUpdate();
    } catch (SQLException e) {
      throw createException(e, uri.toString());
    } finally {
      close(statement);
    }
  }
  
  /* (non-Javadoc)
   * @see org.apache.slide.store.impl.rdbms.StandardRDBMSAdapter#clearBinding(java.sql.Connection, org.apache.slide.common.Uri)
   */
  protected void clearBinding(Connection connection, Uri uri)
      throws ServiceAccessException, ObjectNotFoundException, SQLException {
    PreparedStatement statement = null;
    
    // clear this uri from having bindings and being bound 
    try {
      statement =
        connection.prepareStatement(
        "delete c from BINDING c, URI u where c.URI_ID = u.URI_ID and u.URI_STRING = ?");
      statement.setString(1, uri.toString());
      statement.executeUpdate();
    } 
    finally {
      close(statement);
    }
    
    try {
      statement =
        connection.prepareStatement(
        "delete c from PARENT_BINDING c, URI u where c.URI_ID = u.URI_ID and u.URI_STRING = ?");
      statement.setString(1, uri.toString());
      statement.executeUpdate();
    } 
    finally {
      close(statement);
    }
  }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to