@Override protected Object readObject(ObjectInput in, List<Object> cache, byte version) throws IOException, ClassNotFoundException { ClobType ct = new ClobType(); ct.readExternal(in); return ct; } }
@Override protected Object readObject(ObjectInput in, List<Object> cache, byte version) throws IOException, ClassNotFoundException { ClobType ct = new ClobType(); ct.readExternal(in); return ct; } }
/** * This method transforms a value of the source type into a value * of the target type. * @param value Incoming value of source type * @return Outgoing value of target type * @throws TransformationException if value is an incorrect input type or * the transformation fails */ public Object transformDirect(Object value) throws TransformationException { String contents = (String)value; //TODO: if the value is too large, we should store in a file buffer return new ClobType(new ClobImpl(contents)); }
public static ClobType geometryToClob(AbstractGeospatialType geometry, boolean withSrid) throws FunctionExecutionException { Geometry jtsGeometry = getGeometry(geometry); int srid = jtsGeometry.getSRID(); StringBuilder geomText = new StringBuilder(); if (withSrid && srid != GeometryType.UNKNOWN_SRID) { geomText.append("SRID=").append(jtsGeometry.getSRID()).append(";"); //$NON-NLS-1$ //$NON-NLS-2$ } geomText.append(jtsGeometry.toText()); return new ClobType(new ClobImpl(geomText.toString())); }
public static ClobType geometryToClob(GeometryType geometry, boolean withSrid) throws FunctionExecutionException { Geometry jtsGeometry = getGeometry(geometry); int srid = jtsGeometry.getSRID(); StringBuilder geomText = new StringBuilder(); if (withSrid && srid != GeometryType.UNKNOWN_SRID) { geomText.append("SRID=").append(jtsGeometry.getSRID()).append(";"); //$NON-NLS-1$ //$NON-NLS-2$ } geomText.append(jtsGeometry.toText()); return new ClobType(new ClobImpl(geomText.toString())); }
private static Object asLob(InputStreamFactory value, Class<?> desiredType) { if (desiredType == DataTypeManager.DefaultDataClasses.CLOB) { //assumes UTF-8 return new ClobType(new ClobImpl(value, -1)); } return new BlobType(new BlobImpl(value)); }
@Test public void testClobCompare() throws Exception { String testString = "this is test clob"; //$NON-NLS-1$ SerialClob clob = new SerialClob(testString.toCharArray()); ClobType ct = new ClobType(clob); SerialClob clob1 = new SerialClob(testString.toCharArray()); ClobType ct1 = new ClobType(clob1); assertEquals(0, ct1.compareTo(ct)); }
public static ClobType lowerCase(ClobType str) { return new ClobType(new ClobImpl(new ClobInputStreamFactory(str) { @Override public Reader getReader(Reader reader) { return new UpperLowerReader(reader, false); } }, str.getLength())); }
public static ClobType upperCase(ClobType str) { return new ClobType(new ClobImpl(new ClobInputStreamFactory(str) { @Override public Reader getReader(Reader reader) { return new UpperLowerReader(reader, true); } }, str.getLength())); }
public static ClobType upperCase(ClobType str) { return new ClobType(new ClobImpl(new ClobInputStreamFactory(str) { @Override public Reader getReader(Reader reader) { return new UpperLowerReader(reader, true); } }, str.getLength())); }
public static ClobType upperCase(ClobType str) { return new ClobType(new ClobImpl(new ClobInputStreamFactory(str) { @Override public Reader getReader(Reader reader) { return new UpperLowerReader(reader, true); } }, str.getLength())); }
public static ClobType lowerCase(ClobType str) { return new ClobType(new ClobImpl(new ClobInputStreamFactory(str) { @Override public Reader getReader(Reader reader) { return new UpperLowerReader(reader, false); } }, str.getLength())); }
public static ClobType lowerCase(ClobType str) { return new ClobType(new ClobImpl(new ClobInputStreamFactory(str) { @Override public Reader getReader(Reader reader) { return new UpperLowerReader(reader, false); } }, str.getLength())); }
@Test public void testUpperLowerClob() throws Exception { char[] val = new char[] {87, 122, 147, 0xD801, 0xDC37}; assertEquals(new String(val).toUpperCase(), ClobType.getString(FunctionMethods.upperCase(new ClobType(ClobImpl.createClob(val))))); assertEquals(new String(val).toLowerCase(), ClobType.getString(FunctionMethods.lowerCase(new ClobType(ClobImpl.createClob(val))))); }
@TeiidFunction(name=SourceSystemFunctions.REGEXP_REPLACE, category=FunctionCategoryConstants.STRING, nullOnNull=true) public static ClobType regexpReplace(CommandContext context, ClobType source, String regex, String replacement, String flags) throws FunctionExecutionException { //TODO: this is not very memory safe - we can write out to the buffermanger if needed String result = regexpReplace(context, source.getCharSequence(), regex, replacement, flags); return new ClobType(new ClobImpl(result)); }
@Test public void testGmlParseSrid() throws Exception { String gml = "<gml:Polygon srsName=\"SDO:8307\" xmlns:gml=\"http://www.opengis.net/gml\"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates decimal=\".\" cs=\",\" ts=\" \">5,1 8,1 8,6 5,7 5,1 </gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>"; GeometryType gt = GeometryUtils.geometryFromGml(new ClobType(ClobImpl.createClob(gml.toCharArray())), null); assertEquals(8307, gt.getSrid()); //oracle will leave of the int with unknown gml = "<gml:Polygon srsName=\"SDO:\" xmlns:gml=\"http://www.opengis.net/gml\"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates decimal=\".\" cs=\",\" ts=\" \">5,1 8,1 8,6 5,7 5,1 </gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>"; gt = GeometryUtils.geometryFromGml(new ClobType(ClobImpl.createClob(gml.toCharArray())), null); assertEquals(GeometryType.UNKNOWN_SRID, gt.getSrid()); }
@Test() public void testStringAggOrdering() throws Exception { String sql = "select string_agg(col1, ',' ORDER BY col1 DESC) as orderByDesc," + " string_agg(col1, ',' ORDER BY col1 ASC) as orderByAsc, " + " string_agg(DISTINCT col1, ',' ORDER BY col1 DESC) as distinctOrderByDesc, " + " string_agg(DISTINCT col1, ',' ORDER BY col1 ASC) as distinctOrderByAsc from (select 'a' as col1 union all select 'b' union all select 'b' union all select 'c') as x"; TransformationMetadata metadata = RealMetadataFactory.example1Cached(); HardcodedDataManager hdm = new HardcodedDataManager(); ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata); TestProcessor.helpProcess(plan, TestProcessor.createCommandContext(), hdm, new List<?>[] { Arrays.asList(new ClobType(new ClobImpl("c,b,b,a")), new ClobType(new ClobImpl("a,b,b,c")), new ClobType(new ClobImpl("c,b,a")), new ClobType(new ClobImpl("a,b,c")))}); }
@Test public void testClobValue() throws Exception { String testString = "this is test clob"; //$NON-NLS-1$ SerialClob clob = new SerialClob(testString.toCharArray()); ClobType cv = new ClobType(clob); assertEquals(testString, cv.getSubString(1L, (int)cv.length())); }
@Test(expected=TeiidProcessingException.class) public void testTextTableInvalidData() throws Exception { String sql = "select count(*) from texttable(? COLUMNS PARTNAME string) x"; //$NON-NLS-1$ FakeDataManager dataManager = new FakeDataManager(); sampleData1(dataManager); char[] data = new char[5000]; processPreparedStatement(sql, null, dataManager, new DefaultCapabilitiesFinder(), RealMetadataFactory.example1Cached(), Arrays.asList(new ClobType(new SerialClob(data)))); }
@Test public void testClobValuePersistence() throws Exception { String testString = "this is test clob"; //$NON-NLS-1$ SerialClob clob = new SerialClob(testString.toCharArray()); ClobType cv = new ClobType(clob); String key = cv.getReferenceStreamId(); // now force to serialize ClobType read = UnitTestUtil.helpSerialize(cv); assertTrue(read.length() > 0); // make sure we have kept the reference stream id assertEquals(key, read.getReferenceStreamId()); // and lost the original object assertNull(read.getReference()); }