本文整理汇总了Java中java.sql.Array.getArray方法的典型用法代码示例。如果您正苦于以下问题:Java Array.getArray方法的具体用法?Java Array.getArray怎么用?Java Array.getArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Array
的用法示例。
在下文中一共展示了Array.getArray方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatArrayColumn
import java.sql.Array; //导入方法依赖的package包/类
/**
* Format the column as an java.sqlArray
*
* @param resultSet
* @param columnIndex
* @return
* @throws SQLException
* @throws IOException
*/
private String formatArrayColumn(ResultSet resultSet, int columnIndex)
throws SQLException, IOException {
Array array = resultSet.getArray(columnIndex);
Object[] objects = (Object[]) array.getArray();
String arrayStr = "{";
for (int i = 0; i < objects.length; i++) {
arrayStr += objects[i] + ",";
}
if (arrayStr.contains(",")) {
arrayStr = StringUtils.substringBeforeLast(arrayStr, ",");
}
arrayStr += "}";
return arrayStr;
/*
* ArrayHttp arrayHttp = new ArrayHttp(array); ArrayTransporter
* arrayTransporter = new ArrayTransporter(); String base64 =
* arrayTransporter.toBase64(arrayHttp); return base64;
*/
}
示例2: nullSafeGet
import java.sql.Array; //导入方法依赖的package包/类
@Override
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner)
throws HibernateException, SQLException {
Array array = rs.getArray(names[0]);
if (array == null) {
return null;
}
Long[] javaArray = (Long[]) array.getArray();
ArrayList<Long> result = new ArrayList<>();
Collections.addAll(result, javaArray); //do not use Arrays.asList(), that method returns a fake ArrayList
return result;
}
示例3: testArrayWithOffsets
import java.sql.Array; //导入方法依赖的package包/类
@Test public void testArrayWithOffsets() throws Exception {
// Define the struct type we're creating
ScalarType intType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER);
ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone());
// Create some arrays from the structs
Array array1 = factory.createArray(intType, Arrays.<Object>asList(1, 2));
Array array3 = factory.createArray(intType, Arrays.<Object>asList(4, 5, 6));
Object[] data = (Object[]) array1.getArray(2, 1);
assertEquals(1, data.length);
assertEquals(2, data[0]);
data = (Object[]) array3.getArray(1, 1);
assertEquals(1, data.length);
assertEquals(4, data[0]);
data = (Object[]) array3.getArray(2, 2);
assertEquals(2, data.length);
assertEquals(5, data[0]);
assertEquals(6, data[1]);
data = (Object[]) array3.getArray(1, 3);
assertEquals(3, data.length);
assertEquals(4, data[0]);
assertEquals(5, data[1]);
assertEquals(6, data[2]);
}
示例4: fromSqlArray
import java.sql.Array; //导入方法依赖的package包/类
public Event fromSqlArray ( final Array array ) throws SQLException, ParseException
{
final DateFormat isoDateFormat = new SimpleDateFormat ( isoDatePatterrn );
final EventBuilder eb = Event.create ();
final String[] fields = (String[])array.getArray ();
for ( int i = 0; i < fields.length; i += 2 )
{
final String key = fields[i];
final String value = fields[i + 1];
if ( key.equals ( "id" ) )
{
eb.id ( UUID.fromString ( value ) );
}
else if ( key.equals ( "sourceTimestamp" ) )
{
eb.sourceTimestamp ( isoDateFormat.parse ( value ) );
}
else if ( key.equals ( "entryTimestamp" ) )
{
eb.entryTimestamp ( isoDateFormat.parse ( value ) );
}
else
{
eb.attribute ( key, VariantEditor.toVariant ( value ) );
}
}
return eb.build ();
}
示例5: convertAccessTypes
import java.sql.Array; //导入方法依赖的package包/类
public static Set<Access> convertAccessTypes(ResultSet rs, String fieldName) throws SQLException {
Array accessTypeArray = rs.getArray(fieldName);
if (accessTypeArray != null) {
Integer[] accessTypeIds = (Integer[]) accessTypeArray.getArray();
int[] accessTypeIds2 = new int[accessTypeIds.length];
for (int i=0; i<accessTypeIds.length; i++) {
accessTypeIds2[i] = accessTypeIds[i];
}
return Access.getAccessTypes(accessTypeIds2);
} else {
return null;
}
}
示例6: getArray
import java.sql.Array; //导入方法依赖的package包/类
private Object[] getArray(Array array) {
if (array == null) {
return null;
}
try {
return (Object[]) array.getArray();
} catch (Exception e) {
}
return null;
}
示例7: getArray
import java.sql.Array; //导入方法依赖的package包/类
@Override
public <T> T[] getArray(String columnName, Class<T> arrayElement) throws WrapperAccessException {
try {
Array arr = rs.getArray(columnName);
if (arr != null) {
@SuppressWarnings("unchecked")
T[] ret = (T[]) arr.getArray();
return ret;
}
return null;
} catch (SQLException ex) {
throw new WrapperAccessException(ex.getLocalizedMessage(), ex);
}
}
示例8: getNullableResult
import java.sql.Array; //导入方法依赖的package包/类
@Override
public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
Array array = rs.getArray(columnName);
return array == null ? null : array.getArray();
}
示例9: readData
import java.sql.Array; //导入方法依赖的package包/类
public List<O2MSyncEventLog> readData(Array oraArray) throws SQLException {
List<O2MSyncEventLog> eventLogList = null;
Object[] eventLogArr = (Object[]) oraArray.getArray();
if (eventLogArr != null && eventLogArr.length > 0) {
eventLogList = new ArrayList<O2MSyncEventLog>();
O2MSyncEventLog eventLog = null;
for (int i = 0; i < eventLogArr.length; i++) {
eventLog = new O2MSyncEventLog();
STRUCT attrArrStruct = (STRUCT) eventLogArr[i];
Object [] attrArr = attrArrStruct.getAttributes();
eventLog.setLogId(new ObjectId());
eventLog.setEventId(String.valueOf(attrArr[0]).trim());
eventLog.setOperation(String.valueOf(attrArr[1]));
java.sql.Timestamp crOn = (java.sql.Timestamp) attrArr[2];
if (crOn != null) {
eventLog.setCrOn(new Date(crOn.getTime()));
} else {
eventLog.setCrOn(new Date());
}
ARRAY oraFilters = (ARRAY) attrArr[6];
Object[] filterStructArr = (Object[]) oraFilters.getOracleArray();
if (filterStructArr != null && filterStructArr.length > 0) {
List<O2MSyncEventInfo> filterList = new ArrayList<O2MSyncEventInfo>();
O2MSyncEventInfo filter = null;
for (int j = 0 ; j < filterStructArr.length; j++) {
STRUCT filterAttrArrStruct = (STRUCT) filterStructArr[j];
Object[] filterAttrArr = filterAttrArrStruct.getAttributes();
filter = new O2MSyncEventInfo();
filter.setTableName(String.valueOf(filterAttrArr[0]).trim());
filter.setColumnName(String.valueOf(filterAttrArr[1]).trim());
filter.setColumnValue(String.valueOf(filterAttrArr[2]));
filterList.add(filter);
}
eventLog.setEventFilters(filterList);
}
eventLogList.add(eventLog);
}
}
return eventLogList;
}
示例10: extractUsingArray
import java.sql.Array; //导入方法依赖的package包/类
/**
* Converts an Array into a List using {@link Array#getArray()}. This implementation assumes
* a non-nested array. Use {link {@link #extractUsingResultSet(Array, Calendar)} if nested
* arrays may be possible.
*/
static List<?> extractUsingArray(Array array, Calendar calendar) throws SQLException {
// No option but to guess as to what the type actually is...
Object o = array.getArray();
if (o instanceof List) {
return (List<?>) o;
}
// Assume that it's a Java array.
return AvaticaUtils.primitiveList(o);
}
示例11: setArray
import java.sql.Array; //导入方法依赖的package包/类
/**
* <!-- start generic documentation -->
* Sets the designated parameter to the given <code>java.sql.Array</code> object.
* The driver converts this to an SQL <code>ARRAY</code> value when it
* sends it to the database.
* <!-- end generic documentation -->
*
* <!-- start release-specific documentation -->
* <div class="ReleaseSpecificDocumentation">
* <h3>HSQLDB-Specific Information:</h3> <p>
*
* From version 2.0, HSQLDB supports the SQL ARRAY type.
*
* </div>
* <!-- end release-specific documentation -->
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x an <code>Array</code> object that maps an SQL <code>ARRAY</code> value
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since JDK 1.2 (JDK 1.1.x developers: read the overview for
* JDBCParameterMetaData)
*/
public synchronized void setArray(int parameterIndex,
Array x) throws SQLException {
checkParameterIndex(parameterIndex);
Type type = this.parameterMetaData.columnTypes[parameterIndex - 1];
if (!type.isArrayType()) {
throw JDBCUtil.sqlException(ErrorCode.X_42561);
}
if (x == null) {
setParameter(parameterIndex, null);
return;
}
Object[] data = null;
if (x instanceof JDBCArray) {
data = ((JDBCArray) x).getArrayInternal();
} else {
Object object = x.getArray();
if (object instanceof Object[]) {
Type baseType = type.collectionBaseType();
Object[] array = (Object[]) object;
data = new Object[array.length];
for (int i = 0; i < data.length; i++) {
data[i] = baseType.convertJavaToSQL(session, array[i]);
}
} else {
// if foreign data is not Object[]
throw JDBCUtil.notSupported();
}
}
parameterValues[parameterIndex - 1] = data;
parameterSet[parameterIndex - 1] = Boolean.TRUE;
}
示例12: ArrayHttp
import java.sql.Array; //导入方法依赖的package包/类
public ArrayHttp(Array array) throws SQLException {
baseTypeName = array.getBaseTypeName();
baseType = array.getBaseType();
arrayElements = array.getArray();
}
示例13: setArray
import java.sql.Array; //导入方法依赖的package包/类
/**
* <!-- start generic documentation -->
* Sets the designated parameter to the given <code>java.sql.Array</code> object.
* The driver converts this to an SQL <code>ARRAY</code> value when it
* sends it to the database.
* <!-- end generic documentation -->
*
* <!-- start release-specific documentation -->
* <div class="ReleaseSpecificDocumentation">
* <h3>HSQLDB-Specific Information:</h3> <p>
*
* From version 2.0, HSQLDB supports the SQL ARRAY type.
*
* </div>
* <!-- end release-specific documentation -->
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x an <code>Array</code> object that maps an SQL <code>ARRAY</code> value
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since JDK 1.2 (JDK 1.1.x developers: read the overview for
* JDBCParameterMetaData)
*/
public synchronized void setArray(int parameterIndex,
Array x) throws SQLException {
checkParameterIndex(parameterIndex);
Type type = this.parameterMetaData.columnTypes[parameterIndex - 1];
if (!type.isArrayType()) {
throw JDBCUtil.sqlException(ErrorCode.X_42561);
}
if (x == null) {
setParameter(parameterIndex, null);
return;
}
Object[] data = null;
if (x instanceof JDBCArray) {
data = (Object[]) ((JDBCArray) x).getArrayInternal();
} else {
Object object = x.getArray();
if (object instanceof Object[]) {
Type baseType = type.collectionBaseType();
Object[] array = (Object[]) object;
data = new Object[array.length];
for (int i = 0; i < data.length; i++) {
data[i] = baseType.convertJavaToSQL(session, array[i]);
}
} else {
// if foreign data is not Object[]
throw JDBCUtil.notSupported();
}
}
parameterValues[parameterIndex - 1] = data;
parameterSet[parameterIndex - 1] = Boolean.TRUE;
}