Java Code Examples for java.sql.Array#getArray()
The following examples show how to use
java.sql.Array#getArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractCopySQLData.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
/** * Sets the Jetel attribute of the CopyString object * * @param resultSet The new Jetel value * @exception SQLException Description of Exception * @since October 7, 2002 */ @Override public void setJetel(ResultSet resultSet) throws SQLException { Array fieldVal = resultSet.getArray(fieldSQL); Object obj = fieldVal.getArray(); Object [] objectArray = (Object []) obj; // cast it to an array of objects StringBuffer buffer = new StringBuffer("{"); buffer.append(String.valueOf(objectArray[0])); for (int j=1; j < objectArray.length; j++) { buffer.append(", ").append(String.valueOf(objectArray[j])); } buffer.append("}"); if (resultSet.wasNull()) { ((StringDataField) field).setValue((Object)null); } else { ((StringDataField) field).setValue(buffer.toString()); } }
Example 2
Source File: UtilAdapter.java From importer-exporter with Apache License 2.0 | 6 votes |
@Override protected String[] createDatabaseReport(String schema, Connection connection) throws SQLException { try { interruptableCallableStatement = connection.prepareCall("{? = call " + databaseAdapter.getSQLAdapter().resolveDatabaseOperationName("citydb_stat.table_contents") + "(?)}"); interruptableCallableStatement.registerOutParameter(1, Types.ARRAY); interruptableCallableStatement.setString(2, schema); interruptableCallableStatement.executeUpdate(); Array result = interruptableCallableStatement.getArray(1); return (String[]) result.getArray(); } catch (SQLException e) { if (!isInterrupted) throw e; } finally { if (interruptableCallableStatement != null) { interruptableCallableStatement.close(); interruptableCallableStatement = null; } isInterrupted = false; } return null; }
Example 3
Source File: PArrayDataType.java From phoenix with Apache License 2.0 | 6 votes |
/** * Ensures that the provided {@code object} is a PhoenixArray, attempting a conversion in the * case when it is not. */ PhoenixArray toPhoenixArray(Object object, PDataType baseType) { if (object instanceof PhoenixArray) { return (PhoenixArray) object; } if (!(object instanceof Array)) { throw new IllegalArgumentException("Expected an Array but got " + object.getClass()); } Array arr = (Array) object; try { Object untypedArrayData = arr.getArray(); if (!(untypedArrayData instanceof Object[])) { throw new IllegalArgumentException("Array data is required to be Object[] but data for " + arr.getClass() + " is " + untypedArrayData.getClass()); } return this.getArrayFactory().newArray(baseType, (Object[]) untypedArrayData); } catch (SQLException e) { throw new IllegalArgumentException("Could not convert Array data", e); } }
Example 4
Source File: AbstractCopySQLData.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void setJetel(CallableStatement statement) throws SQLException { Array fieldVal = statement.getArray(fieldSQL); Object obj = fieldVal.getArray(); Object [] objectArray = (Object []) obj; // cast it to an array of objects StringBuffer buffer = new StringBuffer("{"); buffer.append(String.valueOf(objectArray[0])); for (int j=1; j < objectArray.length; j++) { buffer.append(", ").append(String.valueOf(objectArray[j])); } buffer.append("}"); if (statement.wasNull()) { ((StringDataField) field).setValue((Object)null); } else { ((StringDataField) field).setValue(buffer.toString()); } }
Example 5
Source File: RegexpSplitFunctionIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testSplit_DynamicPattern() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); initTable(conn, "ONE,TWO,THREE"); ResultSet rs = conn.createStatement().executeQuery( "SELECT REGEXP_SPLIT(VAL, SEP) FROM " + tableName); assertTrue(rs.next()); Array array = rs.getArray(1); String[] values = (String[]) array.getArray(); assertArrayEquals(new String[] { "ONE", "TWO", "THREE" }, values); }
Example 6
Source File: BooleanArrayTypeHandler.java From mmpt with MIT License | 5 votes |
@Override public Boolean[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { Array outputArray = cs.getArray(columnIndex); if (outputArray == null) { return null; } return (Boolean[])outputArray.getArray(); }
Example 7
Source File: BigIntArrayTypeHandler.java From mmpt with MIT License | 5 votes |
@Override public Long[] getNullableResult(ResultSet rs, String columnName) throws SQLException { Array outputArray = rs.getArray(columnName); if (outputArray == null) { return null; } return (Long[])outputArray.getArray(); }
Example 8
Source File: RegexpSplitFunctionIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testSplit_DynamicPattern() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); initTable(conn, "ONE,TWO,THREE"); ResultSet rs = conn.createStatement().executeQuery( "SELECT REGEXP_SPLIT(VAL, SEP) FROM SPLIT_TEST"); assertTrue(rs.next()); Array array = rs.getArray(1); String[] values = (String[]) array.getArray(); assertArrayEquals(new String[] { "ONE", "TWO", "THREE" }, values); }
Example 9
Source File: Tools.java From flowchat with GNU General Public License v3.0 | 5 votes |
public static <T> List<T> convertArrayToList(Array arr) { try { T[] larr = (T[]) arr.getArray(); List<T> list = new ArrayList<>(Arrays.asList(larr)); return list; } catch(SQLException e) { e.printStackTrace(); } return null; }
Example 10
Source File: DocumentFieldValueLoaders.java From metasfresh-webui-api-legacy with GNU General Public License v3.0 | 5 votes |
private static DisplayNameAndDescription extractDisplayNameAndDescription( @NonNull final ResultSet rs, final String sqlDisplayColumnName, final String adLanguage) throws SQLException { final ITranslatableString displayName; final ITranslatableString description; final Array array = rs.getArray(sqlDisplayColumnName); if (array == null) { displayName = TranslatableStrings.empty(); description = TranslatableStrings.empty(); } else { final String[] nameAndDescription = (String[])array.getArray(); displayName = TranslatableStrings.singleLanguage(adLanguage, nameAndDescription[0]); final boolean hasDescription = nameAndDescription.length > 1; if (hasDescription) { description = TranslatableStrings.singleLanguage(adLanguage, nameAndDescription[1]); } else { description = TranslatableStrings.empty(); } } return new DisplayNameAndDescription(displayName, description); }
Example 11
Source File: RegexpSplitFunctionIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testSplit_PatternEscape() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); initTable(conn, "ONE|TWO|THREE"); ResultSet rs = conn.createStatement().executeQuery( "SELECT REGEXP_SPLIT(VAL, '\\\\|') FROM SPLIT_TEST"); assertTrue(rs.next()); Array array = rs.getArray(1); String[] values = (String[]) array.getArray(); assertArrayEquals(new String[] { "ONE", "TWO", "THREE" }, values); }
Example 12
Source File: RegexpSplitFunctionIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testSplit_AlternateSeparator() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); initTable(conn, "ONE:TWO:THREE"); ResultSet rs = conn.createStatement().executeQuery( "SELECT REGEXP_SPLIT(VAL, ':') FROM " + tableName); assertTrue(rs.next()); Array array = rs.getArray(1); String[] values = (String[]) array.getArray(); assertArrayEquals(new String[] { "ONE", "TWO", "THREE" }, values); }
Example 13
Source File: BigIntArrayTypeHandler.java From mmpt with MIT License | 5 votes |
@Override public Long[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { Array outputArray = cs.getArray(columnIndex); if (outputArray == null) { return null; } return (Long[])outputArray.getArray(); }
Example 14
Source File: EventConverter.java From neoscada with Eclipse Public License 1.0 | 5 votes |
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 (); }
Example 15
Source File: GClause.java From tuffylite with Apache License 2.0 | 4 votes |
/** * Initialize GClause from results of SQL. This involves set * $cid$ to {@link GClause#id}, $weight$ {@link GClause#weight}, * $lits$ to {@link GClause#lits}, $fcid$ to {@link GClause#fcid}. * @param rs the ResultSet for SQL. This sql is a sequential * scan on table {@link Config#relClauses}. * */ public void parse(ResultSet rs){ try { id = rs.getInt("cid"); weight = rs.getDouble("weight"); Array a = rs.getArray("lits"); int[] atomIdsInClause = new int[Config.maxAtomId]; Integer[] ilits = (Integer[]) a.getArray(); lits = new int[ilits.length]; for(int i=0; i<lits.length; i++){ if (ilits[i] < Config.maxAtomId) { if (atomIdsInClause[Math.abs(ilits[i])] != 0) { if (Math.signum(ilits[i]) != atomIdsInClause[Math.abs(ilits[i])]) { lits[i] = ilits[i]; // just add to certify the tautology tautology = true; return; } } else { atomIdsInClause[Math.abs(ilits[i])] = (int) Math.signum(ilits[i]); } } lits[i] = ilits[i]; } if(Config.track_clause_provenance){ Array fc = rs.getArray("fcid"); Integer[] ifc = (Integer[]) fc.getArray(); ArrayList<Integer> lfcid = new ArrayList<Integer>(); for(int i=0; i< ifc.length; i++){ // ignoring soft evidence unit clauses if(ifc[i] != null && ifc[i] != 0){ lfcid.add(ifc[i]); // ADDED BY CE ON NOV. 29 if(Math.abs(ifc[i]) > GClause.maxFCID){ GClause.maxFCID = Math.abs(ifc[i]); } } } fcid = new int[lfcid.size()]; for(int i=0; i<fcid.length; i++){ fcid[i] = lfcid.get(i); } fc = rs.getArray("ffcid"); String[] sfc = (String[]) fc.getArray(); ArrayList<String> lsfc = new ArrayList<String>(); for(int i=0; i< sfc.length; i++){ // ignoring soft evidence unit clauses if(sfc[i] != null && sfc[i] != "0"){ lsfc.add(sfc[i]); } } ffcid = new String[lsfc.size()]; for(int i=0; i<ffcid.length; i++){ ffcid[i] = lsfc.get(i); } } } catch (Exception e) { ExceptionMan.handle(e); } }
Example 16
Source File: ArrayTypeHandler.java From mybaties with Apache License 2.0 | 4 votes |
@Override public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { Array array = cs.getArray(columnIndex); return array == null ? null : array.getArray(); }
Example 17
Source File: ArrayTypeHandler.java From tangyuan2 with GNU General Public License v3.0 | 4 votes |
@Override public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { Array array = cs.getArray(columnIndex); return array == null ? null : array.getArray(); }
Example 18
Source File: ArrayTypeHandler.java From tangyuan2 with GNU General Public License v3.0 | 4 votes |
@Override public Object getNullableResult(ResultSet rs, String columnName) throws SQLException { Array array = rs.getArray(columnName); return array == null ? null : array.getArray(); }
Example 19
Source File: ArrayTypeHandler.java From mybatis with Apache License 2.0 | 4 votes |
@Override public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException { Array array = rs.getArray(columnIndex); return array == null ? null : array.getArray(); }
Example 20
Source File: PostgreSQLTypeFunctions.java From binnavi with Apache License 2.0 | 4 votes |
/** * Loads all {@link RawTypeSubstitution} for the given module from the database. * * @param connection The {@link Connection} to access the database with. * @param module The {@link INaviModule} to load the {@link RawTypeSubstitution} for. * * @return The {@link List} of {@link RawTypeSubstitution} for the given {@link INaviModule}. * * @throws CouldntLoadDataException if the {@link RawTypeSubstitution} could not be loaded from * the database. */ public static List<RawTypeSubstitution> loadRawTypeSubstitutions(final Connection connection, final INaviModule module) throws CouldntLoadDataException { Preconditions.checkNotNull(connection, "Error: connection argument can not be null"); Preconditions.checkNotNull(module, "Error: module argument can not be null"); final String query = " SELECT * FROM load_type_substitutions(?) "; final List<RawTypeSubstitution> rawSubstitutions = new ArrayList<RawTypeSubstitution>(); try { final PreparedStatement statement = connection.prepareStatement(query); statement.setInt(1, module.getConfiguration().getId()); final ResultSet results = statement.executeQuery(); try { while (results.next()) { final long address = results.getLong("address"); final int position = results.getInt("position"); final int expressionId = results.getInt("expression_id"); final int baseTypeId = results.getInt("base_type_id"); final Array arr = results.getArray("path"); Integer[] path = (Integer[]) arr.getArray(); if (results.wasNull()) { path = new Integer[0]; } Integer offset = results.getInt("offset"); if (results.wasNull()) { offset = null; } rawSubstitutions.add(new RawTypeSubstitution(new CAddress(address), position, expressionId, baseTypeId, path, offset)); } } finally { results.close(); statement.close(); } } catch (final SQLException exception) { throw new CouldntLoadDataException(exception); } return rawSubstitutions; }