Class Model
- java.lang.Object
-
- com.exedio.cope.Model
-
- All Implemented Interfaces:
Serializable
public final class Model extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Model.NotConnectedException
-
Constructor Summary
Constructors Constructor Description Model(int revisionNumber, Type<?>... types)
Deprecated.UseModel(Revisions, Type...)
andRevisions(int)
.Model(Revision[] revisions, Type<?>... types)
Deprecated.Model(Revisions.Factory revisions, Type<?>... types)
Model(Revisions.Factory revisions, TypeSet[] typeSets, Type<?>... types)
Model(RevisionsFuture revisions, Type<?>... types)
Deprecated.UseModel(Revisions.Factory, Type...)
instead.Model(RevisionsFuture revisions, TypeSet[] typeSets, Type<?>... types)
Deprecated.UseModel(Revisions.Factory, TypeSet[], Type...)
instead.Model(Revisions revisions, Type<?>... types)
Deprecated.UseModel(Revisions.Factory, Type...)
orDirectRevisionsFactory
instead.Model(Revisions revisions, TypeSet[] typeSets, Type<?>... types)
Deprecated.UseModel(Revisions.Factory, TypeSet[], Type...)
orDirectRevisionsFactory
instead.Model(Type<?>... types)
-
Method Summary
-
-
-
Constructor Detail
-
Model
public Model(Type<?>... types)
-
Model
@Deprecated public Model(Revisions.Factory revisions, Type<?>... types)
-
Model
@Deprecated public Model(Revisions.Factory revisions, TypeSet[] typeSets, Type<?>... types)
-
Model
@Deprecated public Model(int revisionNumber, Type<?>... types)
Deprecated.UseModel(Revisions, Type...)
andRevisions(int)
.
-
Model
@Deprecated public Model(Revision[] revisions, Type<?>... types)
Deprecated.
-
Model
@Deprecated public Model(Revisions revisions, Type<?>... types)
Deprecated.UseModel(Revisions.Factory, Type...)
orDirectRevisionsFactory
instead.
-
Model
@Deprecated public Model(Revisions revisions, TypeSet[] typeSets, Type<?>... types)
Deprecated.UseModel(Revisions.Factory, TypeSet[], Type...)
orDirectRevisionsFactory
instead.
-
Model
@Deprecated public Model(RevisionsFuture revisions, Type<?>... types)
Deprecated.UseModel(Revisions.Factory, Type...)
instead.
-
Model
@Deprecated public Model(RevisionsFuture revisions, TypeSet[] typeSets, Type<?>... types)
Deprecated.UseModel(Revisions.Factory, TypeSet[], Type...)
instead.
-
-
Method Detail
-
builder
public static ModelBuilder builder()
-
contains
public boolean contains(TypeSet typeSet)
-
containsTypeSet
public boolean containsTypeSet(Type<?>... typeSet)
-
connect
public void connect(ConnectProperties properties)
Connects this model to the database described in the properties.- Throws:
IllegalStateException
- if this model has already been connected.
-
disconnect
public void disconnect()
-
getRevisions
public Revisions getRevisions()
-
revise
public void revise()
-
reviseIfSupportedAndAutoEnabled
public void reviseIfSupportedAndAutoEnabled()
If this method returns successfully, the model's revisions (if any) have been executed. Automatic execution of revisions is controlled by connect property revise.auto.enabled. This method will throw an exception if auto-revisions are not enabled and revisions are pending.
-
getRevisionLogs
public Map<Integer,byte[]> getRevisionLogs()
- See Also:
getRevisionLogsAndMutex()
-
getRevisionLogsAndMutex
public Map<Integer,byte[]> getRevisionLogsAndMutex()
- See Also:
getRevisionLogs()
-
isConnected
public boolean isConnected()
-
getConnectProperties
public ConnectProperties getConnectProperties()
-
getConnectDate
public Date getConnectDate()
-
getType
public Type<?> getType(String id)
Finds a type by itsid
. Returns null, if there is no such type.
-
getFeature
public Feature getFeature(String id)
- See Also:
Feature.getID()
-
getInitializeDate
public Date getInitializeDate()
-
supportsEmptyStrings
public boolean supportsEmptyStrings()
Returns, whether the database can store empty strings.If true, an empty string can be stored into a
StringField
like any other string viaFunctionField.set(Item,Object)
. A subsequent retrieval of that string viaFunctionField.get(Item)
returns an empty string. If false, an empty string stored into aStringField
is converted to null, thus a subsequent retrieval of that string returns null.Up to now, only Oracle does not support empty strings.
-
supportsUTF8mb4
public boolean supportsUTF8mb4()
https://dev.mysql.com/doc/refman/5.6/en/charset-unicode-utf8mb4.html
-
supportsRandom
public boolean supportsRandom()
- See Also:
Random
-
getDatabaseListener
public DatabaseListener getDatabaseListener()
-
setDatabaseListener
public void setDatabaseListener(DatabaseListener listener)
-
createSchema
public void createSchema()
-
createSchemaConstraints
public void createSchemaConstraints(EnumSet<Constraint.Type> types)
-
checkEmptySchema
public void checkEmptySchema()
-
deleteSchema
public void deleteSchema()
- Throws:
IllegalStateException
- is a transaction is bound to the current thread- See Also:
deleteSchemaForTest()
-
deleteSchemaForTest
public void deleteSchemaForTest()
Use for tests only. Does some optimizations for faster execution, that are valid under certain conditions only:- Changes to the database are done via this cope model only. This also means that there is no cluster.
- No transactions running concurrently to
deleteSchemaForTest
connect property
.- Throws:
IllegalStateException
- is a transaction is bound to the current thread- See Also:
deleteSchema()
-
dropSchema
public void dropSchema()
-
dropSchemaConstraints
public void dropSchemaConstraints(EnumSet<Constraint.Type> types)
-
tearDownSchema
public void tearDownSchema()
-
tearDownSchemaConstraints
public void tearDownSchemaConstraints(EnumSet<Constraint.Type> types)
-
getVerifiedSchema
public Schema getVerifiedSchema()
-
getSchema
public Schema getSchema()
-
purgeSchema
public void purgeSchema(JobContext ctx)
Gives this cope model the chance to purge / cleanup whatever it needs to. Should be called once a day.
-
getSchemaSavepoint
public String getSchemaSavepoint() throws SQLException
Returns a string that may help you resetting the schema to the current contents. This may or may not be supported by the database. The meaning of the result heavily depends on the database. Never returns null.- Throws:
SQLException
- if not supported by the database
-
getItem
public Item getItem(String id) throws NoSuchIDException
Returns the item with the given ID. Always returnsactive
objects.- Throws:
NoSuchIDException
- if there is no item with the given id.- See Also:
Item.getCopeID()
-
getThreadControllers
public List<ThreadController> getThreadControllers()
-
getChangeHookString
public String getChangeHookString()
ReturnsObject.toString()
of theChangeHook
registered for this model.
-
getChangeListeners
public List<ChangeListener> getChangeListeners()
- See Also:
addChangeListener(ChangeListener)
-
getChangeListenersInfo
public ChangeListenerInfo getChangeListenersInfo()
-
getChangeListenerDispatcherInfo
public ChangeListenerDispatcherInfo getChangeListenerDispatcherInfo()
-
addChangeListener
public void addChangeListener(ChangeListener listener)
Adds a change listener to the model. The listener is called for eachcommit()
, even on other nodes of the cluster. When the listener is called, there is no transaction present, you may create one if needed. Multiple listeners are called in order of addition.Note, this is something completely different than
commit hooks
.- See Also:
getChangeListeners()
-
removeChangeListener
public void removeChangeListener(ChangeListener listener)
-
removeAllChangeListeners
public void removeAllChangeListeners()
-
getSequenceInfo
public List<SequenceInfo> getSequenceInfo()
-
getItemCacheStatistics
public ItemCacheStatistics getItemCacheStatistics()
-
getQueryCacheInfo
public QueryCacheInfo getQueryCacheInfo()
-
getQueryCacheHistogram
public QueryCacheHistogram[] getQueryCacheHistogram()
-
getConnectionPoolInfo
public Pool.Info getConnectionPoolInfo()
-
flushConnectionPool
public void flushConnectionPool()
-
getEnvironmentInfo
public EnvironmentInfo getEnvironmentInfo()
-
isClusterEnabled
public boolean isClusterEnabled()
-
getClusterProperties
public Properties getClusterProperties()
-
getClusterSenderInfo
public ClusterSenderInfo getClusterSenderInfo()
-
getClusterListenerInfo
public ClusterListenerInfo getClusterListenerInfo()
-
pingClusterNetwork
public void pingClusterNetwork()
-
pingClusterNetwork
public void pingClusterNetwork(int count)
-
startTransaction
public Transaction startTransaction(String name)
- Parameters:
name
- a name for the transaction, useful for debugging. This name is used inTransaction.toString()
.- Throws:
IllegalStateException
- if there is already a transaction bound to the current thread for this model- See Also:
startTransactionTry(String)
-
getNextTransactionId
public long getNextTransactionId()
-
getLastTransactionStartDate
public Date getLastTransactionStartDate()
-
leaveTransaction
public Transaction leaveTransaction()
-
joinTransaction
public void joinTransaction(Transaction tx)
-
hasCurrentTransaction
public boolean hasCurrentTransaction()
-
currentTransaction
public Transaction currentTransaction()
Returns the transaction for this model, that is bound to the currently running thread.- Throws:
IllegalStateException
- if there is no cope transaction bound to current thread- See Also:
Thread.currentThread()
-
rollback
public void rollback()
-
rollbackIfNotCommitted
public void rollbackIfNotCommitted()
-
commit
public void commit()
-
getOpenTransactions
public Collection<Transaction> getOpenTransactions()
Returns the collection of openTransaction
s on this model.Returns an unmodifiable snapshot of the actual data, so iterating over the collection on a live server cannot cause
ConcurrentModificationException
s.
-
addPreCommitHookIfAbsent
@Nonnull public <R extends Runnable> R addPreCommitHookIfAbsent(R hook)
Adds a hook to the current transaction. The hook is called withincommit()
. When the hook is called, the transaction is not yet committed and still available for use. If you don't want this, use apost-commit
hook instead.Multiple hooks are called in order of addition.
If a hook
equal
tohook
has been added before, this method does nothing and returns the hook previously added. Otherwisehook
is returned. Note: this is different fromMap.putIfAbsent
.Note, this is something completely different than
Change Listeners
.- Returns:
- the hook that is present after methods returns.
- See Also:
Transaction.getPreCommitHookCount()
,addPostCommitHookIfAbsent(Runnable)
-
addPostCommitHookIfAbsent
@Nonnull public <R extends Runnable> R addPostCommitHookIfAbsent(R hook)
Adds a hook to the current transaction. The hook is called withincommit()
. When the hook is called, the transaction is already committed and not available for use anymore. If you don't want this, use apre-commit
hook instead.Multiple hooks are called in order of addition.
If a hook
equal
tohook
has been added before, this method does nothing and returns the hook previously added. Otherwisehook
is returned. Note: this is different fromMap.putIfAbsent
.Note, this is something completely different than
Change Listeners
.- Returns:
- the hook that is present after methods returns.
- See Also:
Transaction.getPostCommitHookCount()
,addPreCommitHookIfAbsent(Runnable)
-
startTransactionTry
public TransactionTry startTransactionTry(String name)
- See Also:
startTransaction(String)
-
getTransactionCounters
public TransactionCounters getTransactionCounters()
-
clearCache
public void clearCache()
-
checkTypeColumns
public void checkTypeColumns()
- See Also:
ItemFunction.checkTypeColumn()
-
checkUnsupportedConstraints
public void checkUnsupportedConstraints()
-
isSerializationEnabled
public boolean isSerializationEnabled()
-
getItemCacheInfo
@Deprecated public ItemCacheInfo[] getItemCacheInfo()
Deprecated.
-
addPostCommitHook
@Deprecated public void addPostCommitHook(Runnable hook)
Deprecated.UseaddPostCommitHookIfAbsent(Runnable)
instead
-
addCommitHook
@Deprecated public void addCommitHook(Runnable hook)
Deprecated.UseaddPostCommitHookIfAbsent(Runnable)
instead
-
isClusterNetworkEnabled
@Deprecated public boolean isClusterNetworkEnabled()
Deprecated.UseisClusterEnabled()
instead
-
getHiddenFeatures
@Deprecated public Map<Feature,Feature> getHiddenFeatures()
Deprecated.UseHiddenFeatures.get(Model)
instead.
-
reviseIfSupported
@Deprecated public void reviseIfSupported()
Deprecated.usereviseIfSupportedAndAutoEnabled()
instead
-
nullsAreSortedLow
@Deprecated public boolean nullsAreSortedLow()
Deprecated.Is not supported any longer. Always returns true.
-
startTransaction
@Deprecated public Transaction startTransaction()
Deprecated.UsestartTransaction(String)
instead and provide a useful name.
-
getModificationListeners
@Deprecated public List<ModificationListener> getModificationListeners()
Deprecated.ModificationListener is no longer supported. Always returns an empty list.
-
getModificationListenersCleared
@Deprecated public int getModificationListenersCleared()
Deprecated.ModificationListener is no longer supported. Always returns zero.
-
addModificationListener
@Deprecated public void addModificationListener(ModificationListener listener)
Deprecated.ModificationListener is no longer supported. Always throws aNoSuchMethodError
.
-
removeModificationListener
@Deprecated public void removeModificationListener(ModificationListener listener)
Deprecated.ModificationListener is no longer supported.
-
getCacheInfo
@Deprecated public ItemCacheInfo[] getCacheInfo()
Deprecated.renamed togetItemCacheInfo()
.
-
getCacheQueryHistogram
@Deprecated public QueryCacheHistogram[] getCacheQueryHistogram()
Deprecated.renamed togetQueryCacheHistogram()
.
-
getCacheQueryInfo
@Deprecated public QueryCacheInfo getCacheQueryInfo()
Deprecated.renamed togetQueryCacheInfo()
.
-
migrate
@Deprecated public void migrate()
Deprecated.Userevise()
instead
-
migrateIfSupported
@Deprecated public void migrateIfSupported()
Deprecated.UsereviseIfSupportedAndAutoEnabled()
instead
-
getMigrationLogs
@Deprecated public Map<Integer,byte[]> getMigrationLogs()
Deprecated.UsegetRevisionLogs()
instead
-
getModificationListenersRemoved
@Deprecated public int getModificationListenersRemoved()
Deprecated.UsegetModificationListenersCleared()
instead
-
setPropertiesInitially
@Deprecated public void setPropertiesInitially(ConnectProperties properties)
Deprecated.renamed toconnect(ConnectProperties)
.
-
findByID
@Deprecated public Item findByID(String id) throws NoSuchIDException
Deprecated.UsegetItem(String)
instead- Throws:
NoSuchIDException
-
findTypeByID
@Deprecated public Type<?> findTypeByID(String id)
Deprecated.UsegetType(String)
instead
-
findFeatureByID
@Deprecated public Feature findFeatureByID(String id)
Deprecated.UsegetFeature(String)
instead
-
createDatabase
@Deprecated public void createDatabase()
Deprecated.UsecreateSchema()
instead
-
createDatabaseConstraints
@Deprecated public void createDatabaseConstraints(EnumSet<Constraint.Type> types)
Deprecated.UsecreateSchemaConstraints(EnumSet)
instead
-
checkSchema
@Deprecated public void checkSchema()
Deprecated.This functionality is no longer supported. This method does nothing.Checks the schema, whether the tables representing the types do exist.
-
checkDatabase
@Deprecated public void checkDatabase()
Deprecated.UsecheckSchema()
instead
-
checkEmptyDatabase
@Deprecated public void checkEmptyDatabase()
Deprecated.UsecheckEmptySchema()
instead
-
dropDatabase
@Deprecated public void dropDatabase()
Deprecated.UsedropSchema()
instead
-
dropDatabaseConstraints
@Deprecated public void dropDatabaseConstraints(EnumSet<Constraint.Type> types)
Deprecated.UsedropSchemaConstraints(EnumSet)
instead
-
tearDownDatabase
@Deprecated public void tearDownDatabase()
Deprecated.UsetearDownSchema()
instead
-
tearDownDatabaseConstraints
@Deprecated public void tearDownDatabaseConstraints(EnumSet<Constraint.Type> types)
Deprecated.UsetearDownSchemaConstraints(EnumSet)
instead
-
flushSequences
@Deprecated public void flushSequences()
Deprecated.Not supported anymore. This method does nothing.
-
getProperties
@Deprecated public ConnectProperties getProperties()
Deprecated.UsegetConnectProperties()
instead
-
getDatabaseInfo
@Deprecated public Properties getDatabaseInfo()
Deprecated.UsegetEnvironmentInfo()
andEnvironmentInfo.asProperties()
instead.
-
getCurrentTransaction
@Deprecated public Transaction getCurrentTransaction()
Deprecated.UsecurrentTransaction()
instead
-
supportsCheckConstraints
@Deprecated public boolean supportsCheckConstraints()
Deprecated.UseSchemaInfo.supportsCheckConstraints(Model)
instead
-
supportsSequences
@Deprecated public boolean supportsSequences()
Deprecated.UseSchemaInfo.supportsSequences(Model)
instead
-
isLoggingEnabled
@Deprecated public static boolean isLoggingEnabled()
Deprecated.UseConnectProperties.isLoggingEnabled()
instead, always returns false.
-
getChangeListenersCleared
@Deprecated public int getChangeListenersCleared()
Deprecated.usegetChangeListenersInfo()
.ChangeListenerInfo.getCleared()
instead.
-
-