SlideShare a Scribd company logo
1 of 66
Download to read offline
Migrating existing Projects to
Wonder
Maik Musall, Selbstdenker AG
Samstag, 22. Juni 13
ā€¢ Existing application of some complexity
ā€¢ Using perhaps custom frameworks, but not yet Wonder
ā€¢ Want to use Wonder for several reasons, but uncertain where to
start and how to manage the migration process
The Task
Samstag, 22. Juni 13
Goals
ā€¢ Make the switch at a chosen, planned point in time
ā€¢ Being able to switch back to the non-Wonder version if
problems come up in production
ā€¢ Identify which steps to do when, and how
Samstag, 22. Juni 13
The Big Steps
ā€¢ Move to Git (if you havenā€˜t already)
ā€¢ Prepare the code base ahead of the actual wonderization
ā€¢ Create a wonderization branch
ā€¢ Wonderize in that branch, periodically merge new stuff from
your main branch
ā€¢ Release and celebrate
Samstag, 22. Juni 13
Prep step: Move to Git
ā€¢ Youā€˜ll need branches during the migration
ā€¢ Wonder is Git-based anyway
ā€¢ It just makes everything easier
ā€¢ Plan some time to get up to speed using Git ļ¬rst
ā€¢ Use Sourcetree
Samstag, 22. Juni 13
Prep step: Move to Git
Time
release branches
masterdevelop hotfixes
feature
branches
Feature
for future
release
Tag
1.0
Major
feature for
next release
From this point on,
ā€œnext releaseā€
means the release
after 1.0
Severe bug
fixed for
production:
hotfix 0.2
Bugfixes from
rel. branch
may be
continuously
merged back
into develop
Tag
0.1
Tag
0.2
Incorporate
bugfix in
develop
Only
bugfixes!
Start of
release
branch for
1.0
Author: Vincent Driessen
Samstag, 22. Juni 13
Prep step: Move to Git
Time
release branches
masterdevelop hotfixes
feature
branches
Feature
for future
release
Major
feature for
next release
Severe bug
fixed for
production:
hotfix 0.2
Tag
0.1
Tag
0.2
Incorporate
bugfix in
develop
Start ofSamstag, 22. Juni 13
Prep step: Move to Git
release
Tag
1.0
From this point on,
ā€œnext releaseā€
means the release
after 1.0
Bugfixes from
rel. branch
may be
Tag
0.2
Incorporate
bugfix in
develop
Only
bugfixes!
Start of
release
branch for
1.0
Samstag, 22. Juni 13
Prep step: Move to Git
Tag
1.0
From this point on,
ā€œnext releaseā€
means the release
after 1.0
Bugfixes from
rel. branch
may be
continuously
merged back
into develop
Only
bugfixes!
Start of
release
branch for
1.0
Samstag, 22. Juni 13
Managing Wonderization in Git
ļ¬rst wonderized release
second wonderized release
conventional version as fallback
conventional version as fallback
wonderized version merged into main
1.0
1.0
develop wonderize
1.1
feature
1.2
1.2
1.3
1.3
2.0
1.2
Samstag, 22. Juni 13
Prep step: Java packages
ā€¢ You canā€˜t inherit from packaged classes if your classes arenā€˜t in
packages, too
ā€¢ So if you havenā€˜t already, create packages and move all your
sources into them
ā€¢ Beneļ¬t: clariļ¬ed namespaces for your stuff
Samstag, 22. Juni 13
Java packages gotchas
ā€¢ Getters and setters in components need to be(come) public
ā€¢ Check class.getName() calls to become class.getSimpleName()
ā€¢ Class.forName() needs full packaged path
ā€¢ Overridden methods in enums become unreachable code in WO
bindings
Samstag, 22. Juni 13
public enum ContentType {
! literature {
! ! @Override public String cssClassName() { return "read"; }
! },
! film {
! ! @Override public String cssClassName() { return "watch"; }
! },
! music {
! ! @Override public String cssClassName() { return "listen"; }
! };
!
! public abstract String cssClassName();
! public boolean isAvailable() { return true; }
}
Packages: overriding enum methods
Samstag, 22. Juni 13
Packages: overriding enum methods
public enum ContentType {
! literature {
! ! @Override public String cssClassName() { return "read"; }
! },
! film {
! ! @Override public String cssClassName() { return "watch"; }
! },
! music {
! ! @Override public String cssClassName() { return "listen"; }
! },
! pr0n {
! ! @Override public String cssClassName() {
! ! ! return getUser().isAdult() ? "watch" : "nothingForYou";
! ! }
! };
!
! public abstract String cssClassName();
}
Samstag, 22. Juni 13
Packages: overriding enum methods
public enum ContentType {
! literature {
! ! @Override String cssClassNameImpl() { return "read"; }
! },
! film {
! ! @Override String cssClassNameImpl() { return "watch"; }
! },
! music {
! ! @Override String cssClassNameImpl() { return "listen"; }
! },
! pr0n {
! ! @Override String cssClassNameImpl() {
! ! ! return getUser().isAdult() ? "watch" : "nothingForYou";
! ! }
! };
!
! abstract String cssClassNameImpl();
! public String cssClassName() { return cssClassNameImpl(); }
}
Samstag, 22. Juni 13
Packages: overriding enum methods
public enum ContentType implements NSKeyValueCoding {
! literature {
! ! @Override public String cssClassName() { return "read"; }
! },
! film {
! ! @Override public String cssClassName() { return "watch"; }
! },
! music {
! ! @Override public String cssClassName() { return "listen"; }
! },
! pr0n {
! ! @Override public String cssClassName() {
! ! ! return getUser().isAdult() ? "watch" : "nothingForYou";
! ! }
! };
! !
! public abstract String cssClassName();
! @Override public void takeValueForKey( Object obj, String s ) { return; }
! @Override public Object valueForKey( String s ) {
! ! try {
! ! ! return this.getClass().getMethod( s, (Class<?>[]) null ).invoke( this, (Object[]) null );
! ! } catch( Exception e ) {
! ! ! throw new RuntimeException( e );
! ! }
! }
}
Samstag, 22. Juni 13
Prep step: own EC class
ā€¢ You gain a lot of ļ¬‚exibility by using your own EOEditingContext
subclass
ā€¢ example: logging on saveChanges() or invalidateAllObjects()
ā€¢ example: undoManager().removeAllActions() after saves
ā€¢ Changing the superclass later to ERXEC becomes easy
Samstag, 22. Juni 13
Prep step: own DA class
ā€¢ Create a common superclass between concrete DirectAction
classes and WODirectAction
ā€¢ Changing the superclass later to ERXDirectAction becomes easy
Samstag, 22. Juni 13
Prep step: own logging class
ā€¢ Create your own org.apache.log4j.Logger subclass
ā€¢ Changing the superclass later to ERXLogger becomes easy
Samstag, 22. Juni 13
import org.apache.log4j.Logger;
public class MyLogger extends Logger {
! public MyLogger( String name ) {
! ! super( name );
! }
! public static Factory factory = null;
! static {
! ! String factoryClassName = MyLogger.Factory.class.getName();
! ! try {
! ! ! MyLogger.factory = (Factory) Class.forName( factoryClassName ).newInstance();
! ! } catch( Exception ex ) {
! ! ! System.err.println( "Exception while creating logger factory of class " + factoryClassName + ": " + ex );
! ! }
! }
! public static class Factory implements org.apache.log4j.spi.LoggerFactory {
! ! @Override
! ! public Logger makeNewLoggerInstance( String name ) {
! ! ! return new MyLogger( name );
! ! }
! ! public void loggingConfigurationDidChange() {
! ! }
! }
Your own logging class (1/2)
Samstag, 22. Juni 13
! public static MyLogger getMyLogger( String name ) {
! ! Logger logger = MyLogger.getLogger( name );
! ! if( logger != null && ! (logger instanceof MyLogger) ) {
! ! ! throw new RuntimeException(
! ! ! ! "Can't load Logger for ""
! ! ! ! + name
! ! ! ! + "" because it is not of class MyLogger but ""
! ! ! ! + logger.getClass().getName()
! ! ! ! + "". Check if there is a "log4j.loggerFactory=er.extensions.Logger$Factory" line in your properties."
! ! ! );
! ! }
! ! return (MyLogger) logger;
! }
! public static Logger getLogger( String name ) {
! ! return Logger.getLogger( name, MyLogger.factory );
! }
! public static MyLogger getMyLogger( Class clazz ) {
! ! return MyLogger.getMyLogger( clazz.getName() );
! }
! public static Logger getLogger( Class clazz ) {
! ! return MyLogger.getMyLogger( clazz );
! }
}
Your own logging class (2/2)
Samstag, 22. Juni 13
Prep step: rename enums
ā€¢ ERXKey constants in new templates could collide with enum
names
ā€¢ Common collision pattern: uppercase enum with same name as
EO attribute
ā€¢ Eclipse refactoring tools are your friend
ā€¢ Make this a separate commit
Samstag, 22. Juni 13
public class MyFlightRoute extends _MyFlightRoute {
! public static enum STATUS {
! ! obsolete,
! ! current,
! ! preliminary,
! ! deleted;
! }
! public void setStatus( STATUS status ) {
! ! super.setStatus( status.name() );
! }
}
enum renames
Samstag, 22. Juni 13
public class MyFlightRoute extends _MyFlightRoute {
! public static enum STATUS {
! ! obsolete,
! ! current,
! ! preliminary,
! ! deleted;
! }
! public void setStatus( STATUS status ) {
! ! super.setStatus( status.name() );
! }
}
public abstract class _MyFlightRoute extends MyEOGenericRecord {
! public static final ERXKey<String> STATUS = new ERXKey<String>("status");
! public static final String STATUS_KEY = STATUS.key();
}
enum renames
Samstag, 22. Juni 13
public class MyFlightRoute extends _MyFlightRoute {
! public static enum STATUS {
! ! obsolete,
! ! current,
! ! preliminary,
! ! deleted;
! }
! public void setStatus( STATUS status ) {
! ! super.setStatus( status.name() );
! }
}
public abstract class _MyFlightRoute extends MyEOGenericRecord {
! public static final ERXKey<String> STATUS = new ERXKey<String>("status");
! public static final String STATUS_KEY = STATUS.key();
}
enum renames
Samstag, 22. Juni 13
public class MyFlightRoute extends _MyFlightRoute {
! public static enum FRSTATUS {
! ! obsolete,
! ! current,
! ! preliminary,
! ! deleted;
! }
! public void setStatus( FRSTATUS status ) {
! ! super.setStatus( status.name() );
! }
}
public abstract class _MyFlightRoute extends MyEOGenericRecord {
! public static final ERXKey<String> STATUS = new ERXKey<String>("status");
! public static final String STATUS_KEY = STATUS.key();
}
enum renames
Samstag, 22. Juni 13
Prep step: instance settings
ā€¢-XX:MaxPermSize=256m
Samstag, 22. Juni 13
Wonderization: Frameworks
ā€¢ Now is the time to start the actual wonderization
ā€¢ Start by the usual way to import Wonder into Eclipse
ā€¢ Then add ERJars, ERExtensions,WOOgnl and Wonderā€˜s
JavaWOExtensions to your project
ā€¢ And ERPrototypes if you want to use them
ā€¢ Remove log4j and potentially other jars that are contained in
ERJars (check version compatibilities)
Samstag, 22. Juni 13
Properties ļ¬le
ā€¢ Wonder manages nearly all settings through Properties
ā€¢ Live in ļ¬le Resources/Properties
ā€¢ You have to create at least a minimal ļ¬le to start with
Samstag, 22. Juni 13
Properties ļ¬le
# OGNL
ognl.active = true
ognl.helperFunctions = true
ognl.inlineBindings = true
ognl.parseStandardTags = false
# Misc
er.extensions.stackTrace.cleanup = true
file.encoding = UTF-8
# EOF
er.extensions.ERXEC.safeLocking = true
er.extensions.ERXEC.useSharedEditingContext = false
er.extensions.ERXEnterpriseObject.applyRestrictingQualifierOnInsert = true
er.extensions.ERXRaiseOnMissingEditingContextDelegate = false
# Migrations
er.migration.migrateAtStartup = true
er.migration.createTablesIfNecessary = true
er.migration.modelNames = MYMODELNAME
MYMODELNAME.MigrationClassPrefix=com.selbstdenker.foo.bar.migration.MYMODELNAME
Samstag, 22. Juni 13
Application.java
ā€¢ Requirement: subclass ERXApplication
ā€¢ If you subclassed a custom base class instead of WOApplication,
you can either make that inherit ERXApplication, or copy the
methods you need over to your Application class.
Samstag, 22. Juni 13
public class Application extends ERXApplication {
! public static void main( String[] argv ) {
! ! ERXApplication.main( argv, Application.class );
! }
Application.java (1/2)
Samstag, 22. Juni 13
public class Application extends ERXApplication {
! public static void main( String[] argv ) {
! ! ERXApplication.main( argv, Application.class );
! }
! public Application() {
! ! WOMessage.setDefaultEncoding( "UTF-8" );
! ! ERXMessageEncoding.setDefaultEncodingForAllLanguages( "UTF-8" );
! ! // ...and whatever else you need to have here, but not more.
! ! log.info( "######### Application startup complete #########" );
! }
Application.java (1/2)
Samstag, 22. Juni 13
public class Application extends ERXApplication {
! public static void main( String[] argv ) {
! ! ERXApplication.main( argv, Application.class );
! }
! public Application() {
! ! WOMessage.setDefaultEncoding( "UTF-8" );
! ! ERXMessageEncoding.setDefaultEncodingForAllLanguages( "UTF-8" );
! ! // ...and whatever else you need to have here, but not more.
! ! log.info( "######### Application startup complete #########" );
! }
! // everything that can be deferred better goes here instead
! @Override public void didFinishLaunching() {
! ! new ERXShutdownHook() {
! ! ! @Override public void hook() {
! ! ! ! // cleanup that needs to run when application is shut down
! ! ! }
! ! };
! ! // example for project-specific stuff
! ! taskManager = new BackgroundTaskManager();
! ! taskManager.newRecurringTask( new MySystemState.SystemStateUpdaterTask(), 60 );
! ! super.didFinishLaunching();
! ! log.info( "######### post-startup sequence complete #########" );
! }
Application.java (1/2)
Samstag, 22. Juni 13
public class Application extends ERXApplication {
! public static void main( String[] argv ) {
! ! ERXApplication.main( argv, Application.class );
! }
! public Application() {
! ! WOMessage.setDefaultEncoding( "UTF-8" );
! ! ERXMessageEncoding.setDefaultEncodingForAllLanguages( "UTF-8" );
! ! // ...and whatever else you need to have here, but not more.
! ! log.info( "######### Application startup complete #########" );
! }
! // everything that can be deferred better goes here instead
! @Override public void didFinishLaunching() {
! ! new ERXShutdownHook() {
! ! ! @Override public void hook() {
! ! ! ! // cleanup that needs to run when application is shut down
! ! ! }
! ! };
! ! // example for project-specific stuff
! ! taskManager = new BackgroundTaskManager();
! ! taskManager.newRecurringTask( new MySystemState.SystemStateUpdaterTask(), 60 );
! ! super.didFinishLaunching();
! ! log.info( "######### post-startup sequence complete #########" );
! }
Application.java (1/2)
Samstag, 22. Juni 13
! @Override protected void migrationsWillRun( ERXMigrator migrator ) {
! ! log.info( "Starting migrations" );
! }
!
! @Override protected void migrationsDidRun( ERXMigrator migrator ) {
! ! log.info( "Finished migrations" );
! }
}
Application.java (2/2)
Samstag, 22. Juni 13
! // instead of using a Property, this switches gzip on/off based on system type
! @Override public boolean responseCompressionEnabled() {
! ! switch( systemType() ) {
! ! ! case TESTING! ! : return true;
! ! ! case DEVELOPMENT! : return true;
! ! default!! ! ! : return false; // gzip done by load balancer
! ! }
! }
! @Override protected void migrationsWillRun( ERXMigrator migrator ) {
! ! log.info( "Starting migrations" );
! }
!
! @Override protected void migrationsDidRun( ERXMigrator migrator ) {
! ! log.info( "Finished migrations" );
! }
}
Application.java (2/2)
Samstag, 22. Juni 13
! // instead of using a Property, this switches gzip on/off based on system type
! @Override public boolean responseCompressionEnabled() {
! ! switch( systemType() ) {
! ! ! case TESTING! ! : return true;
! ! ! case DEVELOPMENT! : return true;
! ! default!! ! ! : return false; // gzip done by load balancer
! ! }
! }
! // the default context logging for exceptions is a bit too bulky for my taste, so strip that down a bit
! @Override public NSMutableDictionary extraInformationForExceptionInContext( Exception e, WOContext context ) {
! ! NSMutableDictionary<String,Object> extraInfo = ERXRuntimeUtilities.informationForException( e );
! ! // copy informatinForContext() from ERXApplication, override and strip down
! ! extraInfo.addEntriesFromDictionary( informationForContext( context ) );
! ! extraInfo.addEntriesFromDictionary( ERXRuntimeUtilities.informationForBundles() );
! ! return extraInfo;
! }
! @Override protected void migrationsWillRun( ERXMigrator migrator ) {
! ! log.info( "Starting migrations" );
! }
!
! @Override protected void migrationsDidRun( ERXMigrator migrator ) {
! ! log.info( "Finished migrations" );
! }
}
Application.java (2/2)
Samstag, 22. Juni 13
Session.java
ā€¢ Requirement: subclass ERXSession
ā€¢ No code to show, nothing special to adapt
ā€¢ Except when you had used MultiECLockManager
ā€¢ If you did and you want to switch to ERXEC autolocking,
remove any code related to MultiECLockManager from your
Session class
Samstag, 22. Juni 13
MyEditingContext.java
ā€¢ Recommendation: subclass ERXEC
ā€¢ You need to implement a factory
ā€¢ You can have multiple factories, like one that produces
autolocking contexts, and another for manual locking, without
having different classes.
Samstag, 22. Juni 13
MyEOEditingContext.java
public class MyEOEditingContext extends ERXEC {
! private boolean doCommitLogging;
! /*
! * Constructors and Factories
! */
! private static Factory _myAutoLockingFactory;
! private static Factory _myManualLockingFactory;
! private static synchronized Factory myAutoLockingFactory() {
! ! if( _myAutoLockingFactory == null ) {
! ! ! _myAutoLockingFactory = new MyECAutoLockingFactory();
! ! }
! ! return _myAutoLockingFactory;
! }
! private static synchronized Factory myManualLockingFactory() {
! ! if( _myManualLockingFactory == null ) {
! ! ! _myManualLockingFactory = new MyECManualLockingFactory();
! ! }
! ! return _myManualLockingFactory;
! }
Samstag, 22. Juni 13
! public static class MyECAutoLockingFactory extends ERXEC.DefaultFactory {
! ! @Override protected EOEditingContext _createEditingContext( EOObjectStore parent ) {
! ! ! MyEOEditingContext ec = new MyEOEditingContext(
! ! ! ! ! parent == null ? EOEditingContext.defaultParentObjectStore() : parent );
! ! ! setDefaultDelegateOnEditingContext( ec );
! ! ! return ec;
! ! }
! }
!
! public static class MyECManualLockingFactory extends ERXEC.DefaultFactory {
! ! @Override protected EOEditingContext _createEditingContext( EOObjectStore parent ) {
! ! ! MyEOEditingContext ec = new MyEOEditingContext(
! ! ! ! ! parent == null ? EOEditingContext.defaultParentObjectStore() : parent ) {
! ! ! ! @Override public boolean useAutoLock() { return false; }
! ! ! ! @Override public boolean coalesceAutoLocks() { return false; }
! ! ! };
! ! ! setDefaultDelegateOnEditingContext( ec );
! ! ! return ec;
! ! }
! }
MyEOEditingContext.java
Samstag, 22. Juni 13
! public static MyEOEditingContext newAutoLockingEC() {
! ! MyEOEditingContext newEC = (MyEOEditingContext) myAutoLockingFactory()._newEditingContext();
! ! newEC.init();
! ! return newEC;
! }
! public static MyEOEditingContext newAutoLockingEC( EOObjectStore objectStore ) {
! ! MyEOEditingContext newEC = (MyEOEditingContext) myAutoLockingFactory()._newEditingContext( objectStore );
! ! newEC.init();
! ! return newEC;
! }
! public static MyEOEditingContext newManualLockingEC() {
! ! MyEOEditingContext newEC = (MyEOEditingContext) myManualLockingFactory()._newEditingContext();
! ! newEC.init();
! ! return newEC;
! }
! public static MyEOEditingContext newManualLockingEC( EOObjectStore objectStore ) {
! ! MyEOEditingContext newEC = (MyEOEditingContext) myManualLockingFactory()._newEditingContext( objectStore );
! ! newEC.init();
! ! return newEC;
! }
! private void init() {
! ! doCommitLogging = true;
! ! setRetainsRegisteredObjects( true );! // http://lists.apple.com/archives/webobjects-dev/2010/Nov/msg00009.html
! }
MyEOEditingContext.java
Samstag, 22. Juni 13
! @Override public void saveChanges() {
! ! StringBuilder buf = null;
! ! if( doCommitLogging ) {
! ! ! buf = new StringBuilder();
! ! ! buf.append( "MyEC" ).append( useAutoLock() ? " autoLocking" : " manualLocking" ).append( " saveChanges()" );
! ! ! StackTraceElement[] stack = new Throwable().getStackTrace();
! ! ! if( stack != null && stack.length > 1 )! buf.append( "; " ).append( stack[1].toString() );
! ! ! Collection<String> updatedClasses = setOfClassesFor( updatedObjects() );
! ! ! Collection<String> insertedClasses = setOfClassesFor( insertedObjects() );
! ! ! Collection<String> deletedClasses = setOfClassesFor( deletedObjects() );
! ! ! if( insertedClasses.size() > 0 ) buf.append( "; ins: " ).append( Joiner.on(",").join( insertedClasses ) );
! ! ! if( updatedClasses.size() > 0 ) buf.append( "; upd: " ).append( Joiner.on(",").join( updatedClasses ) );
! ! ! if( deletedClasses.size() > 0 ) buf.append( "; del: " ).append( Joiner.on(",").join( deletedClasses ) );
! ! }
! ! long ms1 = 0; if( buf != null ) ms1 = System.currentTimeMillis();
! ! super.saveChanges();
! ! long ms2 = 0; if( buf != null ) ms2 = System.currentTimeMillis();
! ! NSUndoManager undoManager = undoManager();
! ! if( undoManager != null ) undoManager.removeAllActions();
! ! long ms3 = 0; if( buf != null ) ms3 = System.currentTimeMillis();
! ! if( buf != null ) {
! ! ! buf.append( "; times " ).append( ms2-ms1 ).append( " " ).append( ms3-ms2 );
! ! ! log.info( buf.toString() );
! ! }
! }
MyEOEditingContext.java
Samstag, 22. Juni 13
! @Override public void saveChanges() {
! ! StringBuilder buf = null;
! ! if( doCommitLogging ) {
! ! ! buf = new StringBuilder();
! ! ! buf.append( "MyEC" ).append( useAutoLock() ? " autoLocking" : " manualLocking" ).append( " saveChanges()" );
! ! ! StackTraceElement[] stack = new Throwable().getStackTrace();
! ! ! if( stack != null && stack.length > 1 )! buf.append( "; " ).append( stack[1].toString() );
! ! ! Collection<String> updatedClasses = setOfClassesFor( updatedObjects() );
! ! ! Collection<String> insertedClasses = setOfClassesFor( insertedObjects() );
! ! ! Collection<String> deletedClasses = setOfClassesFor( deletedObjects() );
! ! ! if( insertedClasses.size() > 0 ) buf.append( "; ins: " ).append( Joiner.on(",").join( insertedClasses ) );
! ! ! if( updatedClasses.size() > 0 ) buf.append( "; upd: " ).append( Joiner.on(",").join( updatedClasses ) );
! ! ! if( deletedClasses.size() > 0 ) buf.append( "; del: " ).append( Joiner.on(",").join( deletedClasses ) );
! ! }
! ! long ms1 = 0; if( buf != null ) ms1 = System.currentTimeMillis();
! ! super.saveChanges();
! ! long ms2 = 0; if( buf != null ) ms2 = System.currentTimeMillis();
! ! NSUndoManager undoManager = undoManager();
! ! if( undoManager != null ) undoManager.removeAllActions();
! ! long ms3 = 0; if( buf != null ) ms3 = System.currentTimeMillis();
! ! if( buf != null ) {
! ! ! buf.append( "; times " ).append( ms2-ms1 ).append( " " ).append( ms3-ms2 );
! ! ! log.info( buf.toString() );
! ! }
! }
MyEOEditingContext.java
MyEC autoLocking saveChanges();
com.selbstdenker.foo.bar.MyJourneyManager.createNewInvoice(MyJourneyManager.java:650);
ins: MyCustomerClaimItem(3),MyCustomerLiability(1),MyCustomerClaim(1);
upd: PDCJourney(1);
times 171 1
Samstag, 22. Juni 13
! private Collection<String> setOfClassesFor( NSArray<EOEnterpriseObject> objects ) {
! ! Multiset<String> classNames = HashMultiset.create();
! ! for( EOEnterpriseObject eo : objects ) {
! ! ! classNames.add( eo.getClass().getSimpleName() );
! ! }
! ! List<String> namesWithCount = Lists.newArrayList();
! ! for( Multiset.Entry entry : classNames.entrySet() ) {
! ! ! namesWithCount.add( entry.getElement() + "(" + entry.getCount() + ")" );
! ! }
! ! return namesWithCount;
! }
! public void setLoggingOnCommit( boolean value ) {
! ! this.doCommitLogging = value;
! }
MyEOEditingContext.java
Samstag, 22. Juni 13
!
public void lockIfManualLocking() {
! ! if( useAutoLock() ) return;
! ! lock();
! }
! public void unlockIfManualLocking() {
! ! if( useAutoLock() ) return;
! ! unlock();
! }
!
! public void saveChangesWithLockIfNecessary() {
! ! if( hasChanges() ) {
! ! ! lockIfManualLocking();
! ! ! try {
! ! ! ! saveChanges();
! ! ! } finally {
! ! ! ! unlockIfManualLocking();
! ! ! }
! ! }
! }
!
}
MyEOEditingContext.java
Samstag, 22. Juni 13
autolock vs. manual
ā€¢ In general, autolocking is the right choice for almost everything
ā€¢ Consider using manual locking for db-intensive background tasks
ā€¢ Main autolocking tradeoff: looots of lock/unlock calls that could
become a signiļ¬cant overhead, depending on what youā€˜re doing
Samstag, 22. Juni 13
! public static void deleteObsoleteFolderEntries() {
! ! Thread thread = new Thread() {
! ! ! @Override
! ! ! public void run() {
! ! ! ! log.info( "deleteObsoleteFolderEntries: starting" );
! ! ! ! MyEOEditingContext ec = MyEOEditingContext.newManualLockingEC();
! ! ! ! ec.lock();
! ! ! ! try {
! ! ! ! ! MyJourneyFolderEntry.deleteObsoleteEntries( ec );
! ! ! ! ! ec.saveChanges();
! ! ! ! } catch( Exception e ) {
! ! ! ! ! ec.revert();
! ! ! ! } finally {
! ! ! ! ! ec.unlock();
! ! ! ! }
! ! ! ! log.info( "deleteObsoleteFolderEntries: completed" );
! ! ! }
! ! };
! ! thread.start();
! }
Manual locking case example
Samstag, 22. Juni 13
! public static void deleteObsoleteFolderEntries() {
! ! Thread thread = new Thread() {
! ! ! @Override
! ! ! public void run() {
! ! ! ! log.info( "deleteObsoleteFolderEntries: starting" );
! ! ! ! MyEOEditingContext ec = MyEOEditingContext.newManualLockingEC();
! ! ! ! ec.lockIfManualLocking();
! ! ! ! try {
! ! ! ! ! MyJourneyFolderEntry.deleteObsoleteEntries( ec );
! ! ! ! ! ec.saveChanges();
! ! ! ! } catch( Exception e ) {
! ! ! ! ! ec.revert();
! ! ! ! } finally {
! ! ! ! ! ec.unlockIfManualLocking();
! ! ! ! }
! ! ! ! log.info( "deleteObsoleteFolderEntries: completed" );
! ! ! }
! ! };
! ! thread.start();
! }
Manual locking case example
Samstag, 22. Juni 13
ERXGenericRecord
ā€¢ Requirement: subclass ERXGenericRecord
ā€¢ With EOGenerator, simply change your templateā€˜s superclass
declaration and import statements
ā€¢ Of course you can change them to your own MyGenericRecord
class instead, and let that extend ERXGenericRecord
ā€¢ If you had a delegate in your EC to do stuff before saves, you can
now use ERXGenericRecord.willUpdate() and .willInsert()
instead
Samstag, 22. Juni 13
EO Templates
ā€¢ Use Wonder templates from WOLips
ā€¢ Thereā€˜s a wiki page with all sorts of alternatives
ā€¢ In any case, take one that deļ¬nes proper ERXKey constants
Samstag, 22. Juni 13
ERXDirectAction
ā€¢ Requirement: subclass ERXDirectAction
ā€¢ As usual, you can make your own base class in between
Samstag, 22. Juni 13
Youā€˜re done!
Samstag, 22. Juni 13
Youā€˜re done!
almost...
Samstag, 22. Juni 13
Suggestions to proceed
ā€¢ Beautify your qualiļ¬ers
ā€¢ Migrations
ā€¢ Array operators and bindings
Samstag, 22. Juni 13
ERX*Qualiļ¬er, ERXKey and ERXQ
public class MyFlightRoute extends _MyFlightRoute {
! public static enum FRSTATUS {
! ! obsolete,
! ! current,
! ! preliminary,
! ! deleted;
! }
! public void setStatus( FRSTATUS status ) {
! ! super.setStatus( status.name() );
! }
}
public abstract class _MyFlightRoute extends MyEOGenericRecord {
! public static final ERXKey<String> STATUS = new ERXKey<String>("status");
! public static final String STATUS_KEY = STATUS.key();
}
Samstag, 22. Juni 13
EOQualifier flightRouteValidQualifier =
! ! MyFlightRoute.STATUS.eq( FRSTATUS.current.name() ).or(
! ! MyFlightRoute.STATUS.eq( FRSTATUS.preliminary.name() )
);
EOQualifier flightRouteValidQualifier = ERXQ.or(
! ! MyFlightRoute.STATUS.eq( FRSTATUS.current.name() ),
! ! MyFlightRoute.STATUS.eq( FRSTATUS.preliminary.name() )
);
EOQualifier flightRouteValidQualifier = new EOOrQualifier( new NSArray( new Object[]{
! new EOKeyValueQualifier( MyFlightRoute.STATUS_KEY, EOQualifier.QualifierOperatorEqual, FRSTATUS.current.name() ),
! new EOKeyValueQualifier( MyFlightRoute.STATUS_KEY, EOQualifier.QualifierOperatorEqual, FRSTATUS.preliminary.name() )
} ) );
EOQualifier flightRouteValidQualifier =
! ! MyFlightRoute.STATUS.inObjects( FRSTATUS.current.name(), FRSTATUS.preliminary.name() );
ERX*Qualiļ¬er, ERXKey and ERXQ
Samstag, 22. Juni 13
public class MYMODELNAME17 extends MyMigration {
! @Override public void upgrade( EOEditingContext editingContext, ERXMigrationDatabase database ) throws Throwable {
! ! ERXMigrationTable journeyTable = database.existingTableNamed( MyJourney.ENTITY_NAME );
! ! journeyTable.newFlagBooleanColumn( MyJourney.MY_NEW_ATTR_KEY, ALLOWS_NULL );
! !
! ! String sql = "UPDATE MyJourney SET myNewAttr = false WHERE customerRef IN (...whatever...)";
! ! NSLog.out.appendln( "Executing SQL: " + sql );
! ! ERXJDBCUtilities.executeUpdate( database.adaptorChannel(), sql, true );
! ! MyUserRole specialRole = MyUserRole.newInEc( editingContext );
! ! specialRole.setName( "Speziaaaal" );
! ! specialRole.setRoleType( MyUserRole.ROLETYPE.special.name() );
! }
}
package com.selbstdenker.foo.bar.migration;
import com.webobjects.eocontrol.EOEditingContext;
import er.extensions.migration.ERXMigrationDatabase;
import er.extensions.migration.ERXMigrationDatabase.Migration;
public abstract class MyMigration extends Migration {
! @Override public void downgrade( EOEditingContext editingContext, ERXMigrationDatabase database ) throws Throwable {
! ! // do nothing
! }
}
Migrations
Samstag, 22. Juni 13
JourneyElementRepetition : WORepetition {
! list = selectedJourney.passengerArray.@sortDesc.sortKeyConsideringStatus;
! item = aPassenger;
}
Array operators and Bindings
Samstag, 22. Juni 13
<wo:if condition = "$selectedJourney.passengerArray.@isEmpty">
! <p>blah</p>
</wo:if>
JourneyElementRepetition : WORepetition {
! list = selectedJourney.passengerArray.@sortDesc.sortKeyConsideringStatus;
! item = aPassenger;
}
Array operators and Bindings
Samstag, 22. Juni 13
// valid
<wo:if condition = "$selectedJourney.passengerArray.@isEmpty">
! <p>blah</p>
</wo:if>
JourneyElementRepetition : WORepetition {
! list = selectedJourney.passengerArray.@sortDesc.sortKeyConsideringStatus;
! item = aPassenger;
}
Array operators and Bindings
Samstag, 22. Juni 13
// valid
<wo:if condition = "$selectedJourney.passengerArray.@isEmpty">
! <p>blah</p>
</wo:if>
JourneyElementRepetition : WORepetition {
! list = selectedJourney.passengerArray.@sortDesc.sortKeyConsideringStatus;
! item = aPassenger;
}
Array operators and Bindings
Samstag, 22. Juni 13
// valid
<wo:if condition = "$selectedJourney.passengerArray.@isEmpty">
! <p>blah</p>
</wo:if>
JourneyElementRepetition : WORepetition {
! list = selectedJourney.passengerArray.@sortDesc.sortKeyConsideringStatus;
! item = aPassenger;
}
Array operators and Bindings
Samstag, 22. Juni 13
Information sources
ā€¢ Wiki page ā€žProject Wonder Installationā€œ
ā€¢ Wiki page ā€žIntegrate Wonder into an Existing Applicationā€œ
ā€¢ Wiki page ā€žEOGenerator Templates and Additionsā€œ
ā€¢ Wiki page ā€žUTF-8 Encoding Tipsā€œ
ā€¢ projectlombok.org
Samstag, 22. Juni 13
Q&A
email: maik@selbstdenker.ag
twitter and app.net: @maikm
Samstag, 22. Juni 13

More Related Content

Viewers also liked

iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative version
WO Community
Ā 
Build and deployment
Build and deploymentBuild and deployment
Build and deployment
WO Community
Ā 
Unit Testing with WOUnit
Unit Testing with WOUnitUnit Testing with WOUnit
Unit Testing with WOUnit
WO Community
Ā 
Filtering data with D2W
Filtering data with D2W Filtering data with D2W
Filtering data with D2W
WO Community
Ā 
iOS for ERREST
iOS for ERRESTiOS for ERREST
iOS for ERREST
WO Community
Ā 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systems
WO Community
Ā 
Chaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldChaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real World
WO Community
Ā 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
WO Community
Ā 
Life outside WO
Life outside WOLife outside WO
Life outside WO
WO Community
Ā 
D2W Stateful Controllers
D2W Stateful ControllersD2W Stateful Controllers
D2W Stateful Controllers
WO Community
Ā 
Advanced Apache Cayenne
Advanced Apache CayenneAdvanced Apache Cayenne
Advanced Apache Cayenne
WO Community
Ā 
Deploying WO on Windows
Deploying WO on WindowsDeploying WO on Windows
Deploying WO on Windows
WO Community
Ā 
High availability
High availabilityHigh availability
High availability
WO Community
Ā 
KAAccessControl
KAAccessControlKAAccessControl
KAAccessControl
WO Community
Ā 
"Framework Principal" pattern
"Framework Principal" pattern"Framework Principal" pattern
"Framework Principal" pattern
WO Community
Ā 
In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engine
WO Community
Ā 

Viewers also liked (18)

iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative version
Ā 
Reenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWSReenabling SOAP using ERJaxWS
Reenabling SOAP using ERJaxWS
Ā 
Build and deployment
Build and deploymentBuild and deployment
Build and deployment
Ā 
Unit Testing with WOUnit
Unit Testing with WOUnitUnit Testing with WOUnit
Unit Testing with WOUnit
Ā 
Filtering data with D2W
Filtering data with D2W Filtering data with D2W
Filtering data with D2W
Ā 
iOS for ERREST
iOS for ERRESTiOS for ERREST
iOS for ERREST
Ā 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systems
Ā 
Chaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real WorldChaining the Beast - Testing Wonder Applications in the Real World
Chaining the Beast - Testing Wonder Applications in the Real World
Ā 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
Ā 
Life outside WO
Life outside WOLife outside WO
Life outside WO
Ā 
WOver
WOverWOver
WOver
Ā 
D2W Stateful Controllers
D2W Stateful ControllersD2W Stateful Controllers
D2W Stateful Controllers
Ā 
Advanced Apache Cayenne
Advanced Apache CayenneAdvanced Apache Cayenne
Advanced Apache Cayenne
Ā 
Deploying WO on Windows
Deploying WO on WindowsDeploying WO on Windows
Deploying WO on Windows
Ā 
High availability
High availabilityHigh availability
High availability
Ā 
KAAccessControl
KAAccessControlKAAccessControl
KAAccessControl
Ā 
"Framework Principal" pattern
"Framework Principal" pattern"Framework Principal" pattern
"Framework Principal" pattern
Ā 
In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engine
Ā 

Similar to Migrating existing Projects to Wonder

Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based Games
Ray Toal
Ā 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIs
Dmitry Buzdin
Ā 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
James Williams
Ā 
BookStoreCXFWS.classpathBookStoreCXFWS.project CXF.docx
BookStoreCXFWS.classpathBookStoreCXFWS.project  CXF.docxBookStoreCXFWS.classpathBookStoreCXFWS.project  CXF.docx
BookStoreCXFWS.classpathBookStoreCXFWS.project CXF.docx
hartrobert670
Ā 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
Gabriele Lana
Ā 

Similar to Migrating existing Projects to Wonder (20)

Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
Ā 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
Ā 
What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?
Ā 
Grooscript greach 2015
Grooscript greach 2015Grooscript greach 2015
Grooscript greach 2015
Ā 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based Games
Ā 
Connect2016 AD1387 Integrate with XPages and Java
Connect2016 AD1387 Integrate with XPages and JavaConnect2016 AD1387 Integrate with XPages and Java
Connect2016 AD1387 Integrate with XPages and Java
Ā 
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...
Ā 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIs
Ā 
Java Quiz Questions
Java Quiz QuestionsJava Quiz Questions
Java Quiz Questions
Ā 
Java for beginners
Java for beginnersJava for beginners
Java for beginners
Ā 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
Ā 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
Ā 
Grooscript gr8conf
Grooscript gr8confGrooscript gr8conf
Grooscript gr8conf
Ā 
Webinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and MorphiaWebinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and Morphia
Ā 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo Surabaya
Ā 
Mastering Java ByteCode
Mastering Java ByteCodeMastering Java ByteCode
Mastering Java ByteCode
Ā 
A re introduction to webpack - reactfoo - mumbai
A re introduction to webpack - reactfoo - mumbaiA re introduction to webpack - reactfoo - mumbai
A re introduction to webpack - reactfoo - mumbai
Ā 
Java.lang.object
Java.lang.objectJava.lang.object
Java.lang.object
Ā 
BookStoreCXFWS.classpathBookStoreCXFWS.project CXF.docx
BookStoreCXFWS.classpathBookStoreCXFWS.project  CXF.docxBookStoreCXFWS.classpathBookStoreCXFWS.project  CXF.docx
BookStoreCXFWS.classpathBookStoreCXFWS.project CXF.docx
Ā 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
Ā 

More from WO Community (12)

Localizing your apps for multibyte languages
Localizing your apps for multibyte languagesLocalizing your apps for multibyte languages
Localizing your apps for multibyte languages
Ā 
WOdka
WOdkaWOdka
WOdka
Ā 
ERGroupware
ERGroupwareERGroupware
ERGroupware
Ā 
D2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRollerD2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRoller
Ā 
CMS / BLOG and SnoWOman
CMS / BLOG and SnoWOmanCMS / BLOG and SnoWOman
CMS / BLOG and SnoWOman
Ā 
Using GIT
Using GITUsing GIT
Using GIT
Ā 
Persistent Session Storage
Persistent Session StoragePersistent Session Storage
Persistent Session Storage
Ā 
Back2 future
Back2 futureBack2 future
Back2 future
Ā 
WebObjects Optimization
WebObjects OptimizationWebObjects Optimization
WebObjects Optimization
Ā 
Dynamic Elements
Dynamic ElementsDynamic Elements
Dynamic Elements
Ā 
Practical ERSync
Practical ERSyncPractical ERSync
Practical ERSync
Ā 
ERRest: the Basics
ERRest: the BasicsERRest: the Basics
ERRest: the Basics
Ā 

Recently uploaded

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Ā 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Ā 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
Ā 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Ā 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
Ā 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Ā 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Ā 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Ā 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Ā 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Ā 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
Ā 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
Ā 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Ā 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜
Ā 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Ā 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
Ā 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Ā 

Migrating existing Projects to Wonder

