Author: jonesde
Date: Fri Sep 7 22:32:53 2007 New Revision: 573785 URL: http://svn.apache.org/viewvc?rev=573785&view=rev Log: Added sequence-bank-size to configure sequence bank sizes on a per-entity basis Modified: ofbiz/trunk/framework/entity/dtd/entitymodel.xsd ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java Modified: ofbiz/trunk/framework/entity/dtd/entitymodel.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd?rev=573785&r1=573784&r2=573785&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/dtd/entitymodel.xsd (original) +++ ofbiz/trunk/framework/entity/dtd/entitymodel.xsd Fri Sep 7 22:32:53 2007 @@ -65,6 +65,7 @@ <xs:attribute type="xs:string" name="package-name" use="required"/> <xs:attribute type="xs:string" name="default-resource-name"/> <xs:attribute type="xs:string" name="dependent-on"/> + <xs:attribute type="xs:string" name="sequence-bank-size"/> <xs:attribute name="enable-lock" default="false"> <xs:simpleType> <xs:restriction base="xs:token"> Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=573785&r1=573784&r2=573785&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Fri Sep 7 22:32:53 2007 @@ -2480,8 +2480,11 @@ } } } + + // might be null, but will usually match the entity name + ModelEntity seqModelEntity = this.getModelEntity(seqName); - Long newSeqId = sequencer == null ? null : sequencer.getNextSeqId(seqName, staggerMax); + Long newSeqId = sequencer == null ? null : sequencer.getNextSeqId(seqName, staggerMax, seqModelEntity); return newSeqId; } catch (GenericEntityException e) { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java?rev=573785&r1=573784&r2=573785&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java Fri Sep 7 22:32:53 2007 @@ -76,6 +76,9 @@ /** The entity-name of the Entity that this Entity is dependent on, if empty then no dependency */ protected String dependentOn = ""; + /** The sequence-bank-size of the Entity */ + protected Integer sequenceBankSize = null; + /** A List of the Field objects for the Entity */ protected List fields = FastList.newInstance(); protected Map fieldsMap = null; @@ -237,6 +240,15 @@ this.noAutoStamp = UtilXml.checkBoolean(entityElement.getAttribute("no-auto-stamp"), false); this.neverCache = UtilXml.checkBoolean(entityElement.getAttribute("never-cache"), false); this.autoClearCache = UtilXml.checkBoolean(entityElement.getAttribute("auto-clear-cache"), true); + + String sequenceBankSizeStr = UtilXml.checkEmpty(entityElement.getAttribute("sequence-bank-size")); + if (UtilValidate.isNotEmpty(sequenceBankSizeStr)) { + try { + this.sequenceBankSize = Integer.valueOf(sequenceBankSizeStr); + } catch (NumberFormatException e) { + Debug.logError("Error parsing sequence-bank-size value [" + sequenceBankSizeStr + "] for entity [" + this.entityName + "]", module); + } + } } @@ -400,6 +412,10 @@ } } + public Integer getSequenceBankSize() { + return this.sequenceBankSize; + } + public void updatePkLists() { pks = FastList.newInstance(); nopks = FastList.newInstance(); @@ -1222,6 +1238,10 @@ if (!this.getAutoClearCache()) { root.setAttribute("auto-clear-cache", "false"); + } + + if (this.getSequenceBankSize() != null) { + root.setAttribute("sequence-bank-size", this.getSequenceBankSize().toString()); } if (UtilValidate.isNotEmpty(this.getTitle())) { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java?rev=573785&r1=573784&r2=573785&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java Fri Sep 7 22:32:53 2007 @@ -75,14 +75,14 @@ this.idColName = idField.getColName(); } - public Long getNextSeqId(String seqName, long staggerMax) { + public Long getNextSeqId(String seqName, long staggerMax, ModelEntity seqModelEntity) { SequenceBank bank = (SequenceBank) sequences.get(seqName); if (bank == null) { synchronized(this) { bank = (SequenceBank) sequences.get(seqName); if (bank == null) { - bank = new SequenceBank(seqName, this); + bank = new SequenceBank(seqName, seqModelEntity, this); sequences.put(seqName, bank); } } @@ -93,6 +93,7 @@ class SequenceBank { public static final long defaultBankSize = 10; + public static final long maxBankSize = 5000; public static final long startSeqId = 10000; public static final int minWaitMillis = 5; public static final int maxWaitMillis = 50; @@ -102,13 +103,15 @@ long maxSeqId; String seqName; SequenceUtil parentUtil; + ModelEntity seqModelEntity; - public SequenceBank(String seqName, SequenceUtil parentUtil) { + public SequenceBank(String seqName, ModelEntity seqModelEntity, SequenceUtil parentUtil) { this.seqName = seqName; this.parentUtil = parentUtil; + this.seqModelEntity = seqModelEntity; curSeqId = 0; maxSeqId = 0; - fillBank(1); + fillBank(1, seqModelEntity); } public synchronized Long getNextSeqId(long staggerMax) { @@ -123,7 +126,7 @@ curSeqId += stagger; return retSeqId; } else { - fillBank(stagger); + fillBank(stagger, seqModelEntity); if ((curSeqId + stagger) <= maxSeqId) { Long retSeqId = new Long(curSeqId); curSeqId += stagger; @@ -135,18 +138,23 @@ } } - protected synchronized void fillBank(long stagger) { + protected synchronized void fillBank(long stagger, ModelEntity seqModelEntity) { //Debug.logWarning("[SequenceUtil.SequenceBank.fillBank] Starting fillBank Thread Name is: " + Thread.currentThread().getName() + ":" + Thread.currentThread().toString(), module); + // no need to get a new bank, SeqIds available + if ((curSeqId + stagger) <= maxSeqId) return; + long bankSize = defaultBankSize; + if (seqModelEntity != null && seqModelEntity.getSequenceBankSize() != null) { + bankSize = seqModelEntity.getSequenceBankSize().longValue(); + } if (stagger > 1) { // NOTE: could use staggerMax for this, but if that is done it would be easier to guess a valid next id without a brute force attack bankSize = stagger * defaultBankSize; } + + if (bankSize > maxBankSize) bankSize = maxBankSize; - // no need to get a new bank, SeqIds available - if ((curSeqId + stagger) <= maxSeqId) return; - long val1 = 0; long val2 = 0; |
Free forum by Nabble | Edit this page |