📄 databuffer.java
字号:
/*
*
* Copyright (c) 2004 SourceTap - www.sourcetap.com
*
* The contents of this file are subject to the SourceTap Public License
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
* 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.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*/
package com.sourcetap.sfa.event;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilTimer;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.model.ModelEntity;
/**
* DOCUMENT ME!
*
*/
public class DataBuffer {
public static final String module = DataBuffer.class.getName();
private static final boolean TIMER = false;
protected ArrayList contents = new ArrayList();
protected GenericDelegator delegator = null;
protected DataMatrix parentDataMatrix = null;
protected int rowCount = 0;
public DataBuffer(GenericDelegator delegator, DataMatrix parentDataMatrix) {
setDelegator(delegator);
setParentDataMatrix(parentDataMatrix);
}
/**
* DOCUMENT ME!
*
* @return
*/
public ArrayList getContents() {
return contents;
}
/**
* DOCUMENT ME!
*
* @param row
*
* @return
*/
public Vector getContentsRow(int row) {
// Returns one row from the buffer. The row is a vector of generic values. There will be one generic value
// in the vector for each entity for one row of data.
Vector contentsRow = null;
try {
contentsRow = (Vector) (contents.get(row));
} catch (IndexOutOfBoundsException e) {
Debug.logWarning("[DataBuffer.getContentsRow()]: Row " +
String.valueOf(row) + " does not exist in the buffer.", module);
} catch (Exception e) {
e.printStackTrace();
}
return contentsRow;
}
/**
* DOCUMENT ME!
*
* @param genericValueVector
*/
public void addContentsRow(Vector genericValueVector) {
UtilTimer utilTimer = new UtilTimer();
if (TIMER) {
utilTimer.timerString(5, "[DataBuffer.addContentsRow] Start");
}
contents.add(genericValueVector);
if (TIMER) {
utilTimer.timerString(5, "[DataBuffer.addContentsRow] Finish");
}
setRowCount(getRowCount() + 1);
}
public void setContentsRow(int row, Vector genericValueVector)
{
int numRows = getRowCount();
if ( row < numRows )
contents.set(row,genericValueVector);
else
addContentsRow(genericValueVector);
}
/**
* DOCUMENT ME!
*
* @param row
* @param entityNumber
*
* @return
*/
public GenericValue getGenericValue(int row, int entityNumber) {
UtilTimer utilTimer = new UtilTimer();
if (TIMER) {
utilTimer.timerString(5,
"[DataBuffer.getGenericValue(row, entityNumber)] Start");
}
GenericValue genericValue = (GenericValue) (getContentsRow(row).get(entityNumber));
if (TIMER) {
utilTimer.timerString(5,
"[DataBuffer.getGenericValue(row, entityNumber)] Finished");
}
return genericValue;
}
/**
* DOCUMENT ME!
*
* @param row
* @param entityName
* @param isMandatory
*
* @return
*
* @throws GenericEntityException
*/
public GenericValue getGenericValue(int row, String entityName,
boolean isMandatory) throws GenericEntityException {
// THIS IS SLOW. AVOID USING IT! Try to use getGenericValue(int row, int entityNumber) instead.
UtilTimer utilTimer = new UtilTimer();
if (TIMER) {
utilTimer.timerString(5,
"[DataBuffer.getGenericValue(row, entityName)] Start");
}
Vector contentsRow = getContentsRow(row);
if (contentsRow == null) {
throw new GenericEntityException("Row " + String.valueOf(row) +
" does not exist in the data buffer.");
}
Iterator gVI = getContentsRow(row).iterator();
while (gVI.hasNext()) {
GenericValue testGV = (GenericValue) gVI.next();
if (testGV.getEntityName().equals(entityName)) {
if (TIMER) {
utilTimer.timerString(5,
"[DataBuffer.getGenericValue(row, entityName)] Finished");
}
return testGV;
}
}
if (isMandatory) {
throw new GenericEntityException(
"No generic value was found with name " + entityName);
} else {
return null;
}
}
/**
* DOCUMENT ME!
*
* @param row
* @param entityName
*
* @return
*
* @throws GenericEntityException
*/
public GenericValue getGenericValue(int row, String entityName)
throws GenericEntityException {
return getGenericValue(row, entityName, true);
}
/**
* DOCUMENT ME!
*
* @param entityName
* @param contentsRow
*
* @return
*
* @throws GenericEntityException
*/
public GenericValue getGenericValue(String entityName, Vector contentsRow)
throws GenericEntityException {
// THIS IS SLOW. AVOID USING IT! Try to use getGenericValue(int row, int entityNumber) instead.
UtilTimer utilTimer = new UtilTimer();
if (TIMER) {
utilTimer.timerString(5,
"[DataBuffer.getGenericValue(entityName, contentsRow)] Start");
}
// Find the correct generic value for the specified entity.
GenericValue gV = null;
Iterator contentsRowI = contentsRow.iterator();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -