本文整理匯總了Java中org.databene.commons.ArrayUtil類的典型用法代碼示例。如果您正苦於以下問題:Java ArrayUtil類的具體用法?Java ArrayUtil怎麽用?Java ArrayUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ArrayUtil類屬於org.databene.commons包,在下文中一共展示了ArrayUtil類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: update
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
public String update(DBTable table, String[] pkColumnNames, List<ColumnInfo> columnInfos) {
if (pkColumnNames.length == 0)
throw new UnsupportedOperationException("Cannot update table without primary key: " + table.getName());
StringBuilder builder = new StringBuilder("update ");
appendQualifiedTableName(table, builder).append(" set");
for (int i = 0; i < columnInfos.size(); i++) {
if (!ArrayUtil.contains(columnInfos.get(i).name, pkColumnNames)) {
builder.append(" ");
appendColumnName(columnInfos.get(i).name, builder);
builder.append("=?");
if (i < columnInfos.size() - pkColumnNames.length - 1)
builder.append(", ");
}
}
builder.append(" where");
for (int i = 0; i < pkColumnNames.length; i++) {
builder.append(' ');
appendColumnName(pkColumnNames[i], builder);
builder.append("=?");
if (i < pkColumnNames.length - 1)
builder.append(" and");
}
String sql = builder.toString();
logger.debug("built SQL statement: " + sql);
return sql;
}
示例2: queryScalarRow
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
public static <T> T[] queryScalarRow(String query, Class<T> componentType, Connection connection) {
Statement statement = null;
ResultSet resultSet = null;
try {
statement = connection.createStatement();
resultSet = statement.executeQuery(query);
assertNext(resultSet, query);
int columnCount = columnCount(resultSet);
T[] result = ArrayUtil.newInstance(componentType, columnCount);
for (int i = 0; i < columnCount; i++)
Array.set(result, i, AnyConverter.convert(resultSet.getObject(i + 1), componentType));
assertNoNext(resultSet, query);
return result;
} catch (SQLException e) {
throw new RuntimeException("Database query failed: " + query, e);
} finally {
closeResultSetAndStatement(resultSet, statement);
}
}
示例3: createNkPkIterator
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
@Override
public TabularIterator createNkPkIterator(
Connection connection, String dbId, KeyMapper mapper, Database database) {
String[] pkColumnNames = database.getTable(tableName).getPKColumnNames();
if (ArrayUtil.isEmpty(pkColumnNames))
throw new ConfigurationError("Table '" + tableName + "' has no primary key");
StringBuilder builder = new StringBuilder("select ");
builder.append(pkColumnNames[0]);
for (int i = 1; i < pkColumnNames.length; i++)
builder.append(" || '|' || ").append(pkColumnNames[i]);
for (String pkColumnName : pkColumnNames)
builder.append(", ").append(pkColumnName);
builder.append(" from ").append(tableName);
String query = builder.toString();
return query(query, connection);
}
示例4: createNkPkIterator
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
@Override
public TabularIterator createNkPkIterator(
Connection connection, String dbId, KeyMapper mapper, Database database) {
if (ArrayUtil.isEmpty(columnNames))
throw new ConfigurationError("No unique key columns defined");
StringBuilder builder = new StringBuilder("select ");
builder.append(columnNames[0]);
for (int i = 1; i < columnNames.length; i++)
builder.append(", ").append(columnNames[i]);
String[] pkColumnNames = database.getTable(tableName).getPKColumnNames();
for (String columnName : pkColumnNames)
builder.append(", ").append(columnName);
builder.append(" from ").append(tableName);
String query = builder.toString();
TabularIterator rawIterator = query(query, connection);
ColumnToNkConverter converter = new ColumnToNkConverter(dbId, mapper);
return new UniqueKeyNkPkIterator(rawIterator, converter, pkColumnNames);
}
示例5: doParse
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
@Override
public Statement doParse(Element element, Statement[] parentPath, BeneratorParseContext context) {
String table = getAttribute(ATT_TABLE, element);
TranscodingTaskStatement parent = (TranscodingTaskStatement) ArrayUtil.lastElementOf(parentPath);
Expression<DBSystem> sourceEx = parseSource(element, parent);
Expression<String> selectorEx = parseSelector(element, parent);
Expression<DBSystem> targetEx = parseTarget(element, parent);
Expression<Long> pageSizeEx = parsePageSize(element, parent);
Expression<ErrorHandler> errorHandlerEx = parseOnErrorAttribute(element, table);
TranscodeStatement result = new TranscodeStatement(new MutatingTypeExpression(element, getRequiredAttribute("table", element)),
parent, sourceEx, selectorEx, targetEx, pageSizeEx, errorHandlerEx);
Statement[] currentPath = context.createSubPath(parentPath, result);
for (Element child : XMLUtil.getChildElements(element)) {
String childName = child.getNodeName();
if (!MEMBER_ELEMENTS.contains(childName))
result.addSubStatement(context.parseChildElement(child, currentPath));
// The 'component' child elements (id, attribute, reference) are handled by the MutatingTypeExpression
}
return result;
}
示例6: generate
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
@Override
public P generate() {
Integer size = generateCardinal();
if (size == null)
return null;
// the following works for primitive types as well as for objects
@SuppressWarnings("unchecked")
P array = (P) ArrayUtil.newInstance(componentType, size.intValue());
for (int i = 0; i < size; i++) {
ProductWrapper<S> component = generateFromSource();
if (component == null)
return null;
Array.set(array, i, component.unwrap());
}
return array;
}
示例7: checkCells
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
private void checkCells(HSSFRow row, Object... values) {
if (ArrayUtil.isEmpty(values))
assertNull(row);
for (int i = 0; i < values.length; i++) {
HSSFCell cell = row.getCell(i);
Object expectedContent = values[i];
if (expectedContent == null)
assertNull(cell);
else if (expectedContent instanceof String) {
assertEquals(HSSFCell.CELL_TYPE_STRING, cell.getCellType());
assertEquals(expectedContent, cell.getStringCellValue());
} else if (expectedContent instanceof Number) {
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cell.getCellType());
assertEquals(((Number) expectedContent).doubleValue(), cell.getNumericCellValue());
} else if (expectedContent instanceof Boolean) {
assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, cell.getCellType());
assertEquals(expectedContent, cell.getBooleanCellValue());
} else if (expectedContent instanceof Date) {
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cell.getCellType());
assertEquals(((Date) expectedContent).getTime() / 1000, cell.getDateCellValue().getTime() / 1000); // cut off milliseconds
} else
throw new RuntimeException("Type not supported: " + expectedContent.getClass());
}
}
示例8: checkSequence
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
private void checkSequence(Character[] sequence, int depth) {
String seqString = ArrayFormat.format(sequence);
assertNotNull(sequence);
assertTrue(sequence.length > 0);
for (Character c : sequence)
assertTrue(c >= '0' && c <= '2');
if (depth > 1) {
assertEquals('0', (char) sequence[0]);
char lastAtom = ArrayUtil.lastElementOf(sequence);
assertTrue("Expected last atom to be '1' or '2': " + seqString, lastAtom == '1' || lastAtom == '2');
assertTrue(ArrayUtil.contains('0', sequence));
assertTrue(ArrayUtil.contains('1', sequence));
}
if (depth >= 4) {
assertTrue(
Arrays.deepEquals(sequence, SAMPLE1) ||
Arrays.deepEquals(sequence, SAMPLE2) ||
Arrays.deepEquals(sequence, SAMPLE3)
);
}
}
示例9: testSimpleProjectArchetype
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
@Test
public void testSimpleProjectArchetype() throws Exception {
// prepare
Archetype simple = new Archetype(new URL(ArchetypeManager.ARCHETYPE_FOLDER_URL.toString() + "/simple"));
File targetFolder = new File("target/simple");
FileUtil.deleteIfExists(targetFolder);
// run
simple.copyFilesTo(targetFolder, new EclipseFolderLayout());
// verify
String[] createdFiles = targetFolder.list();
// check that benerator.xml was copied from the archetype
assertTrue(ArrayUtil.contains("benerator.xml", createdFiles));
// check that benerator xsd was copied from the classpath
String schemaPath = StringUtil.splitOnLastSeparator(BeneratorFactory.getSchemaPathForCurrentVersion(), '/')[1];
assertTrue("File not found: " + schemaPath, ArrayUtil.contains(schemaPath, createdFiles));
// check that src/main/resources is mapped to src in Eclipse projects
File src = new File(targetFolder, "src");
assertTrue(src.exists());
assertTrue(src.isDirectory());
assertTrue(ArrayUtil.contains("log4j.xml", src.list()));
// check that ARCHETYPE-INF was not copied
assertFalse(ArrayUtil.contains("ARCHETYPE-INF", createdFiles));
}
示例10: addColumn
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
public void addColumn(short ordinalPosition, String columnName) {
int expectedPosition = columnNames.length + 1;
if (ordinalPosition == expectedPosition)
columnNames = ArrayUtil.append(columnName, columnNames);
else {
if (ordinalPosition > expectedPosition || !columnNames[ordinalPosition - 1].equals(columnName))
throw new IllegalArgumentException("ordinalPosition is expected to be " + expectedPosition + ", " +
"found: " + ordinalPosition);
}
}
示例11: parseFK
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
private static DBForeignKeyConstraint parseFK(Element e, DBTable owner, DBSchema schema) {
String name = e.getAttribute("name");
String refereeTableName = e.getAttribute("refereeTable");
DBTable refereeTable = schema.getTable(refereeTableName);
Assert.notNull(refereeTable, "refereeTable");
String colAttr = e.getAttribute("column");
String[] columnNames = null;
String[] refereeColumnNames = null;
if (!StringUtil.isEmpty(colAttr)) {
columnNames = new String[] { colAttr };
refereeColumnNames = new String[] { e.getAttribute("refereeColumn") };
} else {
Element colsElement = XMLUtil.getChildElement(e, false, true, "columns");
Element[] colElements = XMLUtil.getChildElements(colsElement, false, "column");
for (Element colElement : colElements) {
columnNames = ArrayUtil.append(colElement.getAttribute("name"), columnNames);
refereeColumnNames = ArrayUtil.append(colElement.getAttribute("refereeColumn"), refereeColumnNames);
}
}
boolean autoNamed = false;
if (e.getAttribute("autoNamed") != null)
autoNamed = Boolean.valueOf(e.getAttribute("autoNamed"));
DBForeignKeyConstraint fk = new DBForeignKeyConstraint(name, autoNamed, owner, columnNames, refereeTable, refereeColumnNames);
// parse rules
String updateRule = XMLUtil.getAttribute(e, "updateRule", false);
if (!StringUtil.isEmpty(updateRule))
fk.setUpdateRule(FKChangeRule.valueOf(updateRule));
String deleteRule = XMLUtil.getAttribute(e, "deleteRule", false);
if (!StringUtil.isEmpty(deleteRule))
fk.setDeleteRule(FKChangeRule.valueOf(deleteRule));
return fk;
}
示例12: parseColumnNames
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
public String[] parseColumnNames(Element e) {
String colAttr = e.getAttribute("column");
String[] columnNames = null;
if (!StringUtil.isEmpty(colAttr))
columnNames = new String[] { colAttr };
else {
Element colsElement = XMLUtil.getChildElement(e, false, true, "columns");
Element[] colElements = XMLUtil.getChildElements(colsElement, false, "column");
for (Element colElement : colElements)
columnNames = ArrayUtil.append(colElement.getAttribute("name"), columnNames);
}
return columnNames;
}
示例13: columnReferencedBy
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
public String columnReferencedBy(String fkColumnName, boolean required) {
int index = ArrayUtil.indexOf(fkColumnName, fkColumnNames);
if (index < 0) {
if (required)
throw new ObjectNotFoundException("foreign key '" + name + "' does not have a column '" + fkColumnName + "'");
else
return null;
}
return refereeColumnNames[index];
}
示例14: testRunScript
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
@Test
public void testRunScript() throws Exception {
Connection connection = HSQLUtil.connectInMemoryDB(getClass().getSimpleName());
ErrorHandler errorHandler = new ErrorHandler(getClass());
DBExecutionResult result = DBUtil.executeScriptFile(SCRIPT_FILE, Encodings.ISO_8859_1, connection, true, errorHandler);
assertTrue(result.changedStructure);
Object[][] rows = (Object[][]) DBUtil.queryAndSimplify("select * from T1", connection);
assertEquals(1, rows.length);
assertTrue(Arrays.equals(ArrayUtil.buildObjectArrayOfType(Object.class, 1, "R&B"), rows[0]));
int count = (Integer) DBUtil.queryAndSimplify("select count(*) from T1", connection);
assertEquals(1, count);
}
示例15: getData
import org.databene.commons.ArrayUtil; //導入依賴的package包/類
/** Returns the data elements for this test case, in the order of the parameter list of the test case method. May be an empty
* array if the test case method does not require any parameters. Otherwise, it must have as many entries as the method's
* parameter list.
*
* @return The data elements for this test case, maybe empty, but never <code>null</code>. */
public Data[] getData() {
if (dataSource != null) {
Data[] sourceData = dataSource.getData();
return (sourceData == null) ? new Data[0] : ArrayUtil.copyOfRange(sourceData, 0, sourceData.length);
}
return data;
}