Hi, i try to use Peers but i have some pb with it.

I get a java.lang.StringIndexOutOfBoundsException: String index out of
range: -1 Exception when call the getAll method of my Test class.
I call this method from a jsp.

Maybe i have not understand at all the way to use peers so if you can give
me some help it will be great.

here is my code

Thanks for your help

----------------------------------------------------------------------------
---
MapBuilder
----------------------------------------------------------------------------
---

package ojh.test.db.map;

import java.util.*;
import org.apache.turbine.util.db.pool.*;
import org.apache.turbine.util.db.map.*;

public class OJHMapBuilder implements MapBuilder
{
    /**
        TEST table
    */
    public String getTableTEST()
    {
        return "TEST";
    }

    public String getTESTID()
    {
        return "ID";
    }

    public String getTESTNAME()
    {
        return "NAME";
    }

    /**
        the database map
    */
    private DatabaseMap dbMap = null;

    /**
        tells us if this DatabaseMapBuilder is built so that we don't have
        to re-build it every time
    */
    public boolean isBuilt()
    {
        if ( dbMap != null )
            return true;
        return false;
    }

    /**
        gets the databasemap this map builder built.
    */
    public DatabaseMap getDatabaseMap()
    {
        return this.dbMap;
    }

    /**
        this builds up the databasemapping. It should probably be
        modified to read a .xml file
        representation of the database to build this.
    */
    public void doBuild()
        throws Exception
    {
        // make some objects
        String string = new String("");
        Integer integer = new Integer(0);
        java.util.Date date = new Date();

        // get default map
        dbMap = new DatabaseMap("OJHMap");

        // add tables
        dbMap.addTable(getTableTEST());

        // add Role columns
        TableMap tMap = dbMap.getTable(getTableTEST());
        tMap.addPrimaryKey(getTESTID(), integer);
        tMap.addColumn(getTESTNAME(), string);
    }
}


----------------------------------------------------------------------------
---
ObjectPeer
----------------------------------------------------------------------------
---
package ojh.test;

import ojh.test.db.map.*;

// Turbine Utility Classes
import org.apache.turbine.om.peer.*;
import org.apache.turbine.om.security.*;
import org.apache.turbine.util.*;
import org.apache.turbine.util.db.*;
import org.apache.turbine.util.db.map.*;
import org.apache.turbine.services.resources.TurbineResources;

// Village Database Classes
import com.workingdogs.village.*;

import java.util.*;
import java.sql.*;
/**
 * @author Nicolas PERIDONT - BeLab
 */

public class TestPeer extends BasePeer
{
    private static final OJHMapBuilder mapBuilder = (OJHMapBuilder)
getMapBuilder("ojh.test.db.map.OJHMapBuilder");

    /** The table name for this peer. */
    private static final String TABLE_NAME = mapBuilder.getTableTEST();

  /** The column name for the id field. */
  public static final String ID = mapBuilder.getTESTID();
  /** The column name for the name field. */
  public static final String NAME = mapBuilder.getTESTNAME();

    /**
        Insert new roles.
    */
    public static int doInsert(Criteria criteria) throws Exception
    {
        BasePeer.doInsert(criteria);
        return 0;
    }

    /**
     * @param Criteria object containing data that is used to create the
SELECT statement.
     * @return Vector containing Show objects.
     */
    public static Vector doSelect(Criteria criteria) throws Exception
    {
        criteria.setMapName("OJHMap");


        criteria.addSelectColumn(ID)
                .addSelectColumn(NAME);

        Vector rows = BasePeer.doSelect(criteria);

        return null;
    }

    /**
        Get the name of this table
    */
    public static String getTableName()
    {
        return TABLE_NAME;
    }

    /**
        returns the TABLE_NAME + "." + name
    */
    public static String getColumnName (String name)
    {
        StringBuffer sb = new StringBuffer();
        sb.append (TABLE_NAME);
        sb.append (".");
        sb.append (name);
        return sb.toString();
    }

    /**
        returns a vector of Role objects
    */
    public static Vector selectAll()
        throws Exception
    {
        Criteria criteria = new Criteria();
        criteria.addOrderByColumn(TestPeer.NAME);
        return TestPeer.doSelect(criteria);
    }
}

----------------------------------------------------------------------------
---
Object
----------------------------------------------------------------------------
---

package ojh.test;

import java.util.*;

import ojh.test.db.map.*;

// Turbine Utility Classes
import org.apache.turbine.util.*;
import org.apache.turbine.util.db.*;
import org.apache.turbine.util.db.map.*;
import org.apache.turbine.util.db.pool.*;
import org.apache.turbine.om.*;
import org.apache.turbine.om.peer.*;
import org.apache.turbine.om.user.*;
import org.apache.turbine.om.user.peer.*;
import org.apache.turbine.om.security.peer.*;

import org.apache.turbine.services.resources.*;

 /**
 * @author Nicolas PERIDONT - BeLab
  */

public class Test extends BaseObject
{

 private String mName;
 public void setName(String pName){this.mName = pName;}
 public String getName(){return mName;}

 private int mId_test;
 public void setId_test(int pId_test){this.mId_test = pId_test;}
 public int getId_test(){return mId_test;}

 file://public Test[] getAll(){
 public String getAll(){

  try{
   file://Init TurbineResourceService

TurbineResourceService.setPropertiesFileName("C:/tomcat/webapps/turbine/conf
/TurbineResources.properties");
  }catch(Exception e){}

  Test[] AllTest = null;

  try{
   TestPeer aTestPeer = new TestPeer();
   Vector all = aTestPeer.selectAll();

  }catch (Exception e){return "Exception : " + e;}

  file://return AllTest;
  return "ok";


 }

 /**
 * Used to order Roles in a RoleSet
 */
 public int compareTo(Object o)
 {
   String name1 = ((Test)o).getName();
   String name2 = this.getName();

   return name2.compareTo(name1);
 }



}


-------------------------------------------------------------------
Nicolas Peridont - [EMAIL PROTECTED]
Business Lab, The Netchandising Company
http://www.be-lab.com
26 rue des amandiers - 92000 Nanterre
T�l. : (33) 1 41 20 07 08
Fax : (33) 1 41 20 08 07




------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to