[Opensource] Expresso DBObjects - Serious error in caching or something else?

Gabor Nagypal nagypal at web.de
Thu Aug 14 07:59:17 PDT 2003


Hi Mike,

I tried the things with the 5.3rc1 version and the error is still there. 
I tried with both with the default Hypersonic and PostgreSQL DBs. So it 
seems that your unit tests are not the same. :)

Unfortunately I will be unavailable in the next few weeks so to help you 
track down the problem I attach an example DBObject I use for testing, 
and include my null unit test into this mail. Please try to test the 
things with exactly this configuration. If it works for you I have no 
idea why doesn't it work for me. :(

Regards,

Gabor

----

public void testNullValues() {
     String resourceId = null;
     try {
       log.info("Test null values");
       ResourceDBO resource = new ResourceDBO();
       resource.setDataContext(TestSystemInitializer.getTestContext());
       resource.setField(ResourceDBO.FLD_ID, getNewId());
       resource.setField(ResourceDBO.FLD_REPOSITORY, "FZI");
       resource.setField(
         ResourceDBO.FLD_REG_TS,
         DateTime.getDateTimeForDB(resource.getDBName()));
       resource.add();
       resourceId = resource.getField(ResourceDBO.FLD_ID);
       resource = new ResourceDBO();
       resource.setField(ResourceDBO.FLD_ID, resourceId);
       resource.retrieve();
       assertTrue(resource.isFieldNull(ResourceDBO.FLD_ABSTRACT));
       assertTrue(resource.isFieldNull(ResourceDBO.FLD_ANNUP_TS));
       resource.retrieve();
       assertTrue(resource.isFieldNull(ResourceDBO.FLD_ABSTRACT));
       assertTrue(resource.isFieldNull(ResourceDBO.FLD_ANNUP_TS));
       resource.addOrUpdate();
       resource = new ResourceDBO();
       resource.setField(ResourceDBO.FLD_ID, resourceId);
       resource.retrieve();
       assertTrue(resource.isFieldNull(ResourceDBO.FLD_ABSTRACT));
       assertTrue(resource.isFieldNull(ResourceDBO.FLD_ANNUP_TS));
       resource.setField(ResourceDBO.FLD_ABSTRACT, "Hi!");
       resource.addOrUpdate();
       resource.retrieve();
       assertFalse(resource.isFieldNull(ResourceDBO.FLD_ABSTRACT));
       assertTrue(resource.isFieldNull(ResourceDBO.FLD_ANNUP_TS));
       resource.setField(ResourceDBO.FLD_ABSTRACT, null);
       resource.addOrUpdate();
       resource.retrieve();
       assertTrue(resource.isFieldNull(ResourceDBO.FLD_ABSTRACT));
       assertTrue(resource.isFieldNull(ResourceDBO.FLD_ANNUP_TS));
       resource.delete();
     } catch (Exception e) {
       log.error(e);
       Assert.fail("Exception occured:" + e.getMessage());
     }
   }


Michael Rimov wrote:

> At 05:46 PM 8/11/2003 +0200, you wrote:
> 
>> Hi!
>>
>> I use Expresso 5.0.5 and I have the following problem:
>>
>> I have a DBObject, let's say MyDbo, which has an attribute "id" as DB 
>> key, and "dummy", which can be null.
>> I have a raw in the DB where the attribute "dummy" is null. Let's say 
>> the is for this raw is '1'. Now:
> 
> 
> Gabor,
> 
> Can you please try the RC-1 that has just been announced?  AFAICT the 
> unit tests do the same thing you describe and they pass.  If you're 
> still having problems, PLEASE let me know ASAP so we can figure out what 
> is going on different between your code and ours.
> 
> Thanks!
>                                                         -Mike
> 
> 
> 
> _______________________________________________
> Opensource mailing list
> Opensource at jcorporate.com
> http://mail.jcorporate.com/mailman/listinfo/opensource
> Archives: http://mail.jcorporate.com/pipermail/opensource/
> 
-------------- next part --------------
package org.vicodi.expresso.dbobj;

import java.util.Vector;

import org.apache.log4j.Logger;

