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     public 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     @Override
55     public XPropertySet createDataDescriptor() {
56         SdbcxTableDescriptor descriptor = new SdbcxTableDescriptor(true);
57         synchronized (this) {
58             CompHelper.copyProperties(this, descriptor);
59         }
60         return descriptor;
61     }
62 
63     @Override
64     public void setName(String name) {
65         // TODO Auto-generated method stub
66 
67     }
68 
69     @Override
70     public void rename(String name) throws SQLException, ElementExistException {
71         // TODO Auto-generated method stub
72 
73     }
74 
75     @Override
76     public void alterColumnByIndex(int index, XPropertySet descriptor) throws SQLException, IndexOutOfBoundsException {
77         // TODO Auto-generated method stub
78 
79     }
80 
81     @Override
82     public void alterColumnByName(String name, XPropertySet descriptor) throws SQLException, NoSuchElementException {
83         // TODO Auto-generated method stub
84 
85     }
86 
87     @Override
88     protected OContainer refreshColumns() {
89         try {
90             List<ColumnDescription> columns = new SqlTableHelper().readColumns(getConnection().getMetaData(), catalogName, schemaName, getName());
91             return new OColumnContainer(this, isCaseSensitive(), columns, this, getConnection().getMetaData());
92         } catch (ElementExistException elementExistException) {
93             return null;
94         } catch (SQLException sqlException) {
95             return null;
96         }
97     }
98 
99     @Override
100     protected OContainer refreshIndexes() {
101         try {
102             List<String> indexes = new SqlTableHelper().readIndexes(getConnection().getMetaData(), catalogName, schemaName, getName(), this);
103             return new OIndexContainer(this, indexes, isCaseSensitive(), this);
104         } catch (ElementExistException elementExistException) {
105             return null;
106         } catch (SQLException sqlException) {
107             return null;
108         }
109     }
110 
111     @Override
112     protected OContainer refreshKeys() {
113         try {
114             Map<String, OKey> keys = new SqlTableHelper().readKeys(
115                     getConnection().getMetaData(), catalogName, schemaName, getName(), isCaseSensitive(), this);
116             return new OKeyContainer(this, isCaseSensitive(), keys, this);
117         } catch (ElementExistException elementExistException) {
118             return null;
119         } catch (SQLException sqlException) {
120             return null;
121         }
122     }
123 
124 
125 }
126