  • 1. Migrating existing Projects to Wonder Maik Musall, Selbstdenker AG Samstag, 22. Juni 13
  • 2. ā€¢ Existing application of some complexity ā€¢ Using perhaps custom frameworks, but not yet Wonder ā€¢ Want to use Wonder for several reasons, but uncertain where to start and how to manage the migration process The Task Samstag, 22. Juni 13
  • 3. Goals ā€¢ Make the switch at a chosen, planned point in time ā€¢ Being able to switch back to the non-Wonder version if problems come up in production ā€¢ Identify which steps to do when, and how Samstag, 22. Juni 13
  • 4. The Big Steps ā€¢ Move to Git (if you havenā€˜t already) ā€¢ Prepare the code base ahead of the actual wonderization ā€¢ Create a wonderization branch ā€¢ Wonderize in that branch, periodically merge new stuff from your main branch ā€¢ Release and celebrate Samstag, 22. Juni 13
  • 5. Prep step: Move to Git ā€¢ Youā€˜ll need branches during the migration ā€¢ Wonder is Git-based anyway ā€¢ It just makes everything easier ā€¢ Plan some time to get up to speed using Git ļ¬rst ā€¢ Use Sourcetree Samstag, 22. Juni 13
  • 6. Prep step: Move to Git Time release branches masterdevelop hotfixes feature branches Feature for future release Tag 1.0 Major feature for next release From this point on, ā€œnext releaseā€ means the release after 1.0 Severe bug fixed for production: hotfix 0.2 Bugfixes from rel. branch may be continuously merged back into develop Tag 0.1 Tag 0.2 Incorporate bugfix in develop Only bugfixes! Start of release branch for 1.0 Author: Vincent Driessen Samstag, 22. Juni 13
  • 7. Prep step: Move to Git Time release branches masterdevelop hotfixes feature branches Feature for future release Major feature for next release Severe bug fixed for production: hotfix 0.2 Tag 0.1 Tag 0.2 Incorporate bugfix in develop Start ofSamstag, 22. Juni 13
  • 8. Prep step: Move to Git release Tag 1.0 From this point on, ā€œnext releaseā€ means the release after 1.0 Bugfixes from rel. branch may be Tag 0.2 Incorporate bugfix in develop Only bugfixes! Start of release branch for 1.0 Samstag, 22. Juni 13
  • 9. Prep step: Move to Git Tag 1.0 From this point on, ā€œnext releaseā€ means the release after 1.0 Bugfixes from rel. branch may be continuously merged back into develop Only bugfixes! Start of release branch for 1.0 Samstag, 22. Juni 13
  • 10. Managing Wonderization in Git ļ¬rst wonderized release second wonderized release conventional version as fallback conventional version as fallback wonderized version merged into main 1.0 1.0 develop wonderize 1.1 feature 1.2 1.2 1.3 1.3 2.0 1.2 Samstag, 22. Juni 13
  • 11. Prep step: Java packages ā€¢ You canā€˜t inherit from packaged classes if your classes arenā€˜t in packages, too ā€¢ So if you havenā€˜t already, create packages and move all your sources into them ā€¢ Beneļ¬t: clariļ¬ed namespaces for your stuff Samstag, 22. Juni 13
  • 12. Java packages gotchas ā€¢ Getters and setters in components need to be(come) public ā€¢ Check class.getName() calls to become class.getSimpleName() ā€¢ Class.forName() needs full packaged path ā€¢ Overridden methods in enums become unreachable code in WO bindings Samstag, 22. Juni 13
  • 13. public enum ContentType { ! literature { ! ! @Override public String cssClassName() { return "read"; } ! }, ! film { ! ! @Override public String cssClassName() { return "watch"; } ! }, ! music { ! ! @Override public String cssClassName() { return "listen"; } ! }; ! ! public abstract String cssClassName(); ! public boolean isAvailable() { return true; } } Packages: overriding enum methods Samstag, 22. Juni 13
  • 14. Packages: overriding enum methods public enum ContentType { ! literature { ! ! @Override public String cssClassName() { return "read"; } ! }, ! film { ! ! @Override public String cssClassName() { return "watch"; } ! }, ! music { ! ! @Override public String cssClassName() { return "listen"; } ! }, ! pr0n { ! ! @Override public String cssClassName() { ! ! ! return getUser().isAdult() ? "watch" : "nothingForYou"; ! ! } ! }; ! ! public abstract String cssClassName(); } Samstag, 22. Juni 13
  • 15. Packages: overriding enum methods public enum ContentType { ! literature { ! ! @Override String cssClassNameImpl() { return "read"; } ! }, ! film { ! ! @Override String cssClassNameImpl() { return "watch"; } ! }, ! music { ! ! @Override String cssClassNameImpl() { return "listen"; } ! }, ! pr0n { ! ! @Override String cssClassNameImpl() { ! ! ! return getUser().isAdult() ? "watch" : "nothingForYou"; ! ! } ! }; ! ! abstract String cssClassNameImpl(); ! public String cssClassName() { return cssClassNameImpl(); } } Samstag, 22. Juni 13
  • 16. Packages: overriding enum methods public enum ContentType implements NSKeyValueCoding { ! literature { ! ! @Override public String cssClassName() { return "read"; } ! }, ! film { ! ! @Override public String cssClassName() { return "watch"; } ! }, ! music { ! ! @Override public String cssClassName() { return "listen"; } ! }, ! pr0n { ! ! @Override public String cssClassName() { ! ! ! return getUser().isAdult() ? "watch" : "nothingForYou"; ! ! } ! }; ! ! ! public abstract String cssClassName(); ! @Override public void takeValueForKey( Object obj, String s ) { return; } ! @Override public Object valueForKey( String s ) { ! ! try { ! ! ! return this.getClass().getMethod( s, (Class<?>[]) null ).invoke( this, (Object[]) null ); ! ! } catch( Exception e ) { ! ! ! throw new RuntimeException( e ); ! ! } ! } } Samstag, 22. Juni 13
  • 17. Prep step: own EC class ā€¢ You gain a lot of ļ¬‚exibility by using your own EOEditingContext subclass ā€¢ example: logging on saveChanges() or invalidateAllObjects() ā€¢ example: undoManager().removeAllActions() after saves ā€¢ Changing the superclass later to ERXEC becomes easy Samstag, 22. Juni 13
  • 18. Prep step: own DA class ā€¢ Create a common superclass between concrete DirectAction classes and WODirectAction ā€¢ Changing the superclass later to ERXDirectAction becomes easy Samstag, 22. Juni 13
  • 19. Prep step: own logging class ā€¢ Create your own org.apache.log4j.Logger subclass ā€¢ Changing the superclass later to ERXLogger becomes easy Samstag, 22. Juni 13
  • 20. import org.apache.log4j.Logger; public class MyLogger extends Logger { ! public MyLogger( String name ) { ! ! super( name ); ! } ! public static Factory factory = null; ! static { ! ! String factoryClassName = MyLogger.Factory.class.getName(); ! ! try { ! ! ! MyLogger.factory = (Factory) Class.forName( factoryClassName ).newInstance(); ! ! } catch( Exception ex ) { ! ! ! System.err.println( "Exception while creating logger factory of class " + factoryClassName + ": " + ex ); ! ! } ! } ! public static class Factory implements org.apache.log4j.spi.LoggerFactory { ! ! @Override ! ! public Logger makeNewLoggerInstance( String name ) { ! ! ! return new MyLogger( name ); ! ! } ! ! public void loggingConfigurationDidChange() { ! ! } ! } Your own logging class (1/2) Samstag, 22. Juni 13
  • 21. ! public static MyLogger getMyLogger( String name ) { ! ! Logger logger = MyLogger.getLogger( name ); ! ! if( logger != null && ! (logger instanceof MyLogger) ) { ! ! ! throw new RuntimeException( ! ! ! ! "Can't load Logger for "" ! ! ! ! + name ! ! ! ! + "" because it is not of class MyLogger but "" ! ! ! ! + logger.getClass().getName() ! ! ! ! + "". Check if there is a "log4j.loggerFactory=er.extensions.Logger$Factory" line in your properties." ! ! ! ); ! ! } ! ! return (MyLogger) logger; ! } ! public static Logger getLogger( String name ) { ! ! return Logger.getLogger( name, MyLogger.factory ); ! } ! public static MyLogger getMyLogger( Class clazz ) { ! ! return MyLogger.getMyLogger( clazz.getName() ); ! } ! public static Logger getLogger( Class clazz ) { ! ! return MyLogger.getMyLogger( clazz ); ! } } Your own logging class (2/2) Samstag, 22. Juni 13
  • 22. Prep step: rename enums ā€¢ ERXKey constants in new templates could collide with enum names ā€¢ Common collision pattern: uppercase enum with same name as EO attribute ā€¢ Eclipse refactoring tools are your friend ā€¢ Make this a separate commit Samstag, 22. Juni 13
  • 23. public class MyFlightRoute extends _MyFlightRoute { ! public static enum STATUS { ! ! obsolete, ! ! current, ! ! preliminary, ! ! deleted; ! } ! public void setStatus( STATUS status ) { ! ! super.setStatus( status.name() ); ! } } enum renames Samstag, 22. Juni 13
  • 24. public class MyFlightRoute extends _MyFlightRoute { ! public static enum STATUS { ! ! obsolete, ! ! current, ! ! preliminary, ! ! deleted; ! } ! public void setStatus( STATUS status ) { ! ! super.setStatus( status.name() ); ! } } public abstract class _MyFlightRoute extends MyEOGenericRecord { ! public static final ERXKey<String> STATUS = new ERXKey<String>("status"); ! public static final String STATUS_KEY = STATUS.key(); } enum renames Samstag, 22. Juni 13
  • 25. public class MyFlightRoute extends _MyFlightRoute { ! public static enum STATUS { ! ! obsolete, ! ! current, ! ! preliminary, ! ! deleted; ! } ! public void setStatus( STATUS status ) { ! ! super.setStatus( status.name() ); ! } } public abstract class _MyFlightRoute extends MyEOGenericRecord { ! public static final ERXKey<String> STATUS = new ERXKey<String>("status"); ! public static final String STATUS_KEY = STATUS.key(); } enum renames Samstag, 22. Juni 13
  • 26. public class MyFlightRoute extends _MyFlightRoute { ! public static enum FRSTATUS { ! ! obsolete, ! ! current, ! ! preliminary, ! ! deleted; ! } ! public void setStatus( FRSTATUS status ) { ! ! super.setStatus( status.name() ); ! } } public abstract class _MyFlightRoute extends MyEOGenericRecord { ! public static final ERXKey<String> STATUS = new ERXKey<String>("status"); ! public static final String STATUS_KEY = STATUS.key(); } enum renames Samstag, 22. Juni 13
  • 27. Prep step: instance settings ā€¢-XX:MaxPermSize=256m Samstag, 22. Juni 13
  • 28. Wonderization: Frameworks ā€¢ Now is the time to start the actual wonderization ā€¢ Start by the usual way to import Wonder into Eclipse ā€¢ Then add ERJars, ERExtensions,WOOgnl and Wonderā€˜s JavaWOExtensions to your project ā€¢ And ERPrototypes if you want to use them ā€¢ Remove log4j and potentially other jars that are contained in ERJars (check version compatibilities) Samstag, 22. Juni 13
  • 29. Properties ļ¬le ā€¢ Wonder manages nearly all settings through Properties ā€¢ Live in ļ¬le Resources/Properties ā€¢ You have to create at least a minimal ļ¬le to start with Samstag, 22. Juni 13
  • 30. Properties ļ¬le # OGNL ognl.active = true ognl.helperFunctions = true ognl.inlineBindings = true ognl.parseStandardTags = false # Misc er.extensions.stackTrace.cleanup = true file.encoding = UTF-8 # EOF er.extensions.ERXEC.safeLocking = true er.extensions.ERXEC.useSharedEditingContext = false er.extensions.ERXEnterpriseObject.applyRestrictingQualifierOnInsert = true er.extensions.ERXRaiseOnMissingEditingContextDelegate = false # Migrations er.migration.migrateAtStartup = true er.migration.createTablesIfNecessary = true er.migration.modelNames = MYMODELNAME MYMODELNAME.MigrationClassPrefix=com.selbstdenker.foo.bar.migration.MYMODELNAME Samstag, 22. Juni 13
  • 31. Application.java ā€¢ Requirement: subclass ERXApplication ā€¢ If you subclassed a custom base class instead of WOApplication, you can either make that inherit ERXApplication, or copy the methods you need over to your Application class. Samstag, 22. Juni 13
  • 32. public class Application extends ERXApplication { ! public static void main( String[] argv ) { ! ! ERXApplication.main( argv, Application.class ); ! } Application.java (1/2) Samstag, 22. Juni 13
  • 33. public class Application extends ERXApplication { ! public static void main( String[] argv ) { ! ! ERXApplication.main( argv, Application.class ); ! } ! public Application() { ! ! WOMessage.setDefaultEncoding( "UTF-8" ); ! ! ERXMessageEncoding.setDefaultEncodingForAllLanguages( "UTF-8" ); ! ! // ...and whatever else you need to have here, but not more. ! ! log.info( "######### Application startup complete #########" ); ! } Application.java (1/2) Samstag, 22. Juni 13
  • 34. public class Application extends ERXApplication { ! public static void main( String[] argv ) { ! ! ERXApplication.main( argv, Application.class ); ! } ! public Application() { ! ! WOMessage.setDefaultEncoding( "UTF-8" ); ! ! ERXMessageEncoding.setDefaultEncodingForAllLanguages( "UTF-8" ); ! ! // ...and whatever else you need to have here, but not more. ! ! log.info( "######### Application startup complete #########" ); ! } ! // everything that can be deferred better goes here instead ! @Override public void didFinishLaunching() { ! ! new ERXShutdownHook() { ! ! ! @Override public void hook() { ! ! ! ! // cleanup that needs to run when application is shut down ! ! ! } ! ! }; ! ! // example for project-specific stuff ! ! taskManager = new BackgroundTaskManager(); ! ! taskManager.newRecurringTask( new MySystemState.SystemStateUpdaterTask(), 60 ); ! ! super.didFinishLaunching(); ! ! log.info( "######### post-startup sequence complete #########" ); ! } Application.java (1/2) Samstag, 22. Juni 13
  • 35. public class Application extends ERXApplication { ! public static void main( String[] argv ) { ! ! ERXApplication.main( argv, Application.class ); ! } ! public Application() { ! ! WOMessage.setDefaultEncoding( "UTF-8" ); ! ! ERXMessageEncoding.setDefaultEncodingForAllLanguages( "UTF-8" ); ! ! // ...and whatever else you need to have here, but not more. ! ! log.info( "######### Application startup complete #########" ); ! } ! // everything that can be deferred better goes here instead ! @Override public void didFinishLaunching() { ! ! new ERXShutdownHook() { ! ! ! @Override public void hook() { ! ! ! ! // cleanup that needs to run when application is shut down ! ! ! } ! ! }; ! ! // example for project-specific stuff ! ! taskManager = new BackgroundTaskManager(); ! ! taskManager.newRecurringTask( new MySystemState.SystemStateUpdaterTask(), 60 ); ! ! super.didFinishLaunching(); ! ! log.info( "######### post-startup sequence complete #########" ); ! } Application.java (1/2) Samstag, 22. Juni 13
  • 36. ! @Override protected void migrationsWillRun( ERXMigrator migrator ) { ! ! log.info( "Starting migrations" ); ! } ! ! @Override protected void migrationsDidRun( ERXMigrator migrator ) { ! ! log.info( "Finished migrations" ); ! } } Application.java (2/2) Samstag, 22. Juni 13
  • 37. ! // instead of using a Property, this switches gzip on/off based on system type ! @Override public boolean responseCompressionEnabled() { ! ! switch( systemType() ) { ! ! ! case TESTING! ! : return true; ! ! ! case DEVELOPMENT! : return true; ! ! default!! ! ! : return false; // gzip done by load balancer ! ! } ! } ! @Override protected void migrationsWillRun( ERXMigrator migrator ) { ! ! log.info( "Starting migrations" ); ! } ! ! @Override protected void migrationsDidRun( ERXMigrator migrator ) { ! ! log.info( "Finished migrations" ); ! } } Application.java (2/2) Samstag, 22. Juni 13
  • 38. ! // instead of using a Property, this switches gzip on/off based on system type ! @Override public boolean responseCompressionEnabled() { ! ! switch( systemType() ) { ! ! ! case TESTING! ! : return true; ! ! ! case DEVELOPMENT! : return true; ! ! default!! ! ! : return false; // gzip done by load balancer ! ! } ! } ! // the default context logging for exceptions is a bit too bulky for my taste, so strip that down a bit ! @Override public NSMutableDictionary extraInformationForExceptionInContext( Exception e, WOContext context ) { ! ! NSMutableDictionary<String,Object> extraInfo = ERXRuntimeUtilities.informationForException( e ); ! ! // copy informatinForContext() from ERXApplication, override and strip down ! ! extraInfo.addEntriesFromDictionary( informationForContext( context ) ); ! ! extraInfo.addEntriesFromDictionary( ERXRuntimeUtilities.informationForBundles() ); ! ! return extraInfo; ! } ! @Override protected void migrationsWillRun( ERXMigrator migrator ) { ! ! log.info( "Starting migrations" ); ! } ! ! @Override protected void migrationsDidRun( ERXMigrator migrator ) { ! ! log.info( "Finished migrations" ); ! } } Application.java (2/2) Samstag, 22. Juni 13
  • 39. Session.java ā€¢ Requirement: subclass ERXSession ā€¢ No code to show, nothing special to adapt ā€¢ Except when you had used MultiECLockManager ā€¢ If you did and you want to switch to ERXEC autolocking, remove any code related to MultiECLockManager from your Session class Samstag, 22. Juni 13
  • 40. MyEditingContext.java ā€¢ Recommendation: subclass ERXEC ā€¢ You need to implement a factory ā€¢ You can have multiple factories, like one that produces autolocking contexts, and another for manual locking, without having different classes. Samstag, 22. Juni 13
  • 41. MyEOEditingContext.java public class MyEOEditingContext extends ERXEC { ! private boolean doCommitLogging; ! /* ! * Constructors and Factories ! */ ! private static Factory _myAutoLockingFactory; ! private static Factory _myManualLockingFactory; ! private static synchronized Factory myAutoLockingFactory() { ! ! if( _myAutoLockingFactory == null ) { ! ! ! _myAutoLockingFactory = new MyECAutoLockingFactory(); ! ! } ! ! return _myAutoLockingFactory; ! } ! private static synchronized Factory myManualLockingFactory() { ! ! if( _myManualLockingFactory == null ) { ! ! ! _myManualLockingFactory = new MyECManualLockingFactory(); ! ! } ! ! return _myManualLockingFactory; ! } Samstag, 22. Juni 13
  • 42. ! public static class MyECAutoLockingFactory extends ERXEC.DefaultFactory { ! ! @Override protected EOEditingContext _createEditingContext( EOObjectStore parent ) { ! ! ! MyEOEditingContext ec = new MyEOEditingContext( ! ! ! ! ! parent == null ? EOEditingContext.defaultParentObjectStore() : parent ); ! ! ! setDefaultDelegateOnEditingContext( ec ); ! ! ! return ec; ! ! } ! } ! ! public static class MyECManualLockingFactory extends ERXEC.DefaultFactory { ! ! @Override protected EOEditingContext _createEditingContext( EOObjectStore parent ) { ! ! ! MyEOEditingContext ec = new MyEOEditingContext( ! ! ! ! ! parent == null ? EOEditingContext.defaultParentObjectStore() : parent ) { ! ! ! ! @Override public boolean useAutoLock() { return false; } ! ! ! ! @Override public boolean coalesceAutoLocks() { return false; } ! ! ! }; ! ! ! setDefaultDelegateOnEditingContext( ec ); ! ! ! return ec; ! ! } ! } MyEOEditingContext.java Samstag, 22. Juni 13
  • 43. ! public static MyEOEditingContext newAutoLockingEC() { ! ! MyEOEditingContext newEC = (MyEOEditingContext) myAutoLockingFactory()._newEditingContext(); ! ! newEC.init(); ! ! return newEC; ! } ! public static MyEOEditingContext newAutoLockingEC( EOObjectStore objectStore ) { ! ! MyEOEditingContext newEC = (MyEOEditingContext) myAutoLockingFactory()._newEditingContext( objectStore ); ! ! newEC.init(); ! ! return newEC; ! } ! public static MyEOEditingContext newManualLockingEC() { ! ! MyEOEditingContext newEC = (MyEOEditingContext) myManualLockingFactory()._newEditingContext(); ! ! newEC.init(); ! ! return newEC; ! } ! public static MyEOEditingContext newManualLockingEC( EOObjectStore objectStore ) { ! ! MyEOEditingContext newEC = (MyEOEditingContext) myManualLockingFactory()._newEditingContext( objectStore ); ! ! newEC.init(); ! ! return newEC; ! } ! private void init() { ! ! doCommitLogging = true; ! ! setRetainsRegisteredObjects( true );! // http://lists.apple.com/archives/webobjects-dev/2010/Nov/msg00009.html ! } MyEOEditingContext.java Samstag, 22. Juni 13
  • 44. ! @Override public void saveChanges() { ! ! StringBuilder buf = null; ! ! if( doCommitLogging ) { ! ! ! buf = new StringBuilder(); ! ! ! buf.append( "MyEC" ).append( useAutoLock() ? " autoLocking" : " manualLocking" ).append( " saveChanges()" ); ! ! ! StackTraceElement[] stack = new Throwable().getStackTrace(); ! ! ! if( stack != null && stack.length > 1 )! buf.append( "; " ).append( stack[1].toString() ); ! ! ! Collection<String> updatedClasses = setOfClassesFor( updatedObjects() ); ! ! ! Collection<String> insertedClasses = setOfClassesFor( insertedObjects() ); ! ! ! Collection<String> deletedClasses = setOfClassesFor( deletedObjects() ); ! ! ! if( insertedClasses.size() > 0 ) buf.append( "; ins: " ).append( Joiner.on(",").join( insertedClasses ) ); ! ! ! if( updatedClasses.size() > 0 ) buf.append( "; upd: " ).append( Joiner.on(",").join( updatedClasses ) ); ! ! ! if( deletedClasses.size() > 0 ) buf.append( "; del: " ).append( Joiner.on(",").join( deletedClasses ) ); ! ! } ! ! long ms1 = 0; if( buf != null ) ms1 = System.currentTimeMillis(); ! ! super.saveChanges(); ! ! long ms2 = 0; if( buf != null ) ms2 = System.currentTimeMillis(); ! ! NSUndoManager undoManager = undoManager(); ! ! if( undoManager != null ) undoManager.removeAllActions(); ! ! long ms3 = 0; if( buf != null ) ms3 = System.currentTimeMillis(); ! ! if( buf != null ) { ! ! ! buf.append( "; times " ).append( ms2-ms1 ).append( " " ).append( ms3-ms2 ); ! ! ! log.info( buf.toString() ); ! ! } ! } MyEOEditingContext.java Samstag, 22. Juni 13
  • 45. ! @Override public void saveChanges() { ! ! StringBuilder buf = null; ! ! if( doCommitLogging ) { ! ! ! buf = new StringBuilder(); ! ! ! buf.append( "MyEC" ).append( useAutoLock() ? " autoLocking" : " manualLocking" ).append( " saveChanges()" ); ! ! ! StackTraceElement[] stack = new Throwable().getStackTrace(); ! ! ! if( stack != null && stack.length > 1 )! buf.append( "; " ).append( stack[1].toString() ); ! ! ! Collection<String> updatedClasses = setOfClassesFor( updatedObjects() ); ! ! ! Collection<String> insertedClasses = setOfClassesFor( insertedObjects() ); ! ! ! Collection<String> deletedClasses = setOfClassesFor( deletedObjects() ); ! ! ! if( insertedClasses.size() > 0 ) buf.append( "; ins: " ).append( Joiner.on(",").join( insertedClasses ) ); ! ! ! if( updatedClasses.size() > 0 ) buf.append( "; upd: " ).append( Joiner.on(",").join( updatedClasses ) ); ! ! ! if( deletedClasses.size() > 0 ) buf.append( "; del: " ).append( Joiner.on(",").join( deletedClasses ) ); ! ! } ! ! long ms1 = 0; if( buf != null ) ms1 = System.currentTimeMillis(); ! ! super.saveChanges(); ! ! long ms2 = 0; if( buf != null ) ms2 = System.currentTimeMillis(); ! ! NSUndoManager undoManager = undoManager(); ! ! if( undoManager != null ) undoManager.removeAllActions(); ! ! long ms3 = 0; if( buf != null ) ms3 = System.currentTimeMillis(); ! ! if( buf != null ) { ! ! ! buf.append( "; times " ).append( ms2-ms1 ).append( " " ).append( ms3-ms2 ); ! ! ! log.info( buf.toString() ); ! ! } ! } MyEOEditingContext.java MyEC autoLocking saveChanges(); com.selbstdenker.foo.bar.MyJourneyManager.createNewInvoice(MyJourneyManager.java:650); ins: MyCustomerClaimItem(3),MyCustomerLiability(1),MyCustomerClaim(1); upd: PDCJourney(1); times 171 1 Samstag, 22. Juni 13
  • 46. ! private Collection<String> setOfClassesFor( NSArray<EOEnterpriseObject> objects ) { ! ! Multiset<String> classNames = HashMultiset.create(); ! ! for( EOEnterpriseObject eo : objects ) { ! ! ! classNames.add( eo.getClass().getSimpleName() ); ! ! } ! ! List<String> namesWithCount = Lists.newArrayList(); ! ! for( Multiset.Entry entry : classNames.entrySet() ) { ! ! ! namesWithCount.add( entry.getElement() + "(" + entry.getCount() + ")" ); ! ! } ! ! return namesWithCount; ! } ! public void setLoggingOnCommit( boolean value ) { ! ! this.doCommitLogging = value; ! } MyEOEditingContext.java Samstag, 22. Juni 13
  • 47. ! public void lockIfManualLocking() { ! ! if( useAutoLock() ) return; ! ! lock(); ! } ! public void unlockIfManualLocking() { ! ! if( useAutoLock() ) return; ! ! unlock(); ! } ! ! public void saveChangesWithLockIfNecessary() { ! ! if( hasChanges() ) { ! ! ! lockIfManualLocking(); ! ! ! try { ! ! ! ! saveChanges(); ! ! ! } finally { ! ! ! ! unlockIfManualLocking(); ! ! ! } ! ! } ! } ! } MyEOEditingContext.java Samstag, 22. Juni 13
  • 48. autolock vs. manual ā€¢ In general, autolocking is the right choice for almost everything ā€¢ Consider using manual locking for db-intensive background tasks ā€¢ Main autolocking tradeoff: looots of lock/unlock calls that could become a signiļ¬cant overhead, depending on what youā€˜re doing Samstag, 22. Juni 13
  • 49. ! public static void deleteObsoleteFolderEntries() { ! ! Thread thread = new Thread() { ! ! ! @Override ! ! ! public void run() { ! ! ! ! log.info( "deleteObsoleteFolderEntries: starting" ); ! ! ! ! MyEOEditingContext ec = MyEOEditingContext.newManualLockingEC(); ! ! ! ! ec.lock(); ! ! ! ! try { ! ! ! ! ! MyJourneyFolderEntry.deleteObsoleteEntries( ec ); ! ! ! ! ! ec.saveChanges(); ! ! ! ! } catch( Exception e ) { ! ! ! ! ! ec.revert(); ! ! ! ! } finally { ! ! ! ! ! ec.unlock(); ! ! ! ! } ! ! ! ! log.info( "deleteObsoleteFolderEntries: completed" ); ! ! ! } ! ! }; ! ! thread.start(); ! } Manual locking case example Samstag, 22. Juni 13
  • 50. ! public static void deleteObsoleteFolderEntries() { ! ! Thread thread = new Thread() { ! ! ! @Override ! ! ! public void run() { ! ! ! ! log.info( "deleteObsoleteFolderEntries: starting" ); ! ! ! ! MyEOEditingContext ec = MyEOEditingContext.newManualLockingEC(); ! ! ! ! ec.lockIfManualLocking(); ! ! ! ! try { ! ! ! ! ! MyJourneyFolderEntry.deleteObsoleteEntries( ec ); ! ! ! ! ! ec.saveChanges(); ! ! ! ! } catch( Exception e ) { ! ! ! ! ! ec.revert(); ! ! ! ! } finally { ! ! ! ! ! ec.unlockIfManualLocking(); ! ! ! ! } ! ! ! ! log.info( "deleteObsoleteFolderEntries: completed" ); ! ! ! } ! ! }; ! ! thread.start(); ! } Manual locking case example Samstag, 22. Juni 13
  • 51. ERXGenericRecord ā€¢ Requirement: subclass ERXGenericRecord ā€¢ With EOGenerator, simply change your templateā€˜s superclass declaration and import statements ā€¢ Of course you can change them to your own MyGenericRecord class instead, and let that extend ERXGenericRecord ā€¢ If you had a delegate in your EC to do stuff before saves, you can now use ERXGenericRecord.willUpdate() and .willInsert() instead Samstag, 22. Juni 13
  • 52. EO Templates ā€¢ Use Wonder templates from WOLips ā€¢ Thereā€˜s a wiki page with all sorts of alternatives ā€¢ In any case, take one that deļ¬nes proper ERXKey constants Samstag, 22. Juni 13
  • 53. ERXDirectAction ā€¢ Requirement: subclass ERXDirectAction ā€¢ As usual, you can make your own base class in between Samstag, 22. Juni 13
  • 56. Suggestions to proceed ā€¢ Beautify your qualiļ¬ers ā€¢ Migrations ā€¢ Array operators and bindings Samstag, 22. Juni 13
  • 57. ERX*Qualiļ¬er, ERXKey and ERXQ public class MyFlightRoute extends _MyFlightRoute { ! public static enum FRSTATUS { ! ! obsolete, ! ! current, ! ! preliminary, ! ! deleted; ! } ! public void setStatus( FRSTATUS status ) { ! ! super.setStatus( status.name() ); ! } } public abstract class _MyFlightRoute extends MyEOGenericRecord { ! public static final ERXKey<String> STATUS = new ERXKey<String>("status"); ! public static final String STATUS_KEY = STATUS.key(); } Samstag, 22. Juni 13
  • 58. EOQualifier flightRouteValidQualifier = ! ! MyFlightRoute.STATUS.eq( FRSTATUS.current.name() ).or( ! ! MyFlightRoute.STATUS.eq( FRSTATUS.preliminary.name() ) ); EOQualifier flightRouteValidQualifier = ERXQ.or( ! ! MyFlightRoute.STATUS.eq( FRSTATUS.current.name() ), ! ! MyFlightRoute.STATUS.eq( FRSTATUS.preliminary.name() ) ); EOQualifier flightRouteValidQualifier = new EOOrQualifier( new NSArray( new Object[]{ ! new EOKeyValueQualifier( MyFlightRoute.STATUS_KEY, EOQualifier.QualifierOperatorEqual, FRSTATUS.current.name() ), ! new EOKeyValueQualifier( MyFlightRoute.STATUS_KEY, EOQualifier.QualifierOperatorEqual, FRSTATUS.preliminary.name() ) } ) ); EOQualifier flightRouteValidQualifier = ! ! MyFlightRoute.STATUS.inObjects( FRSTATUS.current.name(), FRSTATUS.preliminary.name() ); ERX*Qualiļ¬er, ERXKey and ERXQ Samstag, 22. Juni 13
  • 59. public class MYMODELNAME17 extends MyMigration { ! @Override public void upgrade( EOEditingContext editingContext, ERXMigrationDatabase database ) throws Throwable { ! ! ERXMigrationTable journeyTable = database.existingTableNamed( MyJourney.ENTITY_NAME ); ! ! journeyTable.newFlagBooleanColumn( MyJourney.MY_NEW_ATTR_KEY, ALLOWS_NULL ); ! ! ! ! String sql = "UPDATE MyJourney SET myNewAttr = false WHERE customerRef IN (...whatever...)"; ! ! NSLog.out.appendln( "Executing SQL: " + sql ); ! ! ERXJDBCUtilities.executeUpdate( database.adaptorChannel(), sql, true ); ! ! MyUserRole specialRole = MyUserRole.newInEc( editingContext ); ! ! specialRole.setName( "Speziaaaal" ); ! ! specialRole.setRoleType( MyUserRole.ROLETYPE.special.name() ); ! } } package com.selbstdenker.foo.bar.migration; import com.webobjects.eocontrol.EOEditingContext; import er.extensions.migration.ERXMigrationDatabase; import er.extensions.migration.ERXMigrationDatabase.Migration; public abstract class MyMigration extends Migration { ! @Override public void downgrade( EOEditingContext editingContext, ERXMigrationDatabase database ) throws Throwable { ! ! // do nothing ! } } Migrations Samstag, 22. Juni 13
  • 60. JourneyElementRepetition : WORepetition { ! list = selectedJourney.passengerArray.@sortDesc.sortKeyConsideringStatus; ! item = aPassenger; } Array operators and Bindings Samstag, 22. Juni 13
  • 61. <wo:if condition = "$selectedJourney.passengerArray.@isEmpty"> ! <p>blah</p> </wo:if> JourneyElementRepetition : WORepetition { ! list = selectedJourney.passengerArray.@sortDesc.sortKeyConsideringStatus; ! item = aPassenger; } Array operators and Bindings Samstag, 22. Juni 13
  • 62. // valid <wo:if condition = "$selectedJourney.passengerArray.@isEmpty"> ! <p>blah</p> </wo:if> JourneyElementRepetition : WORepetition { ! list = selectedJourney.passengerArray.@sortDesc.sortKeyConsideringStatus; ! item = aPassenger; } Array operators and Bindings Samstag, 22. Juni 13
  • 63. // valid <wo:if condition = "$selectedJourney.passengerArray.@isEmpty"> ! <p>blah</p> </wo:if> JourneyElementRepetition : WORepetition { ! list = selectedJourney.passengerArray.@sortDesc.sortKeyConsideringStatus; ! item = aPassenger; } Array operators and Bindings Samstag, 22. Juni 13
  • 64. // valid <wo:if condition = "$selectedJourney.passengerArray.@isEmpty"> ! <p>blah</p> </wo:if> JourneyElementRepetition : WORepetition { ! list = selectedJourney.passengerArray.@sortDesc.sortKeyConsideringStatus; ! item = aPassenger; } Array operators and Bindings Samstag, 22. Juni 13
  • 65. Information sources ā€¢ Wiki page ā€žProject Wonder Installationā€œ ā€¢ Wiki page ā€žIntegrate Wonder into an Existing Applicationā€œ ā€¢ Wiki page ā€žEOGenerator Templates and Additionsā€œ ā€¢ Wiki page ā€žUTF-8 Encoding Tipsā€œ ā€¢ projectlombok.org Samstag, 22. Juni 13
  • 66. Q&A email: maik@selbstdenker.ag twitter and app.net: @maikm Samstag, 22. Juni 13