From: <tri...@us...> - 2008-01-30 17:37:03
|
Revision: 289 http://equanda.svn.sourceforge.net/equanda/?rev=289&view=rev Author: triathlon98 Date: 2008-01-30 09:36:20 -0800 (Wed, 30 Jan 2008) Log Message: ----------- EQ-125 rename "UOID" to "Uoid" Modified Paths: -------------- trunk/equanda-client/src/main/java/org/equanda/export/Export.java trunk/equanda-client/src/main/java/org/equanda/export/ExportField.java trunk/equanda-client/src/main/java/org/equanda/export/ExportFieldEvaluator.java trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaEJB.java trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaEntity.java trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaFieldBean.java trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaImportProxy.java trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaList.java trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaMediatorRoot.java trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaProxy.java trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaProxyState.java trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaSelector.java trunk/equanda-client/src/main/java/org/equanda/persistence/InvalidUOIDException.java trunk/equanda-client/src/main/java/org/equanda/persistence/LazyEJBListBase.java trunk/equanda-client/src/main/java/org/equanda/persistence/LazyList.java trunk/equanda-client/src/main/java/org/equanda/persistence/LazyProxyListBase.java trunk/equanda-client/src/test/java/org/equanda/persistence/EquandaListTest.java trunk/equanda-generate/src/main/velocity/ejb3/DMFieldBean.java.vm trunk/equanda-generate/src/main/velocity/ejb3/DMObjectBean.java.vm trunk/equanda-generate/src/main/velocity/ejb3/DMObjectSelector.java.vm trunk/equanda-generate/src/main/velocity/ejb3/MediatorBase-set.java.vm trunk/equanda-generate/src/main/velocity/ejb3/MediatorBase.java.vm trunk/equanda-generate/src/main/velocity/ejb3/MediatorRoot.java.vm trunk/equanda-generate/src/main/velocity/ejb3/ObjectBase.java.vm trunk/equanda-generate/src/main/velocity/ejb3/ObjectBean.java.vm trunk/equanda-generate/src/main/velocity/ejb3/ObjectEJBLocal.java.vm trunk/equanda-generate/src/main/velocity/ejb3/ObjectProxy.java.vm trunk/equanda-generate/src/main/velocity/ejb3/ObjectProxyState.java.vm trunk/equanda-generate/src/main/velocity/ejb3/ObjectSelectorBean.java.vm trunk/equanda-generate/src/main/velocity/ejb3/ObjectSelectorEJB.java.vm trunk/equanda-generate/src/main/velocity/ejb3/ProxyObjectUpdater.java.vm trunk/equanda-generate/src/main/velocity/import/DatabaseMap.java.vm trunk/equanda-generate/src/main/velocity/import/FieldMap.java.vm trunk/equanda-generate/src/main/velocity/import/ImportObjectProxy.java.vm trunk/equanda-generate/src/main/velocity/t5gui/base/EditPageBase.java.vm trunk/equanda-generate/src/main/velocity/t5gui/base/SelectComponentBase.java.vm trunk/equanda-generate/src/main/velocity/t5gui/components/Display.java.vm trunk/equanda-generate/src/main/velocity/t5gui/components/Edit.java.vm trunk/equanda-generate/src/main/velocity/t5gui/components/LinkList.java.vm trunk/equanda-generate/src/main/velocity/t5gui/components/Select.java.vm trunk/equanda-generate/src/main/velocity/t5gui/edit-tml/pages.tml.vm trunk/equanda-generate/src/main/velocity/t5gui/pages/Edit.java.vm trunk/equanda-server/src/main/java/org/equanda/attachment/AttachmentServlet.java trunk/equanda-server/src/main/java/org/equanda/ymport/FieldHandler.java trunk/equanda-t5gui/src/main/java/org/equanda/t5gui/services/AppModule.java trunk/equanda-t5gui/src/main/java/org/equanda/t5gui/translators/UoidTranslator.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/components/equandaLinkSelects/EquandaLinkSelects.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/components/input/equandaAttachment/EquandaAttachment.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/components/input/equandaLinkInput/LinkInputBinderWrapper.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/components/input/equandaLinkInput/actionHandler/LinkInputActionHandlerImpl.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/components/select/equandaSelectResults/EquandaSelectResults.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/navigation/NavigationEntryContainer.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/pages/alerts/Alerts.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/pages/edit/EditPage.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/pages/shared/AddViewEditManipulation.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/pages/view/ViewPage.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/selectionModel/EmbeddedFieldSelectionModel.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/selectionModel/LinkFieldSelectionModel.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/selectionModel/RoleSelectionModel.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/squeezeAdaptor/EquandaProxySqueezeAdaptor.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/translator/UoidTranslator.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/useradmin/cache/CacheLoaderPersister.java trunk/equanda-tapestry4/src/main/java/org/equanda/tapestry/util/EquandaProxyAccessor.java trunk/equanda-tapestry4/src/main/resources/org/equanda/tapestry/components/select/equandaSelectResults/EquandaSelectResults.html trunk/equanda-test/test-core/src/main/java/org/equanda/test/dm/server/LinkableMediator.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/export/ExportTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/CloneableTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/EmbeddedTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/EquandaQueryTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/FieldTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/LazyInstTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/LinkTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/ModifiedProxyTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/MultipleFieldTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/ProxyTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/SelectionTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/SelectorUpdateTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/SubselectTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/xejb/UniqueFieldsTest.java trunk/equanda-test/test-test/src/test/java/org/equanda/test/ymport/ImportTest.java trunk/equanda-tool/src/main/java/org/equanda/tool/export/ExportWorker.java trunk/equanda-tool/src/main/java/org/equanda/tool/export/object/ObjectSelector.java trunk/equanda-tool/src/main/java/org/equanda/tool/print/provider/ReportPrintInfo.java Added Paths: ----------- trunk/equanda-client/src/main/java/org/equanda/persistence/HasUoid.java trunk/equanda-client/src/main/java/org/equanda/persistence/Uoid.java trunk/equanda-client/src/main/java/org/equanda/persistence/UoidGenerator.java Removed Paths: ------------- trunk/equanda-client/src/main/java/org/equanda/persistence/HasUOID.java trunk/equanda-client/src/main/java/org/equanda/persistence/UOID.java trunk/equanda-client/src/main/java/org/equanda/persistence/UOIDGenerator.java Modified: trunk/equanda-client/src/main/java/org/equanda/export/Export.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/export/Export.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/export/Export.java 2008-01-30 17:36:20 UTC (rev 289) @@ -24,7 +24,7 @@ package org.equanda.export; -import org.equanda.persistence.UOID; +import org.equanda.persistence.Uoid; import org.equanda.persistence.EquandaProxy; import org.equanda.util.Base64; import org.equanda.util.IniFile; @@ -305,7 +305,7 @@ while ( tbLine.charAt( tbLine.length() - 1 ) == '0' ) tbLine.setLength( tbLine.length() - 1 ); if ( tbLine.charAt( tbLine.length() - 1 ) == '.' ) tbLine.setLength( tbLine.length() - 1 ); } - else if ( value instanceof UOID || value instanceof EquandaProxy ) + else if ( value instanceof Uoid || value instanceof EquandaProxy ) { exportLink( value, fieldName, tableName, tableMap, addDirective, tbDirective, tbLine ); } @@ -348,11 +348,11 @@ } else { - tbDirective.append( "UOID" ); + tbDirective.append( "Uoid" ); } } - if ( objToExport instanceof UOID ) + if ( objToExport instanceof Uoid ) { if ( fieldInfo == null ) { @@ -380,15 +380,15 @@ tableName.length() - "Selector".length() ); Class objClass = objSelEJB.getClass(); - Class[] param = { UOID.class }; + Class[] param = { Uoid.class }; Method method; try { - method = objClass.getMethod( "selectUOID", param ); + method = objClass.getMethod( "selectUoid", param ); } catch ( Exception e ) { - throw new ExportException( "Cannot find method selectUOID in " + objClass.getName(), e ); + throw new ExportException( "Cannot find method selectUoid in " + objClass.getName(), e ); } Object[] param_v = { objToExport }; @@ -399,7 +399,7 @@ catch ( Exception e ) { throw new ExportException( - "selectUOID " + ( (UOID) objToExport ).getId() + " in " + objClass.getName() + " failed", + "selectUoid " + ( (Uoid) objToExport ).getId() + " in " + objClass.getName() + " failed", e ); } @@ -597,7 +597,7 @@ } if ( firstIteration ) { - isLink = value instanceof UOID || value instanceof EquandaProxy; + isLink = value instanceof Uoid || value instanceof EquandaProxy; if ( addDirective && isLink ) tbDirective.append( "[" ); } Modified: trunk/equanda-client/src/main/java/org/equanda/export/ExportField.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/export/ExportField.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/export/ExportField.java 2008-01-30 17:36:20 UTC (rev 289) @@ -109,7 +109,7 @@ value = method.invoke( objectToExport ); if ( value instanceof EquandaProxy ) { - value = ( (EquandaProxy) value ).getUOID(); + value = ( (EquandaProxy) value ).getUoid(); } if ( value instanceof Collection ) { @@ -118,7 +118,7 @@ { if ( obj instanceof EquandaProxy ) { - col.add( ( (EquandaProxy) obj).getUOID()); + col.add( ( (EquandaProxy) obj).getUoid()); } else { Modified: trunk/equanda-client/src/main/java/org/equanda/export/ExportFieldEvaluator.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/export/ExportFieldEvaluator.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/export/ExportFieldEvaluator.java 2008-01-30 17:36:20 UTC (rev 289) @@ -68,7 +68,7 @@ Object ret = method.invoke( proxy ); if ( ret instanceof EquandaProxy ) { - ret = ( (EquandaProxy) ret ).getUOID(); + ret = ( (EquandaProxy) ret ).getUoid(); } return ret; } Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaEJB.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaEJB.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaEJB.java 2008-01-30 17:36:20 UTC (rev 289) @@ -30,9 +30,9 @@ * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> */ public interface EquandaEJB - extends HasUOID + extends HasUoid { - void init( UOID uoid ) + void init( Uoid uoid ) throws EquandaPersistenceException; void initEntity( EquandaEntity entity ) throws EquandaPersistenceException; Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaEntity.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaEntity.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaEntity.java 2008-01-30 17:36:20 UTC (rev 289) @@ -33,7 +33,7 @@ */ public interface EquandaEntity { - UOID getUOID(); + Uoid getUoid(); String getEquandaStatus(); Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaFieldBean.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaFieldBean.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaFieldBean.java 2008-01-30 17:36:20 UTC (rev 289) @@ -39,14 +39,14 @@ public class EquandaFieldBean { // fields - protected UOID uoid; + protected Uoid uoid; protected Timestamp equandaCreation; @EmbeddedId - public UOID getUOID() + public Uoid getUoid() { return uoid; } - public void setUOID( UOID uoid ) { this.uoid = uoid; } + public void setUoid( Uoid uoid ) { this.uoid = uoid; } @Version @Column( Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaImportProxy.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaImportProxy.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaImportProxy.java 2008-01-30 17:36:20 UTC (rev 289) @@ -31,15 +31,15 @@ */ public interface EquandaImportProxy { - void setUOID( UOID id ); + void setUoid( Uoid id ); - void setUOID( String id ); + void setUoid( String id ); - boolean hasUOID(); + boolean hasUoid(); String getEquandaType(); - public UOID getUOID(); + public Uoid getUoid(); java.sql.Timestamp getEquandaModificationDate(); Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaList.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaList.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaList.java 2008-01-30 17:36:20 UTC (rev 289) @@ -378,10 +378,10 @@ private boolean equalsElem( Object o1, Object o2 ) { if ( o1 == null || o2 == null ) return false; - if ( o1 instanceof HasUOID && o2 instanceof HasUOID ) + if ( o1 instanceof HasUoid && o2 instanceof HasUoid ) { - UOID u1 = ( (HasUOID) o1 ).getUOID(); - UOID u2 = ( (HasUOID) o2 ).getUOID(); + Uoid u1 = ( (HasUoid) o1 ).getUoid(); + Uoid u2 = ( (HasUoid) o2 ).getUoid(); return !( u1 == null || u2 == null ) && u1.equals( u2 ); } return o1.equals( o2 ); Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaMediatorRoot.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaMediatorRoot.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaMediatorRoot.java 2008-01-30 17:36:20 UTC (rev 289) @@ -48,7 +48,7 @@ public ENTITY getEquandaEntity() { return entity; } // allow retrieval of the base entity information - public UOID getUOID() { return entity.getUOID(); } + public Uoid getUoid() { return entity.getUoid(); } public String getEquandaType() { String type=entity.getEquandaType(); if (type.length()>4) type=type.substring(0,4); return type; } public java.sql.Timestamp getEquandaModificationDate() { return entity.getEquandaModificationDate(); } public java.sql.Timestamp getEquandaCreationDate() { return entity.getEquandaCreationDate(); } Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaProxy.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaProxy.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaProxy.java 2008-01-30 17:36:20 UTC (rev 289) @@ -36,9 +36,9 @@ * @author <a href="mailto:an...@pa...">Andrei Chiritescu</a> */ public abstract class EquandaProxy<PROXY extends EquandaProxy> - implements HasUOID, Serializable + implements HasUoid, Serializable { - protected UOID uoid; + protected Uoid uoid; protected ObjectType equandaType; protected Timestamp equandaModificationDate; protected long equandaVersion; @@ -46,7 +46,7 @@ private static final long serialVersionUID = 2777313477933801153L; protected boolean update; - public UOID getUOID() { return uoid; } + public Uoid getUoid() { return uoid; } public java.sql.Timestamp getEquandaModificationDate() { return equandaModificationDate; } @@ -91,7 +91,7 @@ Class clazz = this.getClass(); tb.append( clazz.getName() ); tb.append( " " ); - tb.append( getUOID() ); + tb.append( getUoid() ); try { Method method = clazz.getMethod( "getReference" ); Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaProxyState.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaProxyState.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaProxyState.java 2008-01-30 17:36:20 UTC (rev 289) @@ -35,7 +35,7 @@ public abstract class EquandaProxyState implements Serializable { - public UOID uoid; + public Uoid uoid; public ObjectType equandaType; public Timestamp equandaCreationDate; public Timestamp equandaModificationDate; Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaSelector.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaSelector.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/EquandaSelector.java 2008-01-30 17:36:20 UTC (rev 289) @@ -34,20 +34,20 @@ * * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> */ -public interface EquandaSelector<PROXY extends EquandaProxy, EJB extends HasUOID> +public interface EquandaSelector<PROXY extends EquandaProxy, EJB extends HasUoid> { String getEquandaName(); PROXY equandaCreate( String type ) throws EquandaPersistenceException; - PROXY selectUOID( UOID uoid ) + PROXY selectUoid( Uoid uoid ) throws EquandaPersistenceException; - EJB selectUOIDEJB( UOID uoid ) + EJB selectUoidEJB( Uoid uoid ) throws EquandaPersistenceException; - PROXY[] selectMultipleUOID( UOID[] arr ) + PROXY[] selectMultipleUoid( Uoid[] arr ) throws EquandaPersistenceException; /* @@ -60,7 +60,7 @@ List<EJB> selectEquandaEJB( EquandaQuery query ) throws EquandaPersistenceException; - List<UOID> equandaRunQueryUOID( EquandaQuery query ) + List<Uoid> equandaRunQueryUoid( EquandaQuery query ) throws EquandaPersistenceException; List<PROXY> equandaRunQuery( EquandaQuery query ) @@ -81,7 +81,7 @@ EJB selectEquandaSingleEJB( EquandaQuery query ) throws EquandaPersistenceException; - PROXY equandaRefresh( UOID uoid, long version ) + PROXY equandaRefresh( Uoid uoid, long version ) throws EquandaPersistenceException; PROXY equandaUpdate( PROXY proxy ) Deleted: trunk/equanda-client/src/main/java/org/equanda/persistence/HasUOID.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/HasUOID.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/HasUOID.java 2008-01-30 17:36:20 UTC (rev 289) @@ -1,41 +0,0 @@ -/** - * This file is part of the equanda project. - * - * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF - * ANY KIND, either express or implied. See the License for the specific language governing rights and - * limitations under the License. - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - */ - -package org.equanda.persistence; - - -/** - * Marker interface to indicate that the object has a UOID. - * - * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> - */ -public interface HasUOID -{ - /** - * Get unique object identifier for this object. - * - * @return uoid - */ - UOID getUOID(); -} Copied: trunk/equanda-client/src/main/java/org/equanda/persistence/HasUoid.java (from rev 281, trunk/equanda-client/src/main/java/org/equanda/persistence/HasUOID.java) =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/HasUoid.java (rev 0) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/HasUoid.java 2008-01-30 17:36:20 UTC (rev 289) @@ -0,0 +1,41 @@ +/** + * This file is part of the equanda project. + * + * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights and + * limitations under the License. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + */ + +package org.equanda.persistence; + + +/** + * Marker interface to indicate that the object has a Uoid. + * + * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> + */ +public interface HasUoid +{ + /** + * Get unique object identifier for this object. + * + * @return uoid + */ + Uoid getUoid(); +} Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/InvalidUOIDException.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/InvalidUOIDException.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/InvalidUOIDException.java 2008-01-30 17:36:20 UTC (rev 289) @@ -27,8 +27,8 @@ import javax.ejb.ApplicationException; /** - * Exception which is thrown when trying to create an invalid UOID. - * This can for example happen when a UOID is built from a string with invalid length or invalid characters. + * Exception which is thrown when trying to create an invalid Uoid. + * This can for example happen when a Uoid is built from a string with invalid length or invalid characters. * * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> */ Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/LazyEJBListBase.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/LazyEJBListBase.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/LazyEJBListBase.java 2008-01-30 17:36:20 UTC (rev 289) @@ -56,11 +56,11 @@ protected abstract SEL getSelector() throws NamingException; - protected EJB getOneObject( UOID uoid ) + protected EJB getOneObject( Uoid uoid ) throws NamingException, EquandaPersistenceException { SEL sel = getSelector(); - EJB res = sel.selectUOIDEJB( uoid ); + EJB res = sel.selectUoidEJB( uoid ); sel.remove(); return res; } @@ -87,12 +87,12 @@ return obj; } - protected EJB[] getMultipleObjects( UOID[] uoids ) + protected EJB[] getMultipleObjects( Uoid[] uoids ) throws NamingException, EquandaPersistenceException { SEL sel = getSelector(); EJB[] res = (EJB[]) new EquandaEJB[uoids.length]; - for ( int i = 0; i < uoids.length ; i++ ) res[ i ] = sel.selectUOIDEJB( uoids[ i ] ); + for ( int i = 0; i < uoids.length ; i++ ) res[ i ] = sel.selectUoidEJB( uoids[ i ] ); sel.remove(); return res; } Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/LazyList.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/LazyList.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/LazyList.java 2008-01-30 17:36:20 UTC (rev 289) @@ -51,7 +51,7 @@ * * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> */ -public abstract class LazyList<TYPE extends HasUOID> +public abstract class LazyList<TYPE extends HasUoid> implements java.util.List<TYPE>, ExceptionCodes, Serializable { private static final long serialVersionUID = -8611799858984015845L; @@ -84,14 +84,14 @@ throws NamingException; /** - * Get TYPE object for the given UOID. + * Get TYPE object for the given Uoid. * * @param uoid pk - * @return object with given UOID + * @return object with given Uoid * @throws NamingException problems * @throws EquandaPersistenceException problems */ - protected abstract TYPE getOneObject( UOID uoid ) + protected abstract TYPE getOneObject( Uoid uoid ) throws NamingException, EquandaPersistenceException; /** @@ -102,7 +102,7 @@ * @throws NamingException problems * @throws EquandaPersistenceException problems */ - protected abstract TYPE[] getMultipleObjects( UOID[] uoids ) + protected abstract TYPE[] getMultipleObjects( Uoid[] uoids ) throws NamingException, EquandaPersistenceException; /** @@ -129,7 +129,7 @@ private static final Logger log = Logger.getLogger( LazyList.class ); private MockObject mock; - private UOID nextObj; // last element of last executed batch (used to throw ConcurrentModificationException) + private Uoid nextObj; // last element of last executed batch (used to throw ConcurrentModificationException) private TYPE[] cache; // cache larger group of values private int startOfCache; // index of the first element (in the results), stored at 0 in cache @@ -151,7 +151,7 @@ private int originalFirst; private int originalMax; - private List<UOID> data; // possible list with data for complex queries + private List<Uoid> data; // possible list with data for complex queries public LazyList( EquandaQuery query ) { @@ -181,8 +181,8 @@ { throw new NullPointerException( "LazyList cannot contain null" ); } - UOID uoid = obj.getUOID(); - if ( data == null ) data = new ArrayList<UOID>(); + Uoid uoid = obj.getUoid(); + if ( data == null ) data = new ArrayList<Uoid>(); if ( !data.contains( uoid ) && ( data.size() < originalMax || originalMax == -1 ) ) { return data.add( uoid ); @@ -195,7 +195,7 @@ throw new UnsupportedOperationException(); } - private UOID getUOID( int index ) + private Uoid getUoid( int index ) { return data.get( index ); } @@ -243,10 +243,10 @@ // size() should still be done for selector with SubSelects and "add" operator long min = Math.min( getCacheCapacity(), fullSize() - index ); size = ( min > Integer.MAX_VALUE ) ? Integer.MAX_VALUE : (int) min; - UOID[] uoids = new UOID[size]; + Uoid[] uoids = new Uoid[size]; for ( int i = 0; i < size ; i++ ) { - uoids[ i ] = getUOID( i + index ); + uoids[ i ] = getUoid( i + index ); } cache = getMultipleObjects( uoids ); startOfCache = index; @@ -272,13 +272,13 @@ if ( cache.length > 0 ) { if ( nextObj != null && ( index == previousEndOfCache ) - && !nextObj.equals( cache[ 0 ].getUOID() ) ) + && !nextObj.equals( cache[ 0 ].getUoid() ) ) { throw new ConcurrentModificationException(); } if ( cache.length == size && size != maxSize ) { - nextObj = cache[ cache.length - 1 ].getUOID(); + nextObj = cache[ cache.length - 1 ].getUoid(); endOfCache--; } else @@ -404,7 +404,7 @@ // for subselects with add operand ( when size is requested ), fetch all UOIDs size = 0; List<TYPE> val; - if ( data == null ) data = new ArrayList<UOID>(); + if ( data == null ) data = new ArrayList<Uoid>(); for ( EquandaQuery query : queries ) { query.setFirstResult( 0 ); Modified: trunk/equanda-client/src/main/java/org/equanda/persistence/LazyProxyListBase.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/LazyProxyListBase.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/LazyProxyListBase.java 2008-01-30 17:36:20 UTC (rev 289) @@ -56,11 +56,11 @@ abstract protected SEL getSelector() throws NamingException; - protected PROXY getOneObject( UOID uoid ) + protected PROXY getOneObject( Uoid uoid ) throws NamingException, EquandaPersistenceException { SEL sel = getSelector(); - PROXY res = sel.selectUOID( uoid ); + PROXY res = sel.selectUoid( uoid ); sel.remove(); return res; } @@ -88,11 +88,11 @@ return obj; } - protected PROXY[] getMultipleObjects( UOID[] uoids ) + protected PROXY[] getMultipleObjects( Uoid[] uoids ) throws NamingException, EquandaPersistenceException { SEL sel = getSelector(); - PROXY[] res = sel.selectMultipleUOID( uoids ); + PROXY[] res = sel.selectMultipleUoid( uoids ); sel.remove(); return res; } Deleted: trunk/equanda-client/src/main/java/org/equanda/persistence/UOID.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/UOID.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/UOID.java 2008-01-30 17:36:20 UTC (rev 289) @@ -1,96 +0,0 @@ -/** - * This file is part of the equanda project. - * - * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF - * ANY KIND, either express or implied. See the License for the specific language governing rights and - * limitations under the License. - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - */ - -package org.equanda.persistence; - -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.Transient; -import java.io.Serializable; - -/** - * UOID definition class. This is just a thin wrapper for String, as a UOID in equanda is just a 14 character String, but - * it is represented in a different class to allow discrimination and better use of polymorphism. - * - * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> - */ -@Embeddable -public class UOID - implements HasUOID, Serializable -{ - private static final long serialVersionUID = -4559093889908903954L; - private String id; - - public UOID() - { - id = "----INVALID---"; - } // to allow UOID to be a DVC - - UOID( byte[] bytes ) - { - id = new String( bytes ); - } - - public UOID( String str ) - { - if ( str.length() > 14 ) str = str.trim(); - if ( str.length() != 14 ) throw new InvalidUOIDException(); - id = str; - } - - @Transient - public UOID getUOID() - { - return this; - } - - @Column( name = "EQUANDA_UOID", columnDefinition = "CHAR(14)" ) - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } // to allow UOID to be a DVC - - public String toString() - { - return this.id; - } - - public boolean equals( Object obj ) - { - if ( obj == null || !( obj instanceof UOID ) ) return false; - UOID other = (UOID) obj; - return id.equals( other.getId() ); - } - - public int hashCode() - { - if ( id == null ) return 0; - return id.hashCode(); - } -} \ No newline at end of file Deleted: trunk/equanda-client/src/main/java/org/equanda/persistence/UOIDGenerator.java =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/UOIDGenerator.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/UOIDGenerator.java 2008-01-30 17:36:20 UTC (rev 289) @@ -1,153 +0,0 @@ -/** - * This file is part of the equanda project. - * - * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF - * ANY KIND, either express or implied. See the License for the specific language governing rights and - * limitations under the License. - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - */ - -package org.equanda.persistence; - -import java.util.Random; - -/** - * generator for UOID values for the newly created records We need a universal object if which is fast to generate, has - * a minimal (no) configuration overhead and cross platform. In accordance with Scott Ambler's article about this - * ("Enterprise Ready Object IDs", @link http://www.sdmagazine.com/print/documentID=11250) we use a HIGH-LOW scheme. - * Values are unique accross tables and normally also accross databases. This is very important when a database is - * remotely added to (eg on a portable) and new data has to be merged later. <p/> I am concerned about mistakes caused - * by improper configuration and therefore do not want to use a configurable HIGH value. A PC's IP address is not - * guaranteed unique when PC's are connecting and disconnecting from the network. I do not know how to obtain a network - * card's MAC address in a cross platform method, so I have to search for a different mechanism. A popular fix to this - * is using a database table to store generated values. I don't like that because lack of transactions can make this - * very dangerous on some databases. <p/> The idea is to use the time of initialisation of this class as base for the - * HIGH address. This should prove to be quite random and chances are very, very slim that a second system which needs - * the same database will also use this timestamp as base for HIGH value. However, to decrease the likelyhood even - * further, the HIGH value also contains a random number which does not use the time at it's seed. <p/> For LOW values - * we just use a counter and we force a new HIGH value when the counter runs out. Contrary to normal practice, the LOW - * counter does not start at zero, but at a random number. This increases the distribution of UOID values (which should - * improve the quality of the indexes). Also, in the unlikely event that HIGH values would clash, this reduces the - * chance of duplicate UOID values. <p/> The UOID consists of a 36bit time, and 30bit random number, giving a 66bit high - * value, and a 18bit LOW value, giving a 84 bit key. This is converted to a 14 digit String using base64 encoding. - * However, the digits are encoded back to front to make the UOID strings discriminate from the start. <p/> There are - * some things which can be chosen in this scheme. The random part of the HIGH value could be regenerated for each UOID - * (giving a HIGH/RAND/LOW scheme), or just once (as in true HIGH/LOW scheme). When going for a once generated random, - * the question is whether you change just the time part or both time and random parts when you run out of LOW values - * and have to generate a new HIGH as a result of that. - * - * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> - */ -public final class UOIDGenerator -{ - private static Integer lock = new Integer( 0 ); // lock to force sequential access - private static long time = System.currentTimeMillis(); // time part of high value - private static boolean initialised; // true when uoid is initialised - private static byte[] uoid = - new byte[ 14 ]; // array to build UOID in, normally contains high in fourth and following characters - private static int low; // next value for LOW - private static int lowLast; // last value for LOW, when low==lowLast then a new high has to be - // regenerated (test on increment, increment after use) - private static final int LOW_MAX = 262144; // max value for LOW (==2^18) - private static byte[] BASE64 = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', - 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', - 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '.', 'a', 'b', - 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', - 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z' }; - - // purely static class, hide constructor - private UOIDGenerator() - { - } - - /** - * get a new UOID - * - * @return UOID (14 character String) - */ - public static UOID get() - { - synchronized ( lock ) - { - if ( !initialised ) - { - // generate the random number - Random rnd = new Random(); // @todo need a different seed, this is now time based and I - // would prefer something different, like an object address - // get the random number, instead of getting an integer and converting that to base64 later, - // we get a string and narrow that down to base64, use the top 6 bits of the characters - // as they are more random than the bottom ones... - rnd.nextBytes( uoid ); // get some random characters - uoid[ 3 ] = BASE64[ ( ( uoid[ 3 ] >> 2 ) & 0x3f ) ]; - uoid[ 4 ] = BASE64[ ( ( uoid[ 4 ] >> 2 ) & 0x3f ) ]; - uoid[ 5 ] = BASE64[ ( ( uoid[ 5 ] >> 2 ) & 0x3f ) ]; - uoid[ 6 ] = BASE64[ ( ( uoid[ 6 ] >> 2 ) & 0x3f ) ]; - uoid[ 7 ] = BASE64[ ( ( uoid[ 7 ] >> 2 ) & 0x3f ) ]; - - // complete the time part in the HIGH value of the UOID - // this also sets the initial low value - completeUOID( rnd ); - - initialised = true; - } - - // fill in LOW value in uoid - int l = low; - uoid[ 0 ] = BASE64[ ( l & 0x3f ) ]; - l >>= 6; - uoid[ 1 ] = BASE64[ ( l & 0x3f ) ]; - l >>= 6; - uoid[ 2 ] = BASE64[ ( l & 0x3f ) ]; - - UOID res = new UOID( uoid ); - - // increment LOW - low++; - if ( low == LOW_MAX ) low = 0; - if ( low == lowLast ) - { - time = System.currentTimeMillis(); - completeUOID(); - } - - return res; - } - } - - private static void completeUOID() - { - completeUOID( new Random() ); - } - - private static void completeUOID( Random rnd ) - { - // fill in time part in UOID string - long t = time; - for ( int i = 0; i < 6; i++ ) - { - uoid[ 8 + i ] = BASE64[ ( ( (int) t ) & 0x3f ) ]; - t >>= 6; - } - - // generate new LOW start value - lowLast = low = rnd.nextInt( LOW_MAX ); - } -} Copied: trunk/equanda-client/src/main/java/org/equanda/persistence/Uoid.java (from rev 281, trunk/equanda-client/src/main/java/org/equanda/persistence/UOID.java) =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/Uoid.java (rev 0) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/Uoid.java 2008-01-30 17:36:20 UTC (rev 289) @@ -0,0 +1,96 @@ +/** + * This file is part of the equanda project. + * + * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights and + * limitations under the License. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + */ + +package org.equanda.persistence; + +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Transient; +import java.io.Serializable; + +/** + * Uoid definition class. This is just a thin wrapper for String, as a Uoid in equanda is just a 14 character String, but + * it is represented in a different class to allow discrimination and better use of polymorphism. + * + * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> + */ +@Embeddable +public class Uoid + implements HasUoid, Serializable +{ + private static final long serialVersionUID = -4559093889908903954L; + private String id; + + public Uoid() + { + id = "----INVALID---"; + } // to allow Uoid to be a DVC + + Uoid( byte[] bytes ) + { + id = new String( bytes ); + } + + public Uoid( String str ) + { + if ( str.length() > 14 ) str = str.trim(); + if ( str.length() != 14 ) throw new InvalidUOIDException(); + id = str; + } + + @Transient + public Uoid getUoid() + { + return this; + } + + @Column( name = "EQUANDA_UOID", columnDefinition = "CHAR(14)" ) + public String getId() + { + return id; + } + + public void setId( String id ) + { + this.id = id; + } // to allow Uoid to be a DVC + + public String toString() + { + return this.id; + } + + public boolean equals( Object obj ) + { + if ( obj == null || !( obj instanceof Uoid ) ) return false; + Uoid other = (Uoid) obj; + return id.equals( other.getId() ); + } + + public int hashCode() + { + if ( id == null ) return 0; + return id.hashCode(); + } +} \ No newline at end of file Copied: trunk/equanda-client/src/main/java/org/equanda/persistence/UoidGenerator.java (from rev 281, trunk/equanda-client/src/main/java/org/equanda/persistence/UOIDGenerator.java) =================================================================== --- trunk/equanda-client/src/main/java/org/equanda/persistence/UoidGenerator.java (rev 0) +++ trunk/equanda-client/src/main/java/org/equanda/persistence/UoidGenerator.java 2008-01-30 17:36:20 UTC (rev 289) @@ -0,0 +1,153 @@ +/** + * This file is part of the equanda project. + * + * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights and + * limitations under the License. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + */ + +package org.equanda.persistence; + +import java.util.Random; + +/** + * generator for Uoid values for the newly created records We need a universal object if which is fast to generate, has + * a minimal (no) configuration overhead and cross platform. In accordance with Scott Ambler's article about this + * ("Enterprise Ready Object IDs", @link http://www.sdmagazine.com/print/documentID=11250) we use a HIGH-LOW scheme. + * Values are unique accross tables and normally also accross databases. This is very important when a database is + * remotely added to (eg on a portable) and new data has to be merged later. <p/> I am concerned about mistakes caused + * by improper configuration and therefore do not want to use a configurable HIGH value. A PC's IP address is not + * guaranteed unique when PC's are connecting and disconnecting from the network. I do not know how to obtain a network + * card's MAC address in a cross platform method, so I have to search for a different mechanism. A popular fix to this + * is using a database table to store generated values. I don't like that because lack of transactions can make this + * very dangerous on some databases. <p/> The idea is to use the time of initialisation of this class as base for the + * HIGH address. This should prove to be quite random and chances are very, very slim that a second system which needs + * the same database will also use this timestamp as base for HIGH value. However, to decrease the likelyhood even + * further, the HIGH value also contains a random number which does not use the time at it's seed. <p/> For LOW values + * we just use a counter and we force a new HIGH value when the counter runs out. Contrary to normal practice, the LOW + * counter does not start at zero, but at a random number. This increases the distribution of Uoid values (which should + * improve the quality of the indexes). Also, in the unlikely event that HIGH values would clash, this reduces the + * chance of duplicate Uoid values. <p/> The Uoid consists of a 36bit time, and 30bit random number, giving a 66bit high + * value, and a 18bit LOW value, giving a 84 bit key. This is converted to a 14 digit String using base64 encoding. + * However, the digits are encoded back to front to make the Uoid strings discriminate from the start. <p/> There are + * some things which can be chosen in this scheme. The random part of the HIGH value could be regenerated for each Uoid + * (giving a HIGH/RAND/LOW scheme), or just once (as in true HIGH/LOW scheme). When going for a once generated random, + * the question is whether you change just the time part or both time and random parts when you run out of LOW values + * and have to generate a new HIGH as a result of that. + * + * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> + */ +public final class UoidGenerator +{ + private static Integer lock = new Integer( 0 ); // lock to force sequential access + private static long time = System.currentTimeMillis(); // time part of high value + private static boolean initialised; // true when uoid is initialised + private static byte[] uoid = + new byte[ 14 ]; // array to build Uoid in, normally contains high in fourth and following characters + private static int low; // next value for LOW + private static int lowLast; // last value for LOW, when low==lowLast then a new high has to be + // regenerated (test on increment, increment after use) + private static final int LOW_MAX = 262144; // max value for LOW (==2^18) + private static byte[] BASE64 = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '.', 'a', 'b', + 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z' }; + + // purely static class, hide constructor + private UoidGenerator() + { + } + + /** + * get a new Uoid + * + * @return Uoid (14 character String) + */ + public static Uoid get() + { + synchronized ( lock ) + { + if ( !initialised ) + { + // generate the random number + Random rnd = new Random(); // @todo need a different seed, this is now time based and I + // would prefer something different, like an object address + // get the random number, instead of getting an integer and converting that to base64 later, + // we get a string and narrow that down to base64, use the top 6 bits of the characters + // as they are more random than the bottom ones... + rnd.nextBytes( uoid ); // get some random characters + uoid[ 3 ] = BASE64[ ( ( uoid[ 3 ] >> 2 ) & 0x3f ) ]; + uoid[ 4 ] = BASE64[ ( ( uoid[ 4 ] >> 2 ) & 0x3f ) ]; + uoid[ 5 ] = BASE64[ ( ( uoid[ 5 ] >> 2 ) & 0x3f ) ]; + uoid[ 6 ] = BASE64[ ( ( uoid[ 6 ] >> 2 ) & 0x3f ) ]; + uoid[ 7 ] = BASE64[ ( ( uoid[ 7 ] >> 2 ) & 0x3f ) ]; + + // complete the time part in the HIGH value of the Uoid + // this also sets the initial low value + completeUOID( rnd ); + + initialised = true; + } + + // fill in LOW value in uoid + int l = low; + uoid[ 0 ] = BASE64[ ( l & 0x3f ) ]; + l >>= 6; + uoid[ 1 ] = BASE64[ ( l & 0x3f ) ]; + l >>= 6; + uoid[ 2 ] = BASE64[ ( l & 0x3f ) ]; + + Uoid res = new Uoid( uoid ); + + // increment LOW + low++; + if ( low == LOW_MAX ) low = 0; + if ( low == lowLast ) + { + time = System.currentTimeMillis(); + completeUOID(); + } + + return res; + } + } + + private static void completeUOID() + { + completeUOID( new Random() ); + } + + private static void completeUOID( Random rnd ) + { + // fill in time part in Uoid string + long t = time; + for ( int i = 0; i < 6; i++ ) + { + uoid[ 8 + i ] = BASE64[ ( ( (int) t ) & 0x3f ) ]; + t >>= 6; + } + + // generate new LOW start value + lowLast = low = rnd.nextInt( LOW_MAX ); + } +} Modified: trunk/equanda-client/src/test/java/org/equanda/persistence/EquandaListTest.java =================================================================== --- trunk/equanda-client/src/test/java/org/equanda/persistence/EquandaListTest.java 2008-01-30 17:32:13 UTC (rev 288) +++ trunk/equanda-client/src/test/java/org/equanda/persistence/EquandaListTest.java 2008-01-30 17:36:20 UTC (rev 289) @@ -5,8 +5,6 @@ import java.util.ArrayList; import java.util.Collection; -import org.equanda.persistence.*; - /** * Test cases for EquandaList. * @@ -106,7 +104,7 @@ throws Exception { DummyProxy dp1 = new DummyProxy(); - DummyProxy dp2 = new DummyProxy( dp1.getUOID() ); + DummyProxy dp2 = new DummyProxy( dp1.getUoid() ); EquandaList<DummyProxy> list = new EquandaList<DummyProxy>(); // new list; // check uniqueness in add list - using different proxies but with the same uoid list.add( dp1 ); @@ -156,7 +154,7 @@ { DummyProxy dp1 = new DummyProxy(); DummyProxy dp2 = new DummyProxy(); - DummyProxy dp2Duplicate = new DummyProxy( dp2.getUOID() ); + DummyProxy dp2Duplicate = new DummyProxy( dp2.getUoid() ); dp2Duplicate.setDistinct( "some value" ); // add a duplicate object but with a diffrent state // check that there is no new elem added but the state of the last added duplicate is saved @@ -198,7 +196,7 @@ { DummyProxy dp1 = new DummyProxy(); DummyProxy dp2 = new DummyProxy(); - DummyProxy dp2Duplicate = new DummyProxy( dp2.getUOID() ); + DummyProxy dp2Duplicate = new DummyProxy( dp2.getUoid() ); dp2Duplicate.setDistinct( "some value" ); // set a duplicate object but with a diffrent state // check that there is no new elem added but the state of the last set duplicate is saved @@ -223,10 +221,10 @@ public DummyProxy() { - uoid = UOIDGenerator.get(); + uoid = UoidGenerator.get(); } - public DummyProxy( UOID uoid ) + public DummyProxy( Uoid uoid ) { this.uoid = uoid; } Modified: trunk/equanda-generate/src/main/velocity/ejb3/DMFieldBean.java.vm =================================================================== --- trunk/equanda-generate/src/main/velocity/ejb3/DMFieldBean.java.vm 2008-01-30 17:32:13 UTC (rev 288) +++... [truncated message content] |