db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
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 GMT
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.*;
+
+/**
+ * <p>
+ * 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.
+ * </p>
+ */
+public    class   LineListVTI  extends FlatFileVTI
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private static  final   String[]    COLUMN_NAMES =
+    {
+        "line"
+    };
+
+    private static  final   int LINE = 0;
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTORS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Build a LineListVTI given the name of a file.
+     * </p>
+     */
+    public  LineListVTI( String fileName )
+    {
+        super( COLUMN_NAMES, fileName );
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // TABLE FUNCTION METHOD
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+
+    /**
+     * <p>
+     * This is the method which is registered as a table function.
+     * </p>
+     */
+    public  static  ResultSet   lineListVTI( String fileName )
+        throws SQLException
+    {
+        return new LineListVTI( fileName );
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // FlatFileVTI BEHAVIOR TO BE IMPLEMENTED BY SUBCLASSES
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Parse the next chunk of text, using readLine(), and return the next row.
+     * Returns null if the file is exhausted.
+     * </p>
+     */
+    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



Mime
View raw message