import com.jcorporate.expresso.core.controller.ControllerRequest;
import com.jcorporate.expresso.core.db.*;
import com.jcorporate.expresso.core.dbobj.*;

/**
 * <p><code>CountryCity</code> </p>
 *
 * <p>This is an Expresso database object that maintains static country
 * city mapping.</p>
 * <br>  <br>
 *
 * @author Peter A.J. Pilgrim, Monday December 11 11:17:20 GMT 2000
 * @version $Id: ResourceDBO.java,v 1.4 2003/08/08 07:35:30 gabor.nagypal Exp $
 */
public class ResourceDBO extends SecuredDBObject {

	public static final String FLD_PUB_STATUS = "publishStatus";
	public static final String FLD_REPOSITORY = "repositoryId";
	public static final String FLD_HIST_CLASS = "histClassCode";
	public static final String FLD_SUBMITTER = "submitter";
	public static final String FLD_AUTHOR = "authorURI";
	public static final String FLD_ABSTRACT = "abstract";
	public static final String FLD_TITLE = "title";
	public static final String FLD_ID = "id";
	public static final String FLD_REG_TS = "registrationTs";
	public static final String FLD_ANNUP_TS = "annUpTs";
	public static final String FLD_ANNCREATE_TS = "annCreateTs";
	public static final String FLD_ACTIVATED = "isActivated";
	public static final String FLD_RIGHTS_OK = "rightsOK";
	public static final String FLD_TRANSFORM_TS = "transformationTs";
	public static final String FLD_CONTEXTCREATE_TS = "contextCreateTs";

	private static Logger log = Logger.getLogger(ResourceDBO.class);

	/**
	 * Constructor
	 * Create a new object of this type with no connection
	 * yet allocated.
	 * @throws DBException upon construction error
	 */
	public ResourceDBO() throws DBException {
		super();
	}
	/**
	 * Constructor
	 *
	 * @param    theConnection Database connection to
	 * communicate with the database
	 * @throws    DBException If the new object cannot be
	 * created
	 */
	public ResourceDBO(DBConnection theConnection) throws DBException {
		super(theConnection);
	}

	/**
	 * Use over (String) constructor.  Initializes the object in the context
	 * of the user who's uid belongs to the parameter.
	 * @param uid the Uid of the user context
	 * @throws DBException if there's an initialization problem
	 */
	public ResourceDBO(int uid) throws DBException {
		super(uid);
	}
	/**
	 * For using DBObjects within Controllers.  Initializes based upon the current
	 * user and the requested db. [Of course this can be modified later]
	 *
	 * @param request - The controller request handed to you by the framework.
	 * @throws DBException if there's an initialization problem
	 */
	public ResourceDBO(ControllerRequest request) throws DBException {
		super(request);
	}

