1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 package com.sun.star.sdbcx.comp.postgresql;
23 
24 import java.util.List;
25 import java.util.Map;
26 
27 import com.sun.star.beans.XPropertySet;
28 import com.sun.star.container.ElementExistException;
29 import com.sun.star.container.NoSuchElementException;
30 import com.sun.star.lang.IndexOutOfBoundsException;
31 import com.sun.star.sdbc.SQLException;
32 import com.sun.star.sdbc.XConnection;
33 import com.sun.star.sdbcx.comp.postgresql.comphelper.CompHelper;
34 import com.sun.star.sdbcx.comp.postgresql.sdbcx.OColumnContainer;
35 import com.sun.star.sdbcx.comp.postgresql.sdbcx.OContainer;
36 import com.sun.star.sdbcx.comp.postgresql.sdbcx.OIndexContainer;
37 import com.sun.star.sdbcx.comp.postgresql.sdbcx.OKey;
38 import com.sun.star.sdbcx.comp.postgresql.sdbcx.OKeyContainer;
39 import com.sun.star.sdbcx.comp.postgresql.sdbcx.OTable;
40 import com.sun.star.sdbcx.comp.postgresql.sdbcx.SqlTableHelper;
41 import com.sun.star.sdbcx.comp.postgresql.sdbcx.SqlTableHelper.ColumnDescription;
42 import com.sun.star.sdbcx.comp.postgresql.sdbcx.descriptors.SdbcxTableDescriptor;
43 
44 public class PostgresqlTable extends OTable {
45     private PostgresqlTable(XConnection connection, OContainer tables, String name,
46             String catalogName, String schemaName, String description, String type) {
47         super(name, true, connection, tables);
48         super.catalogName = catalogName;
49         super.schemaName = schemaName;
50         super.description = description;
51         super.type = type;
52     }
53 
54     public static PostgresqlTable create(XConnection connection, OContainer tables, String name,
55             String catalogName, String schemaName, String description, String type) {
56         return new PostgresqlTable(connection, tables, name, catalogName, schemaName, description, type);
57     }
58 
59     @Override
60     public XPropertySet createDataDescriptor() {
61         SdbcxTableDescriptor descriptor = SdbcxTableDescriptor.create(true);
62         synchronized (this) {
63             CompHelper.copyProperties(this, descriptor);
64         }
65         return descriptor;
66     }
67 
68     @Override
69     public void setName(String name) {
70         // TODO Auto-generated method stub
71 
72     }
73 
74     @Override
75     public void rename(String name) throws SQLException, ElementExistException {
76         // TODO Auto-generated method stub
77 
78     }
79 
80     @Override
81     public void alterColumnByIndex(int index, XPropertySet descriptor) throws SQLException, IndexOutOfBoundsException {
82         // TODO Auto-generated method stub
83 
84     }
85 
86     @Override
87     public void alterColumnByName(String name, XPropertySet descriptor) throws SQLException, NoSuchElementException {
88         // TODO Auto-generated method stub
89 
90     }
91 
92     @Override
93     protected OContainer refreshColumns() {
94         try {
95             List<ColumnDescription> columns = new SqlTableHelper().readColumns(getConnection().getMetaData(), catalogName, schemaName, getName());
96             return new OColumnContainer(this, isCaseSensitive(), columns, this, getConnection().getMetaData());
97         } catch (ElementExistException elementExistException) {
98             return null;
99         } catch (SQLException sqlException) {
100             return null;
101         }
102     }
103 
104     @Override
105     protected OContainer refreshIndexes() {
106         try {
107             List<String> indexes = new SqlTableHelper().readIndexes(getConnection().getMetaData(), catalogName, schemaName, getName(), this);
108             return new OIndexContainer(this, indexes, isCaseSensitive(), this);
109         } catch (ElementExistException elementExistException) {
110             return null;
111         } catch (SQLException sqlException) {
112             return null;
113         }
114     }
115 
116     @Override
117     protected OContainer refreshKeys() {
118         try {
119             Map<String, OKey> keys = new SqlTableHelper().readKeys(
120                     getConnection().getMetaData(), catalogName, schemaName, getName(), isCaseSensitive(), this);
121             return OKeyContainer.create(isCaseSensitive(), keys, this);
122         } catch (ElementExistException elementExistException) {
123             return null;
124         } catch (SQLException sqlException) {
125             return null;
126         }
127     }
128 
129 
130 }
131