Skip to content

Commit

Permalink
coordinator and refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Oct 7, 2012
1 parent bd2ec25 commit 866391c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 97 deletions.
Expand Up @@ -33,6 +33,7 @@ trait ActivateContext

info("Initializing context " + contextName)

ActivateContext.clearContextCaches
EntityHelper.initialize(this.getClass)

private[activate] val liveCache = new LiveCache(this)
Expand Down Expand Up @@ -115,8 +116,11 @@ object ActivateContext {
else
contextCache.getOrElseUpdate(entityClass, context(entityClass))

def clearContextCache =
def clearContextCaches = {
contextCache.clear
Migration.migrationsCache.clear
Migration.storageVersionCache.clear
}

private def context[E <: Entity](entityClass: Class[E]) =
instancesOf[ActivateContext]
Expand Down
Expand Up @@ -43,8 +43,14 @@ object EntityHelper {
initialized = true
}

def getEntityClassFromIdOption(entityId: String) =
if (entityId.length >= 35)
entitiesMetadatas.get(normalizeHex(entityId.substring(37))).map(_.entityClass)
else
None

def getEntityClassFromId(entityId: String) =
entitiesMetadatas(normalizeHex(entityId.substring(37))).entityClass
getEntityClassFromIdOption(entityId).get

def getEntityClassHashId(entityClass: Class[_]): String =
getEntityClassHashId(getEntityName(entityClass))
Expand Down
@@ -1,6 +1,6 @@
package net.fwbrasil.activate.statement

import net.fwbrasil.activate.util.Reflection.newInstance
import net.fwbrasil.activate.util.Reflection._
import net.fwbrasil.activate.util.Reflection.materializeJodaInstant
import net.fwbrasil.activate.util.Reflection.set
import net.fwbrasil.activate.util.Reflection.get
Expand Down Expand Up @@ -127,5 +127,5 @@ object StatementMocks {
}

def mockVar =
newInstance(classOf[FakeVar[_]])
newInstanceUnitialized(classOf[FakeVar[_]])
}
Expand Up @@ -47,11 +47,15 @@ object Reflection {
implicit def toRichClass[T](clazz: Class[T]) = new RichClass(clazz)

def newInstance[T](clazz: Class[T]): T = {
val res = objenesis.newInstance(clazz).asInstanceOf[T]
val res = newInstanceUnitialized(clazz)
initializeBitmaps(res)
res
}

def newInstanceUnitialized[T](clazz: Class[T]): T = {
objenesis.newInstance(clazz).asInstanceOf[T]
}

def getDeclaredFieldsIncludingSuperClasses(concreteClass: Class[_]) = {
var clazz = concreteClass
var fields = List[Field]()
Expand Down
@@ -0,0 +1,5 @@
package net.fwbrasil.activate.play;

public class PlayEntityEnhancer {

}
Expand Up @@ -90,7 +90,7 @@ object oracleContext extends ActivateTestContext {
val jdbcDriver = "oracle.jdbc.driver.OracleDriver"
val user = "ACTIVATE_TEST"
val password = "ACTIVATE_TEST"
val url = "jdbc:oracle:thin:@10.211.55.3:1521:oracle"
val url = "jdbc:oracle:thin:@192.168.1.7:1521:orcl"
val dialect = oracleDialect
}
}
Expand Down
Expand Up @@ -28,97 +28,6 @@ class CreateTables extends Migration {

class SomeEntity(var integer: Int) extends Entity

trait Person extends Entity {
var name: String
def nameAsUpperCase =
name.toUpperCase
}
object Person {
def personsWhereNameStartsWith(string: String) =
select[Person] where (_.name like string + "%")
}
class NaturalPerson(var name: String, var motherName: String) extends Person {
def modifyNameAndMotherName(name: String, motherName: String) = {
this.name = name
this.motherName = motherName
}
}
class LegalPerson(var name: String, var director: NaturalPerson) extends Person

/*
* Tipos de requisi›es
* GET - Transa‹o read-only (se tiver alguma altera‹o vai dar erro)
* POST - Transa‹o n‹o read-only (pode fazer altera›es)
*
* **************
* QUERIES
* (Faz mais sentido usar GET!)
* **************
*
* Obter todas pessoas
* http://fwbrasil.net/myApp/person/all
*
* Pesquisar pessoa por atributo
* http://fwbrasil.net/myApp/person/allWhere?nome=Flavio
*
* Pesquisar pessoa por atributo aninhado
* http://fwbrasil.net/myApp/legalPerson/allWhere?director.name=Flavio
*
* Obter uma pessoa dado ID (poderia usar o allWhere)
* http://fwbrasil.net/myApp/person/c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e
*
* **************
* BEHAVIORS
* (Faz mais sentido usar POST, a n‹o ser que seja um mŽtodo read-only)
* **************
*
* Chamar construtor
* http://fwbrasil.net/myApp/naturalPerson/create?name=Flavio&motherName=Jandira
*
* Chamar um mŽtodo de inst‰ncia
* http://fwbrasil.net/myApp/person/c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e/nameAsUpperCase
*
* Chamar um mŽtodo de inst‰ncia (getter)
* http://fwbrasil.net/myApp/person/c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e/name
*
* Chamar um mŽtodo de inst‰ncia (setter)
* http://fwbrasil.net/myApp/person/c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e/name?value=Novo nome
*
* Chamar um mŽtodo de inst‰ncia (delete)
* http://fwbrasil.net/myApp/person/c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e/delete
*
* Chamar um mŽtodo de inst‰ncia com par‰metro
* http://fwbrasil.net/myApp/person/c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e/modifyNameAndMotherName?name=Novo nome&motherName=Nova mae
*
* Chamar um mŽtodo de classe
* http://fwbrasil.net/myApp/person/personsWhereNameStartsWith?string=Fla
*
* Navegar em mŽtodos (getters)
* http://fwbrasil.net/myApp/legalPerson/c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e/director/name
*
* Navegar em mŽtodos (getter e mŽtodo)
* http://fwbrasil.net/myApp/legalPerson/c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e/director/modifyNameAndMotherName?name=Novo nome&motherName=Nova mae
*
* **************
* OBSERVACOES
* **************
*
* As chamadas que possuem o ID da entidade podem ser feitas sem colocar o tipo no caminho. Por exemplo
* http://fwbrasil.net/myApp/person/c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e/name
* Pode ser chamado como:
* http://fwbrasil.net/myApp/c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e/name
* Essa forma possui um pequeno custo de performance para detectar o tipo baseado no ID
*
*
*
* Se uma entidade possui outra entidade, ser‡ retornado somente o ID! Por exemplo:
* http://fwbrasil.net/myApp/legalPerson/c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e
*
* Vai retornar
* { id: c7970067-a8e3-11e1-803c-0976a061ace5-10c9871e, name: Objective, director: c909019-a8e3-11e1-803c-0976a061ace5-10c9671e
*
*/

case class Runner(entityId: String, numOfVMs: Int, numOfThreads: Int, numOfTransactions: Int) {
def run = {
val tasks =
Expand Down

0 comments on commit 866391c

Please sign in to comment.