From derby-commits-return-8982-apmail-db-derby-commits-archive=db.apache.org@db.apache.org Wed Dec 05 19:52:22 2007 Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 91284 invoked from network); 5 Dec 2007 19:52:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Dec 2007 19:52:22 -0000 Received: (qmail 60869 invoked by uid 500); 5 Dec 2007 19:52:10 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 60835 invoked by uid 500); 5 Dec 2007 19:52:10 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 60824 invoked by uid 99); 5 Dec 2007 19:52:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Dec 2007 11:52:10 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Dec 2007 19:51:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1E80A1A9832; Wed, 5 Dec 2007 11:51:57 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r601492 - /db/derby/code/trunk/java/demo/vtis/java/org/apache/derbyDemo/vtis/example/LineListVTI.java Date: Wed, 05 Dec 2007 19:51:56 -0000 To: derby-commits@db.apache.org From: rhillegas@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071205195157.1E80A1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rhillegas Date: Wed Dec 5 11:51:56 2007 New Revision: 601492 URL: http://svn.apache.org/viewvc?rev=601492&view=rev Log: DERBY-3129: Add another demo vti; this turns a flat file into a one-column table whose rows are just the lines in the file. Added: db/derby/code/trunk/java/demo/vtis/java/org/apache/derbyDemo/vtis/example/LineListVTI.java (with props) Added: db/derby/code/trunk/java/demo/vtis/java/org/apache/derbyDemo/vtis/example/LineListVTI.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/vtis/java/org/apache/derbyDemo/vtis/example/LineListVTI.java?rev=601492&view=auto ============================================================================== --- db/derby/code/trunk/java/demo/vtis/java/org/apache/derbyDemo/vtis/example/LineListVTI.java (added) +++ db/derby/code/trunk/java/demo/vtis/java/org/apache/derbyDemo/vtis/example/LineListVTI.java Wed Dec 5 11:51:56 2007 @@ -0,0 +1,134 @@ +/* + +Derby - Class org.apache.derbyDemo.vtis.example.LineListVTI + +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +*/ + +package org.apache.derbyDemo.vtis.example; + +import java.io.*; +import java.sql.*; +import java.text.SimpleDateFormat; + +import org.apache.derbyDemo.vtis.core.*; + +/** + *

+ * This VTI makes a table out of a text file. The table has one column, + * containing the contents of a line in the file. Leading and trailing white + * space are trimmed. + *

+ */ +public class LineListVTI extends FlatFileVTI +{ + /////////////////////////////////////////////////////////////////////////////////// + // + // CONSTANTS + // + /////////////////////////////////////////////////////////////////////////////////// + + private static final String[] COLUMN_NAMES = + { + "line" + }; + + private static final int LINE = 0; + + /////////////////////////////////////////////////////////////////////////////////// + // + // STATE + // + /////////////////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////////////////// + // + // CONSTRUCTORS + // + /////////////////////////////////////////////////////////////////////////////////// + + /** + *

+ * Build a LineListVTI given the name of a file. + *

+ */ + public LineListVTI( String fileName ) + { + super( COLUMN_NAMES, fileName ); + } + + /////////////////////////////////////////////////////////////////////////////////// + // + // TABLE FUNCTION METHOD + // + /////////////////////////////////////////////////////////////////////////////////// + + + /** + *

+ * This is the method which is registered as a table function. + *

+ */ + public static ResultSet lineListVTI( String fileName ) + throws SQLException + { + return new LineListVTI( fileName ); + } + + /////////////////////////////////////////////////////////////////////////////////// + // + // FlatFileVTI BEHAVIOR TO BE IMPLEMENTED BY SUBCLASSES + // + /////////////////////////////////////////////////////////////////////////////////// + + /** + *

+ * Parse the next chunk of text, using readLine(), and return the next row. + * Returns null if the file is exhausted. + *

+ */ + protected String[] parseRow( ) throws SQLException + { + String[] newRow = new String[ COLUMN_NAMES.length ]; + String nextLine = null; + + nextLine = readLine(); + + // if at EOF, get out of here + if ( nextLine == null ) { return null; } + + nextLine = nextLine.trim(); + + newRow[ LINE ] = nextLine; + + return newRow; + } + + /////////////////////////////////////////////////////////////////////////////////// + // + // ResultSet METHODS + // + /////////////////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////////////////// + // + // MINIONS + // + /////////////////////////////////////////////////////////////////////////////////// + + +} Propchange: db/derby/code/trunk/java/demo/vtis/java/org/apache/derbyDemo/vtis/example/LineListVTI.java ------------------------------------------------------------------------------ svn:eol-style = native