org.csstudio.platform.utility.rdb
Class StringIDHelper

java.lang.Object
  extended by org.csstudio.platform.utility.rdb.StringIDHelper
Direct Known Subclasses:
CachingStringIDHelper

public class StringIDHelper
extends java.lang.Object

Helper for StringID entries in RDB.

The find... calls keep the prepared statement open for re-use.

Author:
Kay Kasemir, Laurent Philippe Switch connection to readonly to MySQL load balancing, Lana Abadie - Readonly change not possible for PostgreSQL. Disable autocommit as needed.

Constructor Summary
StringIDHelper(RDBUtil rdb, java.lang.String table, java.lang.String id_column, java.lang.String name_column)
          Construct helper
 
Method Summary
 StringID add(java.lang.String name)
          Add new name, unless it's already in the RDB.
 void dispose()
          Must be called for cleanup when no longer needed
 StringID find(int id)
          Locate StringID by ID
 StringID find(java.lang.String name)
          Locate StringID by name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringIDHelper

public StringIDHelper(RDBUtil rdb,
                      java.lang.String table,
                      java.lang.String id_column,
                      java.lang.String name_column)
Construct helper

Parameters:
rdb - RDBUTil
table - Name of RDB table
id_column - Name of the ID column
name_column - Name of the Name column
Method Detail

dispose

public void dispose()
Must be called for cleanup when no longer needed


find

public StringID find(java.lang.String name)
              throws java.lang.Exception
Locate StringID by name

Parameters:
name - Name to locate
Returns:
StringID or null if nothing found
Throws:
java.lang.Exception - on error

find

public StringID find(int id)
              throws java.lang.Exception
Locate StringID by ID

Parameters:
id - ID to locate
Returns:
StringID or null if nothing found
Throws:
java.lang.Exception - on error

add

public StringID add(java.lang.String name)
             throws java.lang.Exception
Add new name, unless it's already in the RDB.

Parameters:
name - Name to add
Returns:
StringID found or generated
Throws:
java.lang.Exception - on error