org.slim3.datastore
Class ModelRef<M>

java.lang.Object
  extended by org.slim3.datastore.AbstractModelRef<M>
      extended by org.slim3.datastore.ModelRef<M>
Type Parameters:
M - the model type
All Implemented Interfaces:
Serializable

public class ModelRef<M>
extends AbstractModelRef<M>

A reference for model like ReferenceProperty of Python.

Since:
1.0.0
Author:
higa
See Also:
Serialized Form

Field Summary
protected  Key key
          The key.
protected  M model
          The model.
 
Fields inherited from class org.slim3.datastore.AbstractModelRef
modelClass, modelClassName, modelMeta
 
Constructor Summary
protected ModelRef()
          Constructor.
  ModelRef(Class<M> modelClass)
          Constructor.
 
Method Summary
 Key assignKeyIfNecessary(AsyncDatastoreService ds)
          Assigns a new key to the model if necessary.
 void clear()
          Clears the state of this ModelRef.
 boolean equals(Object obj)
           
 Key getKey()
          Returns the key.
 M getModel()
          Returns the model.
 int hashCode()
           
 M refresh()
          Refreshes the model.
 void setKey(Key key)
          Sets the key.
 void setModel(M model)
          Sets the model.
 
Methods inherited from class org.slim3.datastore.AbstractModelRef
getModelClass, getModelMeta, setModelClass, setModelMeta
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected M model
The model.


key

protected Key key
The key.

Constructor Detail

ModelRef

protected ModelRef()
Constructor.


ModelRef

public ModelRef(Class<M> modelClass)
         throws NullPointerException
Constructor.

Parameters:
modelClass - the model class
Throws:
NullPointerException - if the modelClass parameter is null
Method Detail

getModel

public M getModel()
Returns the model.

Returns:
the model

setModel

public void setModel(M model)
              throws IllegalArgumentException
Sets the model.

Parameters:
model - the model
Throws:
IllegalArgumentException - if the model is null or if the model does not have a primary key or if the kind of the key is different from the kind of ModelMeta

getKey

public Key getKey()
Returns the key.

Returns:
the key

setKey

public void setKey(Key key)
            throws IllegalStateException,
                   IllegalArgumentException
Sets the key.

Parameters:
key - the key
Throws:
IllegalStateException - if the model is set
IllegalArgumentException - if the kind of the key is different from the kind of ModelMeta

refresh

public M refresh()
Refreshes the model.

Returns:
a refreshed model

clear

public void clear()
Clears the state of this ModelRef.


hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

assignKeyIfNecessary

public Key assignKeyIfNecessary(AsyncDatastoreService ds)
                         throws NullPointerException
Assigns a new key to the model if necessary.

Parameters:
ds - the asynchronous datastore service
Returns:
a key
Throws:
NullPointerException - if the ds parameter is null


Copyright © 2009-2010 The Slim3 project. All Rights Reserved.