|
|
|
questions
|
|
The LDAP protocol was designed for a subset of all database tasks. Frequently, developers run into a requirement that is satisfied in other database systems, but is not addressed in LDAP. One of those pernicious gaps is the ability to auto-increment the identifiers for a class of entry. Whereas you can tell an RDBMS to generate keys for new rows and add data without concern, the LDAP model expects you to explicitly identify whatever entries you create. The desire to overcome this issue is expressed so often on the OpenLDAP mailing list, that many of the project's veterans have (sadly) grown weary of even referring others to information on recommended solutions. On one such occasion, I described my own alorithm for an application-layer solution to the problem. Nobody gave me any negative feedback, so when the time came to use auto-incrementing identifiers in my weblog example, I implemented it. The next time somebody asked, I pointed them to my code. The following thread with senior OpenLDAP developer Howard Chu resulted: Jon serves
| |
Original version |
Final version |
|
You will note that the original version sets the new identifier in the preCreate() method using an extensive and expensive private routine, getNextIdentifier(). The final version replaces this with a single call:
Now all you need to do to make an LDAPHttp object use auto-incrementing is to put a counter entry in your database and add a line like this. The method call lets you specify the counter's distinguished name and attribute to be whatever you want. An access control rule may be necessary, but if you put the counter entry in the same base as the entries you're creating, the authority to update the counter can come with the same rule that already gives users authority to create entries in the first place. The original version may still be faster, especially when lots of entries are created in rapid succession, but as Howard points out the final version has the major advantage of working in a distributed environment. I was wrong. Admitting you made a mistake also means you are now wiser. Best practices can be challenged, but their existence presumes that they have already withstood challenge. I am hosting both algorithms because I don't think there is one right answer to this problem, but I accept with all humility that my idea was indeed inferior. My thanks to Howard Chu for taking the time to engage me and help me see the light. May this be the way in the open source community at large, so that we can all grow wiser. | |
Design | Javadocs | Downloads | Examples | Plan
Services | Products | Standards | Vision