Created
October 15, 2014 11:17
-
-
Save pablisco/cd2336b25bbbd6a97550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2014 Work Angel Ltd. All rights reserved. | |
*/ | |
package com.wam.persistency.model.evolutions; | |
/** | |
* Created by pablisco on 14/10/2014. | |
*/ | |
public enum ModelEvolution { | |
INSTANCE; | |
private final Integer INITIAL_VERSION = 1; | |
private Integer currentVersion = INITIAL_VERSION; | |
public static ModelEvolution getModelEvolution() { | |
return INSTANCE; | |
} | |
{ | |
mutate() // VERSION 2 | |
.entity("user").rename("better_user") | |
.entity("wallet") | |
.field("money").retype("double") | |
.field("percentage").rename("total") | |
.field("meme").delete() | |
.entity(""); | |
mutate() // VERSION 3 | |
.withScript("test_script"); | |
} | |
public class EntityMutation { | |
private final String mName; | |
private final Version mVersion; | |
public EntityMutation(String name, Version version) { | |
this.mName = name; | |
this.mVersion = version; | |
} | |
public EntityMutation rename(String name) { | |
return this; | |
} | |
public EntityMutation entity(String name) { | |
return mVersion.entity(name); | |
} | |
public FieldMutation field(String name) { | |
return new FieldMutation(name, this); | |
} | |
} | |
public class FieldMutation { | |
private String mName; | |
private EntityMutation mEntityMutation; | |
public FieldMutation(String mName, EntityMutation mEntityMutation) { | |
this.mName = mName; | |
this.mEntityMutation = mEntityMutation; | |
} | |
public FieldMutation rename(String name) { | |
// TODO | |
return this; | |
} | |
public FieldMutation retype(String type) { | |
// TODO | |
return this; | |
} | |
public FieldMutation delete() { | |
// TODO | |
return this; | |
} | |
public FieldMutation create() { | |
// TODO | |
return this; | |
} | |
public FieldMutation field(String name) { | |
return mEntityMutation.field(name); | |
} | |
public EntityMutation entity(String name) { | |
return mEntityMutation.entity(name); | |
} | |
} | |
public class Version { | |
private Integer version; | |
private Version(Integer version) { | |
this.version = version; | |
} | |
public Version withScript(String path) { | |
// TODO | |
return this; | |
} | |
public EntityMutation entity(String name) { | |
return new EntityMutation(name, this); | |
} | |
} | |
protected Version mutate() { | |
currentVersion++; | |
return new Version(currentVersion); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment