Java Doc for IDBroker.java in  » Database-ORM » Torque » org » apache » torque » oid » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » Torque » org.apache.torque.oid 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.torque.oid.IDBroker

IDBroker
public class IDBroker implements Runnable,IdGenerator(Code)
This method of ID generation is used to ensure that code is more database independent. For example, MySQL has an auto-increment feature while Oracle uses sequences. It caches several ids to avoid needing a Connection for every request. This class uses the table ID_TABLE defined in conf/master/id-table-schema.xml. The columns in ID_TABLE are used as follows:
ID_TABLE_ID - The PK for this row (any unique int).
TABLE_NAME - The name of the table you want ids for.
NEXT_ID - The next id returned by IDBroker when it queries the database (not when it returns an id from memory).
QUANTITY - The number of ids that IDBroker will cache in memory.

Use this class like this:

 int id = dbMap.getIDBroker().getNextIdAsInt(null, "TABLE_NAME");
 - or -
 BigDecimal[] ids = ((IDBroker)dbMap.getIDBroker())
 .getNextIds("TABLE_NAME", numOfIdsToReturn);
 
NOTE: When the ID_TABLE must be updated we must ensure that IDBroker objects running in different JVMs do not overwrite each other. This is accomplished using using the transactional support occuring in some databases. Using this class with a database that does not support transactions should be limited to a single JVM.
author:
   Frank Y. Kim
author:
   John D. McNally
author:
   Henning P. Schmiedehausen
version:
   $Id: IDBroker.java 552333 2007-07-01 16:24:19Z tv $


Field Summary
final public static  StringCOL_NEXT_ID
    
final public static  StringCOL_QUANTITY
    
final public static  StringCOL_TABLE_ID
    
final public static  StringCOL_TABLE_NAME
    
final public static  StringID_TABLE
    
final public static  StringNEXT_ID
    
final public static  StringQUANTITY
    
final public static  StringTABLE_ID
    
final public static  StringTABLE_NAME
    

Constructor Summary
public  IDBroker(Database database)
     constructs an IdBroker for the given Database.
public  IDBroker(TableMap tMap)
     Creates an IDBroker for the ID table.

Method Summary
public  booleanexists(String tableName)
    
public  BigDecimalgetIdAsBigDecimal(Connection connection, Object tableName)
     Returns an id as a BigDecimal.
public  intgetIdAsInt(Connection connection, Object tableName)
     Returns an id as a primitive int.
public  longgetIdAsLong(Connection connection, Object tableName)
     Returns an id as a primitive long.
public  StringgetIdAsString(Connection connection, Object tableName)
     Returns an id as a String.
public synchronized  BigDecimal[]getNextIds(String tableName, int numOfIdsToReturn)
     This method returns x number of ids for the given table.
Parameters:
  tableName - The name of the table for which we want an id.
Parameters:
  numOfIdsToReturn - The desired number of ids.
public synchronized  BigDecimal[]getNextIds(String tableName, int numOfIdsToReturn, Connection connection)
     This method returns x number of ids for the given table. Note this method does not require a Connection. If a Connection is needed one will be requested. To force the use of the passed in connection set the configuration property torque.idbroker.usenewconnection = false
Parameters:
  tableName - The name of the table for which we want an id.
Parameters:
  numOfIdsToReturn - The desired number of ids.
Parameters:
  connection - A Connection.
public  booleanisConnectionRequired()
     A flag to determine whether a Connection is required to generate an id.
public  booleanisPostInsert()
    
public  booleanisPriorToInsert()
    
public  voidrun()
     A background thread that tries to ensure that when someone asks for ids, that there are already some loaded and that the database is not accessed.
public  voidsetConfiguration(Configuration configuration)
    
public  voidstop()
     Shuts down the IDBroker thread. Calling this method stops the thread that was started for this instance of the IDBroker.

Field Detail
COL_NEXT_ID
final public static String COL_NEXT_ID(Code)
Next_ID column name



COL_QUANTITY
final public static String COL_QUANTITY(Code)
Quantity column name



COL_TABLE_ID
final public static String COL_TABLE_ID(Code)
ID column name



COL_TABLE_NAME
final public static String COL_TABLE_NAME(Code)
Table_Name column name



ID_TABLE
final public static String ID_TABLE(Code)
Name of the ID_TABLE = ID_TABLE



NEXT_ID
final public static String NEXT_ID(Code)
Fully qualified Next_ID column name



