• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Automatic data generation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automatic data generation


  • Subject: Re: Automatic data generation
  • From: Kieran Kelleher <email@hidden>
  • Date: Thu, 21 Aug 2008 11:15:46 -0400

Well, you can roll your own pretty easily.

Just make a ValueGenerator class that makes values, taking advantage of the ERXLoremIpsumGenerator, have a myapp.setDevelopmentDefaults=true/false entry in Properties. Then in your base EOF class, have awakeFromInsertion call a custom setDevelopmentDefaults method that *only generates* fill-in values (unique, random or otherwise) where the values are null so you don't override real awakeFromInsertion defaults.

In setDevelopment defaults, you can then finally call a catch-all method to do the trivial attribute fillins and do sth like this:

<snip>
public class MyGenericRecord extends ERXGenericRecord {
private static final Logger log = Logger.getLogger(MyGenericRecord.class);





@Override public void awakeFromInsertion(EOEditingContext editingContext) { super.awakeFromInsertion(editingContext); setDefaultValues(); if (shouldSetDevelopmentDefaults()) { setDevelopmentDefaults(); } //~ if (shouldSetDevelopmentDefaults()) }

/**
* Can be overridden to set default values. Will get called by awakeFromInsertion.
* The Velocity EOGen template (_Enity.java) overrides this method and sets
* default values stored in the attribute userInfo in the model under the key
* 'defaultValue'.
*/
public void setDefaultValues() {
//intentionally blank
}

/**
* Don't cache this since we may want to change the system property while doing development.
* It is already cached in system properties.
* @return true if setDevelopmentDefaults should be called when new entities are created.
*/
public boolean shouldSetDevelopmentDefaults(){
return ERXProperties .booleanForKeyWithDefault("myGreatApp.setDevelopmentDefaults", false);
}


/**
* Hook method that can be optionally overridden for classes.
* Default is to put lorem ipsum filler garbage. However, you can override this method and fully
* control the defaults or call super and then customize the defaults on the attributes you want.
*/
public void setDevelopmentDefaults(){
String TYPE_STRING = "java.lang.String";
String TYPE_DATETIME = "com.webobjects.foundation.NSTimestamp";
String TYPE_DATA = "com.webobjects.foundation.NSData";
String TYPE_NUMBER = "java.lang.Number";


		// Grab the entity for this EO
		EOEntity entity = ERXEOAccessUtilities.entityForEo(this);

		// Get the visible attributes
		NSArray attributes = ModelUtilities.publicAttributesForEntity(entity);

for (java.util.Enumeration attributesEnumerator = attributes.objectEnumerator(); attributesEnumerator
.hasMoreElements();) {
EOAttribute attribute = (EOAttribute) attributesEnumerator.nextElement();


			// The key
			String key = attribute.name();

			// Current value
			Object currentValue = valueForKey(attribute.name());

if (log.isDebugEnabled())
log.debug(attribute.name() + " has initial value of " + (currentValue == null ? "null" : currentValue.toString()));


			// We only want to update attributes in certain situations
			String className = attribute.className();
			String valueType = attribute.valueType();


// Check if we should set a default value
// We don't want to stomp over any values set already
if (currentValue == null
&& !attribute.isDerived()
&& !attribute.isReadOnly() ) {
if (log.isDebugEnabled())
log.debug("Processing attribute: " + attribute);
if (TYPE_STRING.equals(className)) {
// String type
String value = ERXLoremIpsumGenerator.words(1, attribute.width(), attribute.width());
takeValueForKey(value, key);
} else if (TYPE_DATETIME.equals(className)) {
// NSTimestamp - set the current time
takeValueForKey(new NSTimestamp(), key);
} else if (TYPE_DATA.equals(className)){
// NSData type
String value = ERXLoremIpsumGenerator.words(10, 100, attribute.width());
takeValueForKey(new NSData(value.getBytes()), key);
} else if (TYPE_NUMBER.equals(className)){
// Number type
// Which type of number?
if ("i".equals(valueType)) {
// Integer
takeValueForKey(ValueGenerator.sharedInstance().integerValue(), key);
} else if ("d".equals(valueType)){
takeValueForKey(ValueGenerator.sharedInstance().doubleValue(), key);
} else if ("B".equals(valueType)){
takeStoredValueForKey (ValueGenerator.sharedInstance().bigDecimalValue(), key);
} else if ("c".equals(valueType)) {
takeValueForKey(Boolean.FALSE, key);
} //~ if ("i".equals(valueType))
} //~ if ....



} //~ if (currentValue == null)

		} //~ for (java.util.Enumeration attributesEnumerator = ...

	}

}
</snip>



On Aug 21, 2008, at 10:56 AM, Florijan Stamenkovic wrote:

Not sure if this has been discussed already, but I could not find anything in the list archives, nor by quickly googling.

So, I'm thinking of making a framework for automated data generation, based on a model and some runtime settings. This would, obviously, be used for testing. Specifically: filling up a database with arbitrary numbers of nonsense rows, that are however legal, and proceeding from there.

Has anyone made this already? Skimmed through the wonder API, but did not see anything that struck a chord...

If nobody ever made it, then why not? It seems a very nice thing to have, and off the top of my head I can not think of any insurmountable obstacle to making it...

F
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Automatic data generation
      • From: Florijan Stamenkovic <email@hidden>
    • Re: Automatic data generation
      • From: Kieran Kelleher <email@hidden>
References: 
 >Automatic data generation (From: Florijan Stamenkovic <email@hidden>)

  • Prev by Date: Re: Automatic data generation
  • Next by Date: Re: Automatic data generation
  • Previous by thread: Re: Automatic data generation
  • Next by thread: Re: Automatic data generation
  • Index(es):
    • Date
    • Thread