	/**
	 * Define the fields for this object
	 *
	 * <p>This allows expresso to perform <tt>"CREATE TABLE ( ... )"</tt>
	 * and <tt>"SELECT * FROM ..."</tt>
	 * <sup>*PP*</sup>
	 * </p>
	 *
	 * @throws    DBException if the database table cannot be created or
	 * cannot be accessed. Means the web application cannot be initialised
	 * because of serious DB failure.
	 */
	protected synchronized void setupFields() throws DBException {
		setTargetTable("Resource");
		setDescription("Resource metadata");
		addField(FLD_ID, DBField.VARCHAR_TYPE, 255, false, "Resource ID");
		addField(FLD_TITLE, DBField.VARCHAR_TYPE, 255, true, "Title");
		addField(FLD_ABSTRACT, DBField.VARCHAR_TYPE, 255, true, "Abstract");
		addField(
			FLD_SUBMITTER,
			DBField.VARCHAR_TYPE,
			255,
			true,
			"Submitter e-mail");
		addField(FLD_AUTHOR, DBField.VARCHAR_TYPE, 255, true, "Author OI URI");
		addField(
			FLD_REPOSITORY,
			DBField.VARCHAR_TYPE,
			10,
			true,
			"Repository ID");
		setMultiValued(FLD_REPOSITORY);
		setLookupObject(FLD_REPOSITORY, RepositoryDBO.class.getName());
		addField(
			FLD_HIST_CLASS,
			DBField.VARCHAR_TYPE,
			50,
			true,
			"Historical classification");
		setMultiValued(FLD_HIST_CLASS);
		setLookupObject(
			FLD_HIST_CLASS,
			HistoricalClassificationDBO.class.getName());
		addField(
			FLD_PUB_STATUS,
			DBField.INTEGER_TYPE,
			0,
			true,
			"Publication status");
		addField(FLD_ACTIVATED, DBField.BOOLEAN_TYPE, 0, true, "Is activated?");
		addField(
			FLD_RIGHTS_OK,
			DBField.BOOLEAN_TYPE,
			0,
			true,
			"Rights are cleared?");
		addField(
			FLD_REG_TS,
			DBField.DATETIME_TYPE,
			0,
			false,
			"Registration time stamp");
		addField(
			FLD_ANNUP_TS,
			DBField.DATETIME_TYPE,
			0,
			true,
			"Annotations updated time stamp");
		addField(
			FLD_ANNCREATE_TS,
			DBField.DATETIME_TYPE,
			0,
			true,
			"Annotations first created time stamp");
		addField(
			FLD_TRANSFORM_TS,
			DBField.DATETIME_TYPE,
			0,
			true,
			"Content Transformation time stamp");
		addField(
			FLD_CONTEXTCREATE_TS,
			DBField.DATETIME_TYPE,
			0,
			true,
			"Context created time stamp");
		addKey(FLD_ID);
		//		addDetail(
		//			ResourcePartDBO.class.getName(),
		//			FLD_ID,
		//			ResourcePartDBO.FLD_PARENT);
		//				addDetail(AnnotationDBO.class.getName(), FLD_ID, "resourceId");
		//		addDetail(ContextDBO.class.getName(), FLD_ID, ContextDBO.FLD_RESOURCE);
		//		addDetail(
		//			LinkResourceMatCatDBO.class.getName(),
		//			FLD_ID,
		//			LinkResourceMatCatDBO.FLD_RESOURCE);
		//		addDetail(
		//			LinkResourceResRoleDBO.class.getName(),
		//			FLD_ID,
		//			LinkResourceResRoleDBO.FLD_RESOURCE);
	}

	public Vector getValidValues(String fieldName) throws DBException {
		return super.getValidValues(fieldName);
	}

	//	protected void checkAllReferredToBy() throws DBException {
	//		log.debug("checkAllReferredToBy is executed...");
	//		referredToBy(
	//			new ResourcePartDBO(),
	//			ResourcePartDBO.FLD_PARENT,
	//			"This resource is referred by a resource part.");
	//		referredToBy(
	//			new AnnotationDBO(),
	//			AnnotationDBO.FLD_RESOURCE,
	//			"This resource is referred by an annotation.");
	//		referredToBy(
	//			new ContextDBO(),
	//			ContextDBO.FLD_RESOURCE,
	//			"This resource is referred by a context element.");
	//		referredToBy(
	//			new LinkResourceResRoleDBO(),
	//			LinkResourceResRoleDBO.FLD_RESOURCE,
	//			"This resource has a many-to-many connection with a resource role.");
	//		referredToBy(
	//			new LinkResourceMatCatDBO(),
	//			LinkResourceMatCatDBO.FLD_RESOURCE,
	//			"This resource has a many-to-many connection with a material category.");
	//	}

	//	public synchronized void delete() throws DBException {
	//		/*HACK: First delete all annotations, which will
	//		 * delete all of the annotation references
	//		 */
	//		AnnotationDBO annotation = new AnnotationDBO(this.localConnection);
	//		annotation.setField(AnnotationDBO.FLD_RESOURCE, this.getField(FLD_ID));
	//		List annotations = annotation.searchAndRetrieveList();
	//		for (Iterator i = annotations.iterator(); i.hasNext();) {
	//			AnnotationDBO a = (AnnotationDBO) i.next();
	//			a.delete();
	//		}
	//		super.delete();
	//	}

}


More information about the Opensource mailing list