net.loadbang.sql.mxj
Class MXJ_SQL

java.lang.Object
  extended by com.cycling74.max.MaxObject
      extended by net.loadbang.util.EnrichedMaxObject
          extended by net.loadbang.sql.mxj.MXJ_SQL
Direct Known Subclasses:
MySQL, NoddySQL

public abstract class MXJ_SQL
extends net.loadbang.util.EnrichedMaxObject

A superclass for MXJ objects which connect to databases.

Every instance of this object maintains its own database connection (via the embedded Database object); there's no complicated connection pooling (and no real need for it).

I don't know how a DB will react to scheduler-priority threads, but we synchronise access to the connection inside the connector to avoid interference between scheduler and GUI threads.

Author:
Nick Rothwell, nick@cassiel.com / nick@loadbang.net

Field Summary
 
Fields inherited from class com.cycling74.max.MaxObject
EMPTY_STRING_ARRAY, NO_INLETS, NO_OUTLETS
 
Constructor Summary
protected MXJ_SQL(java.lang.Class loggerOwnerClass)
          Constructor.
 
Method Summary
protected  void dropDatabase()
          Drop the database connection (closing it).
protected  Database getDatabase()
          Return database connection, or fail.
 void notifyDeleted()
          On object deletion, close the database connection.
 void query(com.cycling74.max.Atom[] sqlTokens)
          Run an SQL query.
protected  void setDatabase(Database database)
          Set the database, having attempted to open it.
 void update(com.cycling74.max.Atom[] sqlTokens)
          Run an update, and output the number of changed rows (as a message "update <N>").
 
Methods inherited from class net.loadbang.util.EnrichedMaxObject
getLogger
 
Methods inherited from class com.cycling74.max.MaxObject
anything, bail, bang, createInfoOutlet, dblclick, declareAttribute, declareAttribute, declareInlets, declareIO, declareOutlets, declareReadOnlyAttribute, declareReadOnlyAttribute, declareTypedIO, embedMessage, error, gc, getAttr, getAttrAtomArray, getAttrBool, getAttrBoolArray, getAttrByte, getAttrByteArray, getAttrChar, getAttrCharArray, getAttrDouble, getAttrDoubleArray, getAttrFloat, getAttrFloatArray, getAttributeInfo, getAttrInt, getAttrIntArray, getAttrLongArray, getAttrShort, getAttrShortArray, getAttrString, getAttrStringArray, getCodeSourcePath, getContext, getErrorStream, getInfoIdx, getInlet, getInletAssist, getInletType, getLongAttr, getMaxBox, getName, getNumInlets, getNumOutlets, getOutletAssist, getOutletType, getParentPatcher, getPostStream, inlet, inlet, list, loadbang, ouch, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outlet, outletBang, outletBangHigh, outletHigh, outletHigh, outletHigh, outletHigh, outletHigh, outletHigh, outletHigh, outletHigh, outletHigh, outletHigh, post, postCodePath, save, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setAttr, setInletAssist, setInletAssist, setName, setOutletAssist, setOutletAssist, showException, showException, toString, viewsource, zap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MXJ_SQL

protected MXJ_SQL(java.lang.Class loggerOwnerClass)
Constructor. Passes the final class name to Log4j. We also set up the inlets, outlets and assists here (since they should be identical regardless of database).

Method Detail

setDatabase

protected void setDatabase(Database database)
                    throws SetupException
Set the database, having attempted to open it.

Throws:
SetupException

getDatabase

protected Database getDatabase()
                        throws OperationException
Return database connection, or fail.

Throws:
OperationException

dropDatabase

protected void dropDatabase()
Drop the database connection (closing it).


notifyDeleted

public void notifyDeleted()
On object deletion, close the database connection.

Overrides:
notifyDeleted in class com.cycling74.max.MaxObject

update

public void update(com.cycling74.max.Atom[] sqlTokens)
Run an update, and output the number of changed rows (as a message "update <N>"). The output only occurs if the update succeeds.

The database object's query and update methods are synchronised, so be careful when using loops in patchers and don't mix thread priorities.

Parameters:
sqlTokens - a list of tokens representing an SQL update statement

query

public void query(com.cycling74.max.Atom[] sqlTokens)
Run an SQL query. Output the result rows as lists of atoms. We don't try to be very clever about tokenising.

Parameters:
sqlTokens - a list of tokens representing an SQL statement (a query or an update).