|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.melati.poem.Database
public abstract class Database
An RDBMS database. Don't instantiate (or subclass) this class, but rather
PoemDatabase
, which includes the boilerplate code for the standard
tables such as user and columninfo which all POEM
databases must contain. If the database is predefined by a Data Structure
Definition Bar.dsd, there will be an application-specialised
subclass of PoemDatabase called BarDatabase which
provides named methods for accessing application-specialised objects
representing the predefined tables.
PoemDatabase
Nested Class Summary | |
---|---|
class |
Database.ConnectingException
Thrown when a request is made whilst the connection to the underlying database is still in progress. |
Constructor Summary | |
---|---|
Database()
Don't subclass this, subclass PoemDatabase. |
Method Summary | |
---|---|
void |
addConstraints()
Add database constraints. |
Table |
addTableAndCommit(TableInfo info,
String troidName)
Add a Table to this Databse and commit the Transaction. |
Capability |
administerCapability()
|
User |
administratorUser()
|
void |
beginExclusiveLock()
Acquire a lock on the database. |
void |
beginSession(AccessToken accessToken)
Start a db session. |
Enumeration<Column> |
columns()
|
void |
connect(String nameIn,
String dbmsclass,
String url,
String username,
String password,
int transactionsMaxP)
Connect to an RDBMS database. |
protected void |
defineTable(Table table)
Don't call this. |
void |
deleteTableAndCommit(TableInfo info)
|
void |
disconnect()
Releases database connections. |
void |
dump()
Print information about the structure of the database to stdout. |
void |
dumpCacheAnalysis()
Print some diagnostic information about the contents and consistency of POEM's cache to stderr. |
void |
endExclusiveLock()
Release lock. |
void |
endSession()
End a db session. |
Capability |
getCanAdminister()
By default, anyone can administer a database. |
abstract CapabilityTable |
getCapabilityTable()
The table of capabilities (required for reading and/or writing records) defined for the database. |
abstract ColumnInfoTable |
getColumnInfoTable()
|
Connection |
getCommittedConnection()
|
Dbms |
getDbms()
|
String |
getDisplayName()
|
Enumeration<Table> |
getDisplayTables()
All the tables in the database in DisplayOrder order, using current transaction if there is one. |
Enumeration<Table> |
getDisplayTables(PoemTransaction transaction)
Currently all the tables in the database in DisplayOrder order. |
int |
getFreeTransactionsCount()
|
abstract GroupCapabilityTable |
getGroupCapabilityTable()
The table containing group-capability records. |
abstract GroupMembershipTable |
getGroupMembershipTable()
A user is a member of a group iff there is a record in this table to say so. |
abstract GroupTable |
getGroupTable()
|
String |
getLastQuery()
|
String |
getName()
|
int |
getQueryCount()
Used in testing to check if the cache is being used or a new query is being issued. |
abstract SettingTable |
getSettingTable()
|
Table |
getTable(String tableName)
Retrieve the table with a given name. |
abstract TableCategoryTable |
getTableCategoryTable()
|
abstract TableInfoTable |
getTableInfoTable()
|
int |
getTransactionsCount()
|
abstract UserTable |
getUserTable()
|
String |
givesCapabilitySQL(User user,
Capability capability)
Get the raw SQL statement for this database's DBMS for Capability check for a User. |
AccessToken |
guestAccessToken()
|
User |
guestUser()
|
boolean |
hasCapability(User user,
Capability capability)
Check if a user has the specified Capability. |
void |
inCommittedTransaction(AccessToken accessToken,
PoemTask task)
Perform a task with the database, but not in an insulated transaction. |
void |
incrementQueryCount(String sql)
Increment query count. |
void |
inSession(AccessToken accessToken,
PoemTask task)
Perform a task with the database. |
void |
inSessionAsRoot(PoemTask task)
|
boolean |
isFree(PoemTransaction trans)
|
boolean |
logCommits()
|
boolean |
logSQL()
|
PoemTransaction |
poemTransaction(int index)
Find a transaction by its index. |
String |
quotedName(String nameIn)
Quote a name in the DBMS' specific dialect. |
protected void |
redefineTable(Table table)
|
Enumeration<Persistent> |
referencesTo(Persistent object)
Find all references to specified object in all tables. |
Enumeration<Column> |
referencesTo(Table tableIn)
|
void |
setCanAdminister()
Set administrator capability to default. |
void |
setCanAdminister(String capabilityName)
Set administrator capability to named Capability. |
void |
setDisplayName(String displayName)
|
void |
setLogCommits(boolean value)
Toggle commit logging. |
void |
setLogSQL(boolean value)
Toggle logging. |
void |
setTransactionsMax(int t)
Set the maximum number of transactions. |
ResultSet |
sqlQuery(String sql)
Run an arbitrary SQL query against the database. |
int |
sqlUpdate(String sql)
Run an arbitrary SQL update against the database. |
Enumeration<Table> |
tables()
All the tables in the database. |
String |
toString()
Returns the connection url. |
Transaction |
transaction(int index)
Get a Transaction by its index. |
int |
transactionsMax()
The number of transactions available for concurrent use on the database. |
void |
trimCache(int maxSize)
Trim POEM's cache to a given size. |
void |
uncache()
Set the contents of the cache to empty. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Database()
PoemDatabase
Method Detail |
---|
public void connect(String nameIn, String dbmsclass, String url, String username, String password, int transactionsMaxP) throws PoemException
dbmsclass
- The Melati DBMS class (see org/melati/poem/dbms)
to use, usually specified in
org.melati.LogicalDatabase.properties.url
- The JDBC URL for the database; for instance
jdbc:postgresql:williamc. It is the
programmer's responsibility to make sure that an
appropriate driver has been loaded.username
- The username under which to establish JDBC connections
to the database. This has nothing to do with the
user/group/capability authentication performed by
Melati.password
- The password to go with the username.transactionsMaxP
- The maximum number of concurrent Transactions allowed,
usually specified in
org.melati.LogicalDatabase.properties.
PoemException
transactionsMax()
public void disconnect() throws PoemException
PoemException
protected void defineTable(Table table) throws DuplicateTableNamePoemException
DuplicateTableNamePoemException
addTableAndCommit(org.melati.poem.TableInfo, java.lang.String)
protected void redefineTable(Table table)
public Table addTableAndCommit(TableInfo info, String troidName) throws PoemException
info
- Table metadata objecttroidName
- name of troidColumn
Table
PoemException
public void deleteTableAndCommit(TableInfo info)
info
- the tableInfo for the table to deletepublic void addConstraints()
public final int transactionsMax()
transactionsMax
in interface TransactionPool
TransactionPool.transactionsMax()
public final void setTransactionsMax(int t)
setTransactionsMax
in interface TransactionPool
t
- maximum number of transactions to setTransactionPool.setTransactionsMax(int)
public int getTransactionsCount()
getTransactionsCount
in interface TransactionPool
TransactionPool.getTransactionsCount()
public int getFreeTransactionsCount()
getFreeTransactionsCount
in interface TransactionPool
TransactionPool.getFreeTransactionsCount()
public PoemTransaction poemTransaction(int index)
transaction(i).index() == i
index
- the index of the Transaction to return
public final Transaction transaction(int index)
Transaction
by its index.
transaction
in interface TransactionPool
index
- the Transaction index to retrieve
TransactionPool.transaction(int)
public boolean isFree(PoemTransaction trans)
trans
- a PoemTransaction
public void beginExclusiveLock()
public void endExclusiveLock()
public void inSession(AccessToken accessToken, PoemTask task)
accessToken
- A token determining the Capabilitys
available to the task, which in turn determine
what data it can attempt to read and write
without triggering an
AccessPoemException. Note that a
User can be an AccessToken.task
- What to do: its run() is invoked, in
the current Java thread; until run()
returns, all POEM accesses made by the thread
are taken to be performed with the capabilities
given by accessToken, and in a private
transaction. No changes made to the database
by other transactions will be visible to it (in the
sense that once it has seen a particular
version of a record, it will always
subsequently see the same one), and its own
changes will not be made permanent until it
completes successfully or performs an explicit
PoemThread.commit(). If it terminates
with an exception or issues a
PoemThread.rollback() its changes will
be lost. (The task is allowed to continue
after either a commit() or a
rollback().)PoemThread
,
PoemThread.commit()
,
PoemThread.rollback()
,
User
public void inSessionAsRoot(PoemTask task)
task
- the task to runpublic void beginSession(AccessToken accessToken)
public void endSession()
This is the very manual way of doing db work - not recommended - use inSession.
public void inCommittedTransaction(AccessToken accessToken, PoemTask task)
A modification will trigger a WriteCommittedException
,
however a create operation will trigger a NullPointerException,
as we have no Transaction.
Not recommended; why exactly do you want to sidestep the Transaction handling?
inSession(org.melati.poem.AccessToken, org.melati.poem.PoemTask)
public final Table getTable(String tableName) throws NoSuchTablePoemException
tableName
- The name of the table to return, as in the RDBMS
database. It's case-sensitive, and some RDBMSs such as
Postgres 6.4.2 (and perhaps other versions) treat upper
case letters in identifiers inconsistently, so the
name is forced to lowercase.
NoSuchTablePoemException
- if no table with the given name exists in the RDBMSpublic final Enumeration<Table> tables()
public Enumeration<Table> getDisplayTables()
public Enumeration<Table> getDisplayTables(PoemTransaction transaction)
public Enumeration<Column> columns()
Column
s in the whole Database
public abstract TableInfoTable getTableInfoTable()
public abstract TableCategoryTable getTableCategoryTable()
public abstract ColumnInfoTable getColumnInfoTable()
public abstract CapabilityTable getCapabilityTable()
Persistent#getCanRead
,
Persistent#getCanWrite
,
Persistent#getCanDelete
,
JdbcTable.getDefaultCanRead()
,
JdbcTable.getDefaultCanWrite()
,
User
,
getUserTable()
,
Group
,
getGroupTable()
public abstract UserTable getUserTable()
public abstract GroupTable getGroupTable()
public abstract GroupMembershipTable getGroupMembershipTable()
public abstract GroupCapabilityTable getGroupCapabilityTable()
public abstract SettingTable getSettingTable()
public ResultSet sqlQuery(String sql) throws SQLPoemException
SQLPoemException
Table.selection()
,
Table.selection(java.lang.String)
,
Column.selectionWhereEq(java.lang.Object)
public int sqlUpdate(String sql) throws SQLPoemException
NOTE This bypasses the access control mechanism. Furthermore, the cache will be left out of sync with the database and must be cleared out (explicitly, manually) after the current transaction has been committed or completed.
INSERT
, UPDATE
or DELETE
statements, or 0
for SQL statements
that return nothing
SQLPoemException
Table.selection()
,
Table.selection(java.lang.String)
,
Column.selectionWhereEq(java.lang.Object)
,
uncache()
public User guestUser()
public User administratorUser()
public String givesCapabilitySQL(User user, Capability capability)
user
- capability
-
public boolean hasCapability(User user, Capability capability)
user
- the User to checkcapability
- the Capability required
public AccessToken guestAccessToken()
public Capability administerCapability()
public Capability getCanAdminister()
Capability
to administer the db
(null unless overridden)public void setCanAdminister()
NOTE Once a database has had its canAdminister capability set there is no mechanism to set it back to null.
public void setCanAdminister(String capabilityName)
capabilityName
- name of Capabilitypublic void trimCache(int maxSize)
maxSize
- The data for all but this many records per table will
be dropped from POEM's cache, on a least-recently-used
basis.public void uncache()
public Enumeration<Persistent> referencesTo(Persistent object)
object
- the object being referred to
Persistent
spublic Enumeration<Column> referencesTo(Table tableIn)
public void dumpCacheAnalysis()
public void dump()
public Dbms getDbms()
public final String quotedName(String nameIn)
nameIn
-
public String toString()
toString
in class Object
Object.toString()
public Connection getCommittedConnection()
public boolean logSQL()
public void setLogSQL(boolean value)
public boolean logCommits()
public void setLogCommits(boolean value)
public int getQueryCount()
public void incrementQueryCount(String sql)
public String getLastQuery()
public String getName()
public String getDisplayName()
public void setDisplayName(String displayName)
displayName
- the displayName to set
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |