| 1 | /* ============================================================= |
| 2 | * SmallSQL : a free Java DBMS library for the Java(tm) platform |
| 3 | * ============================================================= |
| 4 | * |
| 5 | * (C) Copyright 2004-2006, by Volker Berlin. |
| 6 | * |
| 7 | * Project Info: http://www.smallsql.de/ |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU Lesser General Public License as published by |
| 11 | * the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 16 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 17 | * License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public |
| 20 | * License along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 22 | * USA. |
| 23 | * |
| 24 | * [Java is a trademark or registered trademark of Sun Microsystems, Inc. |
| 25 | * in the United States and other countries.] |
| 26 | * |
| 27 | * --------------- |
| 28 | * TableViewResult.java |
| 29 | * --------------- |
| 30 | * Author: Volker Berlin |
| 31 | * |
| 32 | * Created on 11.06.2004 |
| 33 | */ |
| 34 | package smallsql.database; |
| 35 | |
| 36 | import java.sql.SQLException; |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * @author Volker Berlin |
| 41 | */ |
| 42 | abstract class TableViewResult extends DataSource { |
| 43 | SSConnection con; |
| 44 | |
| 45 | private String alias; |
| 46 | private long tableTimestamp; |
| 47 | int lock = SQLTokenizer.SELECT; |
| 48 | |
| 49 | static TableViewResult createResult(TableView tableView){ |
| 50 | if(tableView instanceof Table) |
| 51 | return new TableResult((Table)tableView); |
| 52 | return new ViewResult( (View)tableView ); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | static TableViewResult getTableViewResult(RowSource from) throws SQLException{ |
| 57 | if(from instanceof Where){ |
| 58 | from = ((Where)from).getFrom(); |
| 59 | } |
| 60 | if(from instanceof TableViewResult){ |
| 61 | return (TableViewResult)from; |
| 62 | } |
| 63 | throw Utils.createSQLException("Rowsource is read only."); |
| 64 | } |
| 65 | |
| 66 | void setAlias( String alias ){ |
| 67 | this.alias = alias; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | String getAlias(){ |
| 72 | return (alias != null) ? alias : getTableView().name; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | boolean hasAlias(){ |
| 77 | return alias != null; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | /** |
| 82 | * Is used for compile() of different Commands |
| 83 | * |
| 84 | * @param con |
| 85 | * @return true if now init; false if allready init |
| 86 | * @throws Exception |
| 87 | */ |
| 88 | boolean init( SSConnection con ) throws Exception{ |
| 89 | TableView tableView = getTableView(); |
| 90 | if(tableTimestamp != tableView.getTimestamp()){ |
| 91 | this.con = con; |
| 92 | tableTimestamp = tableView.getTimestamp(); |
| 93 | return true; |
| 94 | } |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | //abstract TableView getTableView(); |
| 100 | |
| 101 | abstract void deleteRow() throws SQLException; |
| 102 | |
| 103 | abstract void updateRow(Expression[] updateValues) throws Exception; |
| 104 | |
| 105 | abstract void insertRow(Expression[] updateValues) throws Exception; |
| 106 | |
| 107 | |
| 108 | final boolean isScrollable(){ |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | } |