Package ru.curs.celesta.score
Class Grain
- java.lang.Object
-
- ru.curs.celesta.score.NamedElement
-
- ru.curs.celesta.score.Grain
-
public final class Grain extends NamedElement
Grain.
-
-
Field Summary
-
Fields inherited from class ru.curs.celesta.score.NamedElement
MAX_IDENTIFIER_LENGTH
-
-
Constructor Summary
Constructors Constructor Description Grain(AbstractScore score, String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addIndex(Index index)
Adds an index.void
finalizeParsing()
Indicates that the grain parsing is completed.List<NativeSqlElement>
getAfterSqlList(DBType dbType)
List<NativeSqlElement>
getBeforeSqlList(DBType dbType)
int
getChecksum()
Returns checksum of the script file that the grain was created from.int
getDependencyOrder()
If a grain has a higher number than the other grain then it means that it can depend from the first one.<T extends GrainElement>
TgetElement(String name, Class<T> classOfElement)
Returns an element by its name and class or throws an exception with the message that element is not found.<T extends GrainElement>
Map<String,T>getElements(Class<T> classOfElement)
Returns a set of elements of specified type defined in the grain.Set<GrainPart>
getGrainParts()
Returns grain parts that this grain consists of.Map<String,Index>
getIndices()
Returns a set of indices defined in the grain.int
getLength()
Returns length of the script file that the grain was created from.MaterializedView
getMaterializedView(String name)
Returns a materialized view by its name or an exception with a message that the view was not found.Map<String,MaterializedView>
getMaterializedViews()
Returns a set of materialized views defined in the grain.Namespace
getNamespace()
Returns namespace of the grain.ParameterizedView
getParameterizedView(String name)
Returns a parameterized view by its name or an exception with a message that the view was not found.Map<String,ParameterizedView>
getParameterizedViews()
Returns a set of parameterized views defined in the grain.AbstractScore
getScore()
Returns model that the grain belongs to.BasicTable
getTable(String name)
Returns a table by its name or an exception with a message that the table was not found.<T extends BasicTable>
TgetTable(String name, Class<T> tableClass)
Returns a table by its name and a table class.Map<String,BasicTable>
getTables()
Returns a set of tables defined in the grain.<T extends BasicTable>
Map<String,T>getTables(Class<T> tableClass)
Returns a set of tables defined in the grain by a table class.VersionString
getVersion()
Returns the grain version.View
getView(String name)
Returns a view by its name or an exception with a message that the view was not found.Map<String,View>
getViews()
Returns a set of views defined in the grain.boolean
isAutoupdate()
Valuefalse
indicates that grain was created with option WITH NO AUTOUPDATE, and won't be updated.boolean
isModified()
Returns a flag of grain modification (true
if parts of grain were modified in the runtime).boolean
isParsingComplete()
Indicates that the grain parsing from file is completed.void
setAutoupdate(boolean autoupdate)
Sets autoupdate option.void
setNamespace(Namespace namespace)
Sets namespace of the grain.void
setVersion(String version)
Sets the grain version.-
Methods inherited from class ru.curs.celesta.score.NamedElement
equals, getCelestaDoc, getName, getQuotedName, getQuotedNameIfNeeded, hashCode, limitName, limitName, setCelestaDoc
-
-
-
-
Constructor Detail
-
Grain
public Grain(AbstractScore score, String name) throws ParseException
- Throws:
ParseException
-
-
Method Detail
-
getElements
public <T extends GrainElement> Map<String,T> getElements(Class<T> classOfElement)
Returns a set of elements of specified type defined in the grain.- Type Parameters:
T
- class of element- Parameters:
classOfElement
- class of elements from the set
-
getMaterializedViews
public Map<String,MaterializedView> getMaterializedViews()
Returns a set of materialized views defined in the grain.
-
getParameterizedViews
public Map<String,ParameterizedView> getParameterizedViews()
Returns a set of parameterized views defined in the grain.
-
getTables
public Map<String,BasicTable> getTables()
Returns a set of tables defined in the grain.
-
getTables
public <T extends BasicTable> Map<String,T> getTables(Class<T> tableClass)
Returns a set of tables defined in the grain by a table class.- Type Parameters:
T
- table type (e.g. Table or ReadOnlyTable)- Parameters:
tableClass
- Table class
-
getElement
public <T extends GrainElement> T getElement(String name, Class<T> classOfElement) throws ParseException
Returns an element by its name and class or throws an exception with the message that element is not found.- Type Parameters:
T
- class of element- Parameters:
name
- element nameclassOfElement
- element class- Throws:
ParseException
- if element with such name and class is not found in the grain
-
addIndex
public void addIndex(Index index) throws ParseException
Adds an index.- Parameters:
index
- new index of the grain.- Throws:
ParseException
- In case if an index with the same name already exists.
-
getScore
public AbstractScore getScore()
Returns model that the grain belongs to.
-
isAutoupdate
public boolean isAutoupdate()
Valuefalse
indicates that grain was created with option WITH NO AUTOUPDATE, and won't be updated. Default value istrue
.
-
setAutoupdate
public void setAutoupdate(boolean autoupdate)
Sets autoupdate option. Default value istrue
.- Parameters:
autoupdate
- autoupdate flag
-
getVersion
public VersionString getVersion()
Returns the grain version.
-
setVersion
public void setVersion(String version) throws ParseException
Sets the grain version.- Parameters:
version
- Quoted-string. In course of processing single and double quotes are removed.- Throws:
ParseException
- in case if format of quoted string is incorrect.
-
getLength
public int getLength()
Returns length of the script file that the grain was created from.
-
getChecksum
public int getChecksum()
Returns checksum of the script file that the grain was created from. Coincidence of version, length and checksum is considered to be a sufficient solution for skipping the reading and update of the database structure.
-
isParsingComplete
public boolean isParsingComplete()
Indicates that the grain parsing from file is completed.
-
getDependencyOrder
public int getDependencyOrder()
If a grain has a higher number than the other grain then it means that it can depend from the first one.
-
finalizeParsing
public void finalizeParsing() throws ParseException
Indicates that the grain parsing is completed. A system method.- Throws:
ParseException
- thrown when there are tables with illegal names.
-
isModified
public boolean isModified()
Returns a flag of grain modification (true
if parts of grain were modified in the runtime).
-
getView
public View getView(String name) throws ParseException
Returns a view by its name or an exception with a message that the view was not found.- Parameters:
name
- View name- Throws:
ParseException
- If view with that name was not found in the grain.
-
getMaterializedView
public MaterializedView getMaterializedView(String name) throws ParseException
Returns a materialized view by its name or an exception with a message that the view was not found.- Parameters:
name
- Materialized view name- Throws:
ParseException
- If materialized view with that name was not found in the grain.
-
getParameterizedView
public ParameterizedView getParameterizedView(String name) throws ParseException
Returns a parameterized view by its name or an exception with a message that the view was not found.- Parameters:
name
- Parameterized view name- Throws:
ParseException
- If parameterized view with that name was not found in the grain.
-
getTable
public BasicTable getTable(String name) throws ParseException
Returns a table by its name or an exception with a message that the table was not found.- Parameters:
name
- Table name- Throws:
ParseException
- If table with that name was not found in the grain.
-
getTable
public <T extends BasicTable> T getTable(String name, Class<T> tableClass) throws ParseException
Returns a table by its name and a table class.- Type Parameters:
T
- table type (e.g. Table or ReadOnlyTable)- Parameters:
name
- Table nametableClass
- Table class- Throws:
ParseException
- If table with that name was not found in the grain.
-
getBeforeSqlList
public List<NativeSqlElement> getBeforeSqlList(DBType dbType)
-
getAfterSqlList
public List<NativeSqlElement> getAfterSqlList(DBType dbType)
-
getGrainParts
public Set<GrainPart> getGrainParts()
Returns grain parts that this grain consists of.
-
getNamespace
public Namespace getNamespace()
Returns namespace of the grain.
-
setNamespace
public void setNamespace(Namespace namespace)
Sets namespace of the grain.- Parameters:
namespace
- namespace
-
-