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