Welcome Guest  |  Register  |  Login
Login Name Password
  Search  
  Index  | Recent Threads  | Unanswered Threads  | Who's Online  | Help


Quick Go »

No member browsing this thread
Thread Status: Active
Total posts in this thread: 4
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 1775 times and has 3 replies Next Thread
Male jfrantzius
Advanced Member
Member's Avatar

Germany
Joined: Jun 18, 2004
Post Count: 385
Status: Offline
Reply to this Post  Reply with Quote 
"Standalone ID generation" docs out of date

Hi,

in the docs about Standalone ID generation, a method PoidManager.setConnection() is used, but that doesn't exist. Probably setJdbcConnectionProvider() is the one to be used?

URL: http://www.jpox.org/docs/1_1/identity_generation.html (at bottom)

Cheers,
J�rg.
[May 2, 2005 1:42:49 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male jfrantzius
Advanced Member
Member's Avatar

Germany
Joined: Jun 18, 2004
Post Count: 385
Status: Offline
Reply to this Post  Reply with Quote 
Re: "Standalone ID generation" docs out of date

As example code, I'd propose the following, which seems to work:
PersistenceManagerImpl pm = (PersistenceManagerImpl) ... // cast your pm to impl ;
// Obtain a PoidManager
PoidManager poidManager = new PoidManager();
poidManager.setStoreManager((RDBMSManager) pm.getStoreManager());
Properties properties = new Properties();
// use a global sequence number, i.e. for all tables
properties.setProperty("table-name", "GLOBAL");
poidManager.setProperties(properties);
poidManager.setPoidGeneratorName("org.jpox.poid.SequenceTablePoidGenerator");
poidManager.setJDBCConnectionProvider(new PoidJDBCConnectionProvider() {
RDBMSManager rdbmsManager = null;
Connection con;
public Connection getPoidJDBCConnection() {
rdbmsManager = (RDBMSManager) pm.getStoreManager();
try {
// important to use TRANSACTION_NONE like JPOX does
con = (Connection)rdbmsManager.getConnection(Connection.TRANSACTION_NONE);;
return con;
} catch (SQLException e) {
logger.error("Failed to obtain new DB connection for identity generation!");
throw new RuntimeException(e);
}
}
public void releaseConnection() {
try {
rdbmsManager.closeConnection(con);
} catch (SQLException e) {
logger.error("Failed to close DB connection for identity generation!");
throw new RuntimeException(e);
} finally {
rdbmsManager = null;
}
}
});

[May 2, 2005 7:28:58 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male andy
Expert
Member's Avatar

UK
Joined: Mar 13, 2004
Post Count: 5686
Status: Offline
Reply to this Post  Reply with Quote 
Re: "Standalone ID generation" docs out of date

As example code, I'd propose the following, which seems to work:

Now updated in CVS - will appear on the website when the nightly build process runs. Thanks.
----------------------------------------
-Andy smile

----------------------------------------
[Edit 1 times, last edit by andy at May 3, 2005 8:08:54 AM]
[May 3, 2005 8:08:05 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male areg
Newbie



Canada
Joined: Apr 7, 2010
Post Count: 12
Status: Offline
Reply to this Post  Reply with Quote 
Re: "Standalone ID generation" docs out of date

Another update for the latest version. Seems to work on 2.1.0:


final String generatorName = "MyGenerator";
// Obtain a ValueGenerationManager
ValueGenerationManager mgr = new ValueGenerationManager();

Properties properties = new Properties();
properties.setProperty("sequence-name", "GLOBAL"); // Use a global sequence number (for all tables)

ValueGenerator generator = mgr.getValueGenerator(generatorName);
if (generator == null) {
generator = mgr.createValueGenerator(generatorName,
TableGenerator.class,
properties,
pm.getObjectManager().getStoreManager(),
new ValueGenerationConnectionProvider() {
RDBMSStoreManager rdbmsManager = null;
ManagedConnection con;

public ManagedConnection retrieveConnection() {
rdbmsManager = (RDBMSStoreManager) pm.getObjectManager().getStoreManager();
// important to use TRANSACTION_NONE like DataNucleus does
con = rdbmsManager.getConnection(Connection.TRANSACTION_NONE);
return con;
}

public void releaseConnection() {
try {
con.close();
con = null;
}
finally {
rdbmsManager = null;
}
}
});
}

// Retrieve the next identity using this strategy
Long identifier = (Long) generator.next();

[Jun 1, 2010 7:28:30 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread