use of org.teiid.core.types.SQLXMLImpl in project teiid by teiid.
the class TransformationMetadata method getXMLSchemas.
public List<SQLXMLImpl> getXMLSchemas(final Object groupID) throws TeiidComponentException, QueryMetadataException {
Table tableRecord = (Table) groupID;
// lookup transformation record for the group
String groupName = tableRecord.getFullName();
// get the schema Paths
List<String> schemaPaths = tableRecord.getSchemaPaths();
List<SQLXMLImpl> schemas = new LinkedList<SQLXMLImpl>();
if (schemaPaths == null) {
return schemas;
}
String path = getParentPath(tableRecord.getResourcePath());
for (String string : schemaPaths) {
String parentPath = path;
boolean relative = false;
while (string.startsWith("../")) {
// $NON-NLS-1$
relative = true;
string = string.substring(3);
parentPath = getParentPath(parentPath);
}
SQLXMLImpl schema = null;
if (!relative) {
schema = getVDBResourceAsSQLXML(string);
}
if (schema == null) {
if (!parentPath.endsWith("/")) {
// $NON-NLS-1$
// $NON-NLS-1$
parentPath += "/";
}
schema = getVDBResourceAsSQLXML(parentPath + string);
}
if (schema == null) {
throw new QueryMetadataException(QueryPlugin.Event.TEIID30364, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30364, groupName));
}
schemas.add(schema);
}
return schemas;
}
use of org.teiid.core.types.SQLXMLImpl in project teiid by teiid.
the class ResultSetImpl method getObjectDirect.
/**
* Get the value of the current row at the column index specified.
* @param column Column index
* @return Value at column, which may be null
* @throws SQLException if this result set has an exception
*/
public Object getObjectDirect(int column) throws SQLException {
checkClosed();
if (column < 1 || column > columnCount) {
// $NON-NLS-1$
throw new IllegalArgumentException(JDBCPlugin.Util.getString("ResultsImpl.Invalid_col_index", column));
}
List<?> cursorRow = batchResults.getCurrentRow();
if (cursorRow == null) {
// $NON-NLS-1$
throw new TeiidSQLException(JDBCPlugin.Util.getString("ResultsImpl.The_cursor_is_not_on_a_valid_row._1"));
}
// defect 13539 - set the currentValue (defined in MMResultSet) so that wasNull() accurately returns whether this value was null
currentValue = cursorRow.get(column - 1);
if (currentValue instanceof Streamable<?>) {
Object reference = ((Streamable<?>) currentValue).getReference();
if (reference != null) {
return reference;
}
if (currentValue instanceof ClobType) {
return new ClobImpl(createInputStreamFactory((ClobType) currentValue), ((ClobType) currentValue).getLength());
} else if (currentValue instanceof BlobType) {
InputStreamFactory isf = createInputStreamFactory((BlobType) currentValue);
isf.setLength(((BlobType) currentValue).getLength());
return new BlobImpl(isf);
} else if (currentValue instanceof XMLType) {
XMLType val = (XMLType) currentValue;
SQLXMLImpl impl = new SQLXMLImpl(createInputStreamFactory(val));
impl.setEncoding(val.getEncoding());
return impl;
}
} else if (currentValue instanceof java.util.Date) {
return TimestampWithTimezone.create((java.util.Date) currentValue, serverTimeZone, getDefaultCalendar(), currentValue.getClass());
} else if (maxFieldSize > 0 && currentValue instanceof String) {
String val = (String) currentValue;
return val.substring(0, Math.min(maxFieldSize / 2, val.length()));
} else if (currentValue instanceof BinaryType) {
BinaryType val = (BinaryType) currentValue;
return val.getBytesDirect();
}
return currentValue;
}
use of org.teiid.core.types.SQLXMLImpl in project teiid by teiid.
the class ODataSQLBuilder method updateStreamProperty.
public Update updateStreamProperty(EdmProperty edmProperty, final InputStream content) throws TeiidException {
Update update = new Update();
update.setGroup(this.context.getGroupSymbol());
Column column = this.context.getColumnByName(edmProperty.getName());
ElementSymbol symbol = new ElementSymbol(column.getName(), this.context.getGroupSymbol());
update.addChange(symbol, new Reference(0));
Class<?> lobType = DataTypeManager.getDataTypeClass(column.getRuntimeType());
int sqlType = JDBCSQLTypeInfo.getSQLType(column.getRuntimeType());
if (content == null) {
this.params.add(new SQLParameter(null, sqlType));
} else {
Object value = null;
InputStreamFactory isf = new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return content;
}
};
if (lobType.isAssignableFrom(SQLXML.class)) {
value = new SQLXMLImpl(isf);
} else if (lobType.isAssignableFrom(ClobType.class)) {
value = new ClobImpl(isf, -1);
} else if (lobType.isAssignableFrom(BlobType.class)) {
value = new BlobImpl(isf);
} else {
throw new TeiidException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16031, column.getName()));
}
this.params.add(new SQLParameter(value, sqlType));
}
update.setCriteria(this.context.getCriteria());
return update;
}
use of org.teiid.core.types.SQLXMLImpl in project teiid by teiid.
the class TestEmbeddedServer method testSourceLobUnderTxn.
@Test
public void testSourceLobUnderTxn() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setMaxResultSetCacheStaleness(0);
MockTransactionManager tm = new MockTransactionManager();
ec.setTransactionManager(tm);
ec.setUseDisk(false);
es.start(ec);
final AtomicBoolean closed = new AtomicBoolean();
es.addTranslator("foo", new ExecutionFactory() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
return new ResultSetExecution() {
private boolean returned;
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
closed.set(true);
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (returned) {
return null;
}
returned = true;
ArrayList<Object> result = new ArrayList<Object>(1);
result.add(new SQLXMLImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
// need to make it of a sufficient size to not be inlined
return new ByteArrayInputStream(new byte[DataTypeManager.MAX_LOB_MEMORY_BYTES + 1]);
}
}));
return result;
}
};
}
});
es.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\"><source name=\"foo\" translator-name=\"foo\"/><metadata type=\"DDL\"><![CDATA[CREATE foreign table x (y xml);]]> </metadata></model></vdb>".getBytes()));
Connection c = es.getDriver().connect("jdbc:teiid:test", null);
c.setAutoCommit(false);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from x");
rs.next();
assertFalse(closed.get());
s.close();
assertTrue(closed.get());
}
Aggregations