QUANTITY
final public static String QUANTITY(Code)
Fully qualified Quantity column name



TABLE_ID
final public static String TABLE_ID(Code)
Fully qualified ID column name



TABLE_NAME
final public static String TABLE_NAME(Code)
Fully qualified Table_Name column name




Constructor Detail
IDBroker
public IDBroker(Database database)(Code)
constructs an IdBroker for the given Database.
Parameters:
  database - the database where this IdBroker is running in.



IDBroker
public IDBroker(TableMap tMap)(Code)
Creates an IDBroker for the ID table.
Parameters:
  tMap - A TableMap.




Method Detail
exists
public boolean exists(String tableName) throws Exception(Code)

Parameters:
  tableName - a String value that is used to identifythe row a boolean value
exception:
  TorqueException - if a Torque error occurs.
exception:
  Exception - if another error occurs.



getIdAsBigDecimal
public BigDecimal getIdAsBigDecimal(Connection connection, Object tableName) throws Exception(Code)
Returns an id as a BigDecimal. Note this method does not require a Connection, it just implements the KeyGenerator interface. if a Connection is needed one will be requested. To force the use of the passed in connection set the configuration property torque.idbroker.usenewconnection = false
Parameters:
  connection - A Connection.
Parameters:
  tableName - a String that identifies a table.. A BigDecimal id.
exception:
  Exception - Database error.



getIdAsInt
public int getIdAsInt(Connection connection, Object tableName) throws Exception(Code)
Returns an id as a primitive int. Note this method does not require a Connection, it just implements the KeyGenerator interface. if a Connection is needed one will be requested. To force the use of the passed in connection set the configuration property torque.idbroker.usenewconnection = false
Parameters:
  connection - A Connection.
Parameters:
  tableName - an Object that contains additional info. An int with the value for the id.
exception:
  Exception - Database error.



getIdAsLong
public long getIdAsLong(Connection connection, Object tableName) throws Exception(Code)
Returns an id as a primitive long. Note this method does not require a Connection, it just implements the KeyGenerator interface. if a Connection is needed one will be requested. To force the use of the passed in connection set the configuration property torque.idbroker.usenewconnection = false
Parameters:
  connection - A Connection.
Parameters:
  tableName - a String that identifies a table. A long with the value for the id.
exception:
  Exception - Database error.



getIdAsString
public String getIdAsString(Connection connection, Object tableName) throws Exception(Code)
Returns an id as a String. Note this method does not require a Connection, it just implements the KeyGenerator interface. if a Connection is needed one will be requested. To force the use of the passed in connection set the configuration property torque.idbroker.usenewconnection = false
Parameters:
  connection - A Connection should be null.
Parameters:
  tableName - a String that identifies a table. A String id
exception:
  Exception - Database error.



getNextIds
public synchronized BigDecimal[] getNextIds(String tableName, int numOfIdsToReturn) throws Exception(Code)
This method returns x number of ids for the given table.
Parameters:
  tableName - The name of the table for which we want an id.
Parameters:
  numOfIdsToReturn - The desired number of ids. A BigDecimal.
exception:
  Exception - Database error.



getNextIds
public synchronized BigDecimal[] getNextIds(String tableName, int numOfIdsToReturn, Connection connection) throws Exception(Code)
This method returns x number of ids for the given table. Note this method does not require a Connection. If a Connection is needed one will be requested. To force the use of the passed in connection set the configuration property torque.idbroker.usenewconnection = false
Parameters:
  tableName - The name of the table for which we want an id.
Parameters:
  numOfIdsToReturn - The desired number of ids.
Parameters:
  connection - A Connection. A BigDecimal.
exception:
  Exception - Database error.



isConnectionRequired
public boolean isConnectionRequired()(Code)
A flag to determine whether a Connection is required to generate an id. a boolean value



isPostInsert
public boolean isPostInsert()(Code)
A flag to determine the timing of the id generation a boolean value



isPriorToInsert
public boolean isPriorToInsert()(Code)
A flag to determine the timing of the id generation * a boolean value



run
public void run()(Code)
A background thread that tries to ensure that when someone asks for ids, that there are already some loaded and that the database is not accessed.



setConfiguration
public void setConfiguration(Configuration configuration)(Code)
Set the configuration
Parameters:
  configuration - the configuration



stop
public void stop()(Code)
Shuts down the IDBroker thread. Calling this method stops the thread that was started for this instance of the IDBroker. This method should be called during MapBroker Service shutdown.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.