Kaydet (Commit) 330392f8 authored tarafından Damjan Jovanovic's avatar Damjan Jovanovic

#i127350# - Table design: can't change length of Postgresql char types

Add the initial version of a new SDBC driver, for the PostgreSQL database.

Also its build changes: since it needs Apache Commons Lang version 3,
get configure.ac to check for that, and get that to always build,
just like our driver does.

Patch by: me
üst 6dd83d1c
......@@ -37,7 +37,7 @@ ANT_BUILDFILE=build.xml
TAR!:=$(GNUTAR)
.IF "$(SOLAR_JAVA)" != "" && "$(ENABLE_MEDIAWIKI)" == "YES"
.IF "$(SOLAR_JAVA)" != ""
# --- Files --------------------------------------------------------
TARFILE_NAME=commons-lang3-3.3-src
......@@ -70,7 +70,7 @@ BUILD_ACTION=$(ANT) -Dbuild.label="build-$(RSCREVISION)" -f $(ANT_BUILDFILE) jar
.INCLUDE : set_ext.mk
.INCLUDE : target.mk
.IF "$(SOLAR_JAVA)" != "" && "$(ENABLE_MEDIAWIKI)" == "YES"
.IF "$(SOLAR_JAVA)" != ""
.INCLUDE : tg_ext.mk
.ENDIF
<?xml version="1.0" encoding="UTF-8"?>
<!--***********************************************************
*
* 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.
*
***********************************************************-->
<project name="sdbc_postgresql" default="main" basedir=".">
<!-- ================================================================= -->
<!-- settings -->
<!-- ================================================================= -->
<!-- global properties -->
<property file="../../../ant.properties"/>
<!-- version info -->
<property file="../../../solenv/inc/minor.mk"/>
<!-- name of this sub target used in recursive builds -->
<property name="target" value="sdbc_postgresql"/>
<!-- name of jar file created, without .jar extension -->
<property name="jarname" value="sdbc_postgresql"/>
<!-- relative path to project directory -->
<property name="prj" value="../.."/>
<!-- build output directory -->
<!-- FIXME: there are also extremely rare/obsolete dbcs/bndchk/truetime/hbtoolkit cases in main/solenv/inc/settings.mk -->
<condition property="out" value="${prj}/${OUTPATH}.cap">
<isset property="${profile}"/>
</condition>
<condition property="out" value="${prj}/${OUTPATH}.pro">
<isset property="${PRODUCT}"/>
</condition>
<property name="out" value="${prj}/${OUTPATH}"/>
<!-- build directories -->
<property name="build.dir" value="${out}"/>
<property name="build.class" value="${build.dir}/class/${target}"/>
<property name="build.misc" value="${build.dir}/misc/${target}"/>
<!-- start of java source code package structure -->
<property name="java.dir" value="src"/>
<!-- define how to handle CLASSPATH environment -->
<property name="build.sysclasspath" value="ignore"/>
<!-- classpath settings for compile and javadoc tasks -->
<condition property="jar-class-path" value="${COMMONS_LANG_JAR}" else="commons-lang3-3.3.jar">
<equals arg1="${SYSTEM_APACHE_COMMONS}" arg2="YES"/>
</condition>
<condition property="commons-lang-jar" value="${COMMONS_LANG_JAR}" else="${OUTDIR}/bin/commons-lang3-3.3.jar">
<equals arg1="${SYSTEM_APACHE_COMMONS}" arg2="YES"/>
</condition>
<path id="classpath">
<pathelement location="${OUTDIR}/bin/juh.jar"/>
<pathelement location="${OUTDIR}/bin/jurt.jar"/>
<pathelement location="${OUTDIR}/bin/ridl.jar"/>
<pathelement location="${OUTDIR}/bin/unoil.jar"/>
<!-- 3rd party libs -->
<pathelement location="${commons-lang-jar}"/>
</path>
<!-- name to display in documentation -->
<property name="docname" value="sdbc_postgresql"/>
<!-- set "modern" java compiler -->
<property name="build.compiler" value="modern"/>
<!-- set wether we want to compile with debug information -->
<property name="debug" value="on"/>
<!-- set wether we want to compile with optimisation -->
<property name="optimize" value="off"/>
<!-- set wether we want to compile with or without deprecation -->
<property name="deprecation" value="on"/>
<target name="info">
<echo message="--------------------"/>
<echo message="${target}"/>
<echo message="--------------------"/>
</target>
<!-- ================================================================= -->
<!-- custom targets -->
<!-- ================================================================= -->
<!-- the main target, called in recursive builds -->
<target name="main" depends="info,prepare,compile,jar,javadoc,zipdoc"/>
<!-- prepare output directories -->
<target name="prepare">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.dir}/doc/${target}"/>
<mkdir dir="${build.class}"/>
<mkdir dir="${build.misc}"/>
</target>
<target name="res" depends="prepare">
<copy todir="${build.class}">
<fileset dir="${java.dir}">
<include name="**/*.properties"/>
<include name="**/*.css"/>
<include name="**/*.dtd"/>
<include name="**/*.form"/>
<include name="**/*.gif "/>
<include name="**/*.htm"/>
<include name="**/*.html"/>
<include name="**/*.js"/>
<include name="**/*.mod"/>
<include name="**/*.sql"/>
<include name="**/*.xml"/>
<include name="**/*.xsl"/>
<include name="**/*.map"/>
</fileset>
</copy>
</target>
<target name="compile" depends="prepare,res">
<javac destdir="${build.class}"
debug="${debug}"
debuglevel="lines,vars,source"
deprecation="${deprecation}"
optimize="${optimize}"
classpathref="classpath">
<src path="${java.dir}"/>
<include name="**/*.java"/>
</javac>
</target>
<!-- check if javadoc is up to date -->
<target name="javadoc_check" depends="prepare" if="build.dir">
<uptodate property="javadocBuild.notRequired" value="true"
targetfile="${build.dir}/doc/${target}/${target}_javadoc.zip">
<srcfiles dir="${java.dir}" includes="**/*.java"/>
</uptodate>
</target>
<!-- generate java documentation -->
<target name="javadoc" depends="prepare,javadoc_check,compile"
unless="javadocBuild.notRequired"
if="build.dir">
<javadoc destdir="${build.dir}/doc/${target}/javadoc"
verbose="false"
author="false"
nodeprecated="true"
nodeprecatedlist="true"
use="true"
Doctitle="${docname}"
windowtitle="${docname}"
classpathref="classpath">
<packageset dir="${java.dir}" defaultexcludes="yes">
<include name="com/**"/>
<include name="org/**"/>
</packageset>
<link offline="true" href="http://java.sun.com/j2se/1.4.2/docs/api"
packagelistLoc="${common.doc}/jdk1.4.2"/>
<link offline="true"
href="http://java.sun.com/products/servlet/2.3/javadoc"
packagelistLoc="${common.doc}/servlet2.3"/>
<link offline="true"
href="http://logging.apache.org/log4j/docs/api"
packagelistLoc="${common.doc}/log4j-1.2.8"/>
<link offline="true"
href="http://java.sun.com/products/javabeans/glasgow/javadocs"
packagelistLoc="${common.doc}/jaf-1.0.2"/>
<link offline="true"
href="http://java.sun.com/products/javamail/javadocs"
packagelistLoc="${common.doc}/javamail-1.3.1"/>
<link offline="true"
href="http://ws.apache.org/soap/docs"
packagelistLoc="${common.doc}/soap-2.3.1"/>
<bottom>&lt;i&gt;Copyright &amp;#169; 2004 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, CA 94303 USA&lt;/i&gt;</bottom>
<header>${docname}</header>
</javadoc>
</target>
<!-- zip documentation and store in build/doc/${target} -->
<target name="zipdoc" depends="javadoc" if="build.dir" unless="javadocBuild.notRequired">
<zip zipfile="${build.dir}/doc/${target}/${target}_javadoc.zip"
basedir="${build.dir}/doc/${target}/javadoc"
update="true"/>
</target>
<!-- clean up -->
<target name="clean" depends="prepare">
<delete dir="${build.class}" includeEmptyDirs="true"/>
<delete dir="${build.dir}/doc/${target}" includeEmptyDirs="true"/>
</target>
<!-- create jar file -->
<target name="jar" depends="prepare,compile" if="build.class">
<jar jarfile="${build.class}/${jarname}.jar"
basedir="${build.class}">
<manifest>
<attribute name="Class-Path" value="${jar-class-path} juh.jar jurt.jar ridl.jar unoil.jar"/>
<attribute name="Solar-Version" value="${RSCREVISION}"/>
<attribute name="RegistrationClassName" value="com.sun.star.sdbcx.comp.postgresql.PostgresqlDriver"/>
<attribute name="Sealed" value="true"/>
<attribute name="UNO-Type-Path" value=""/>
</manifest>
<include name="**/*.class"/>
<include name="**/*.properties"/>
<include name="**/*.css"/>
<include name="**/*.dtd"/>
<include name="**/*.form"/>
<include name="**/*.gif "/>
<include name="**/*.htm"/>
<include name="**/*.html"/>
<include name="**/*.js"/>
<include name="**/*.mod"/>
<include name="**/*.sql"/>
<include name="**/*.xml"/>
<include name="**/*.xsl"/>
<include name="**/*.map"/>
</jar>
</target>
<target name="test" depends="prepare">
</target>
</project>
#**************************************************************
#
# 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.
#
#**************************************************************
PRJ=..$/..
PRJNAME=connectivity
TARGET=sdbc_postgresql
# --- Settings -----------------------------------------------------
.INCLUDE : $(PRJ)$/makefile.pmk
.INCLUDE : $(PRJ)$/version.mk
.IF defined(debug) || defined(DEBUG)
ANTDEBUG=true
.ELSE
ANTDEBUG=off
.ENDIF
ANT_FLAGS+=-Dantdebug=$(ANTDEBUG)
# --- Targets ------------------------------------------------------
.INCLUDE : $(PRJ)$/target.pmk
ALLTAR: ANTBUILD $(MISC)/postgresql.component
$(MISC)/postgresql.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \
postgresql.component
$(XSLTPROC) --nonet --stringparam uri '$(COMPONENTPREFIX_URE_JAVA)sdbc_postgresql.jar' \
-o $@ $(SOLARENV)/bin/createcomponent.xslt postgresql.component
<?xml version="1.0" encoding="UTF-8"?>
<!--***********************************************************
*
* 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.
*
***********************************************************-->
<component loader="com.sun.star.loader.Java2"
xmlns="http://openoffice.org/2010/uno-components">
<implementation name="com.sun.star.sdbcx.comp.postgresql.PostgresqlDriver">
<service name="com.sun.star.sdbc.Driver"/>
</implementation>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<!--***********************************************************
*
* 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.
*
***********************************************************-->
<oor:component-data oor:name="Drivers" oor:package="org.openoffice.Office.DataAccess" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<node oor:name="Installed">
<node oor:name="sdbc:postgresql:jdbc:*" oor:op="replace">
<prop oor:name="Driver">
<value>com.sun.star.sdbcx.comp.postgresql.PostgresqlDriver</value>
</prop>
<prop oor:name="DriverTypeDisplayName" oor:type="xs:string">
<value xml:lang="en-US">PostgreSQL</value>
</prop>
<node oor:name="Properties">
<node oor:name="JavaDriverClass" oor:op="replace">
<prop oor:name="Value" oor:type="xs:string">
<value>org.postgresql.Driver</value>
</prop>
</node>
</node>
<node oor:name="Features">
</node>
<node oor:name="MetaData">
<node oor:name="SupportsBrowsing" oor:op="replace">
<prop oor:name="Value" oor:type="xs:boolean">
<value>true</value>
</prop>
</node>
<node oor:name="SupportsTableCreation" oor:op="replace">
<prop oor:name="Value" oor:type="xs:boolean">
<value>true</value>
</prop>
</node>
<node oor:name="UseJava" oor:op="replace">
<prop oor:name="Value" oor:type="xs:boolean">
<value>true</value>
</prop>
</node>
<node oor:name="Authentication" oor:op="replace">
<prop oor:name="Value" oor:type="xs:string">
<value>UserPassword</value>
</prop>
</node>
<node oor:name="SupportsColumnDescription" oor:op="replace">
<prop oor:name="Value" oor:type="xs:boolean">
<value>true</value>
</prop>
</node>
</node>
</node>
</node>
</oor:component-data>
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql;
import java.util.ArrayList;
import java.util.List;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XResultSet;
import com.sun.star.sdbc.XRow;
import com.sun.star.sdbcx.comp.postgresql.comphelper.CompHelper;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.OCatalog;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.OContainer;
import com.sun.star.uno.Any;
import com.sun.star.uno.UnoRuntime;
public class PostgresqlCatalog extends OCatalog {
public PostgresqlCatalog(PostgresqlConnection connection) throws SQLException {
super(connection.getMetaData());
}
@Override
public OContainer refreshTables() {
XResultSet results = null;
try {
// Using { "VIEW", "TABLE", "%" } shows INFORMATION_SCHEMA and others, but it also shows indexes :-(
results = metadata.getTables(Any.VOID, "%", "%", new String[] { "VIEW", "TABLE" });
XRow row = UnoRuntime.queryInterface(XRow.class, results);
List<String> names = new ArrayList<>();
while (results.next()) {
String name = buildName(row);
System.out.println("Table " + name);
names.add(name);
}
return new PostgresqlTables(lock, metadata, this, names);
} catch (SQLException sqlException) {
} finally {
CompHelper.disposeComponent(results);
}
return null;
}
@Override
public OContainer refreshViews() {
XResultSet results = null;
try {
results = metadata.getTables(Any.VOID, "%", "%", new String[] { "VIEW" });
XRow row = UnoRuntime.queryInterface(XRow.class, results);
List<String> names = new ArrayList<>();
while (results.next()) {
String name = buildName(row);
names.add(name);
}
return new PostgresqlTables(lock, metadata, this, names);
} catch (SQLException sqlException) {
} finally {
CompHelper.disposeComponent(results);
}
return null;
}
@Override
public OContainer refreshGroups() {
return null;
}
@Override
public OContainer refreshUsers() {
return null;
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql;
import java.util.HashSet;
import java.util.concurrent.atomic.AtomicBoolean;
import com.sun.star.container.XNameAccess;
import com.sun.star.lang.DisposedException;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XEventListener;
import com.sun.star.lib.uno.helper.ComponentBase;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XConnection;
import com.sun.star.sdbc.XDatabaseMetaData;
import com.sun.star.sdbc.XPreparedStatement;
import com.sun.star.sdbc.XStatement;
import com.sun.star.sdbc.XWarningsSupplier;
import com.sun.star.uno.UnoRuntime;
public class PostgresqlConnection extends ComponentBase implements XConnection, XWarningsSupplier, XEventListener {
private XConnection impl;
private XComponent implComponent;
private XWarningsSupplier implWarningsSupplier;
private String url;
private AtomicBoolean isDisposed = new AtomicBoolean(false);
private HashSet<XComponent> statements = new HashSet<>();
public PostgresqlConnection(XConnection impl, String url) {
this.impl = impl;
implComponent = UnoRuntime.queryInterface(XComponent.class, impl);
implWarningsSupplier = UnoRuntime.queryInterface(XWarningsSupplier.class, impl);
this.url = url;
}
// XComponent:
@Override
protected synchronized void postDisposing() {
isDisposed.set(true);
implComponent.dispose();
for (XComponent pgStatement : statements) {
try {
pgStatement.dispose();
} catch (DisposedException disposedException) {
}
}
};
private void checkDisposed() throws DisposedException {
if (isDisposed.get()) {
throw new DisposedException();
}
}
// XEventListener:
public synchronized void disposing(EventObject source) {
statements.remove(source.Source);
}
// XWarningsSupplier:
public void clearWarnings() throws SQLException {
checkDisposed();
implWarningsSupplier.clearWarnings();
}
public Object getWarnings() throws SQLException {
checkDisposed();
return implWarningsSupplier.getWarnings();
}
// XConnection:
public void close() throws SQLException {
dispose();
}
public void commit() throws SQLException {
checkDisposed();
impl.commit();
}
public synchronized XStatement createStatement() throws SQLException {
checkDisposed();
PostgresqlStatement pgStatement = new PostgresqlStatement(impl.createStatement(), this);
statements.add(pgStatement);
pgStatement.addEventListener(this);
return pgStatement;
}
public boolean getAutoCommit() throws SQLException {
checkDisposed();
return impl.getAutoCommit();
}
public String getCatalog() throws SQLException {
checkDisposed();
return impl.getCatalog();
}
public XDatabaseMetaData getMetaData() throws SQLException {
checkDisposed();
return new PostgresqlDatabaseMetadata(impl.getMetaData(), this, url);
}
public int getTransactionIsolation() throws SQLException {
checkDisposed();
return impl.getTransactionIsolation();
}
public XNameAccess getTypeMap() throws SQLException {
checkDisposed();
return impl.getTypeMap();
}
public boolean isClosed() throws SQLException {
checkDisposed();
return impl.isClosed();
}
public boolean isReadOnly() throws SQLException {
checkDisposed();
return impl.isReadOnly();
}
public String nativeSQL(String arg0) throws SQLException {
checkDisposed();
return impl.nativeSQL(arg0);
}
public synchronized XPreparedStatement prepareCall(String arg0) throws SQLException {
checkDisposed();
PostgresqlPreparedStatement pgStatement = new PostgresqlPreparedStatement(impl.prepareCall(arg0), this);
statements.add(pgStatement);
pgStatement.addEventListener(this);
return pgStatement;
}
public synchronized XPreparedStatement prepareStatement(String arg0) throws SQLException {
checkDisposed();
PostgresqlPreparedStatement pgStatement = new PostgresqlPreparedStatement(impl.prepareStatement(arg0), this);
statements.add(pgStatement);
pgStatement.addEventListener(this);
return pgStatement;
}
public void rollback() throws SQLException {
checkDisposed();
impl.rollback();
}
public void setAutoCommit(boolean arg0) throws SQLException {
checkDisposed();
impl.setAutoCommit(arg0);
}
public void setCatalog(String arg0) throws SQLException {
checkDisposed();
impl.setCatalog(arg0);
}
public void setReadOnly(boolean arg0) throws SQLException {
checkDisposed();
impl.setReadOnly(arg0);
}
public void setTransactionIsolation(int arg0) throws SQLException {
checkDisposed();
impl.setTransactionIsolation(arg0);
}
public void setTypeMap(XNameAccess arg0) throws SQLException {
checkDisposed();
impl.setTypeMap(arg0);
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import com.sun.star.beans.PropertyValue;
import com.sun.star.lang.DisposedException;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.XSingleComponentFactory;
import com.sun.star.lib.uno.helper.ComponentBase;
import com.sun.star.lib.uno.helper.Factory;
import com.sun.star.sdbc.DriverPropertyInfo;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XConnection;
import com.sun.star.sdbc.XDriver;
import com.sun.star.sdbc.XDriverManager;
import com.sun.star.sdbcx.XDataDefinitionSupplier;
import com.sun.star.sdbcx.XTablesSupplier;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.SharedResources;
import com.sun.star.sdbcx.comp.postgresql.util.StandardSQLState;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public class PostgresqlDriver extends ComponentBase implements XServiceInfo, XDriver, XDataDefinitionSupplier {
private static String[] services = new String[] {
"com.sun.star.sdbc.Driver",
"com.sun.star.sdbcx.Driver"
};
private XComponentContext componentContext;
private AtomicBoolean isDisposed = new AtomicBoolean(false);
public static XSingleComponentFactory __getComponentFactory(String implName) {
XSingleComponentFactory xSingleComponentFactory = null;
if (implName.equals(getImplementationNameStatic())) {
xSingleComponentFactory = Factory.createComponentFactory(PostgresqlDriver.class,
getImplementationNameStatic(), services);
}
return xSingleComponentFactory;
}
public PostgresqlDriver(XComponentContext componentContext) {
this.componentContext = componentContext;
SharedResources.registerClient(componentContext);
}
private static String getImplementationNameStatic() {
return PostgresqlDriver.class.getName();
}
// XComponent:
@Override
protected void postDisposing() {
isDisposed.set(true);
componentContext = null;
SharedResources.revokeClient();
}
private void checkDisposed() throws DisposedException {
if (isDisposed.get()) {
throw new DisposedException();
}
}
// XServiceInfo:
@Override
public String getImplementationName() {
return getImplementationNameStatic();
}
@Override
public String[] getSupportedServiceNames() {
return services.clone();
}
@Override
public boolean supportsService(String serviceName) {
for (String service : services) {
if (service.equals(serviceName)) {
return true;
}
}
return false;
}
// XDriver:
@Override
public boolean acceptsURL(String url) throws SQLException {
return url.startsWith("sdbc:postgresql:jdbc:");
}
@Override
public XConnection connect(String url, PropertyValue[] info) throws SQLException {
checkDisposed();
XConnection connection = null;
if (acceptsURL(url)) {
String jdbcUrl = transformUrl(url);
System.out.println("Using SDBC URL " + url + " and JDBC URL " + jdbcUrl);
try {
Object driverManagerObject = componentContext.getServiceManager().createInstanceWithContext(
"com.sun.star.sdbc.DriverManager", componentContext);
XDriverManager driverManager = UnoRuntime.queryInterface(XDriverManager.class, driverManagerObject);
ArrayList<PropertyValue> properties = new ArrayList<>();
boolean haveJavaClass = false;
for (PropertyValue property : info) {
if (property.Name.equals("JavaDriverClass")) {
haveJavaClass = true;
}
properties.add(property);
}
if (!haveJavaClass) {
PropertyValue javaClassProperty = new PropertyValue();
javaClassProperty.Name = "JavaDriverClass";
javaClassProperty.Value = "org.postgresql.Driver";
properties.add(javaClassProperty);
}
PropertyValue[] jdbcInfo = properties.toArray(new PropertyValue[properties.size()]);
connection = driverManager.getConnectionWithInfo(jdbcUrl, jdbcInfo);
if (connection != null) {
connection = new PostgresqlConnection(connection, url);
}
} catch (SQLException sqlException) {
throw sqlException;
} catch (Exception exception) {
throw new SQLException(exception.getMessage(), this, StandardSQLState.SQL_UNABLE_TO_CONNECT.text(), 0, exception);
}
}
return connection;
}
@Override
public int getMajorVersion() {
return 1;
}
@Override
public int getMinorVersion() {
return 0;
}
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, PropertyValue[] info) throws SQLException {
if (!acceptsURL(url)) {
return new DriverPropertyInfo[0];
}
return new DriverPropertyInfo [] {
new DriverPropertyInfo("JavaClassName", "The JDBC driver class name.", true,
"com.postgresql.Driver", new String[0]),
};
}
private static String transformUrl(String url) {
// 012345678901234567890
// sdbc:postgresql:jdbc:
return "jdbc:postgresql:" + url.substring(21);
}
// XDataDefinitionSupplier:
public XTablesSupplier getDataDefinitionByConnection(XConnection connection) throws SQLException {
checkDisposed();
return new PostgresqlCatalog((PostgresqlConnection)connection);
}
public XTablesSupplier getDataDefinitionByURL(String url, PropertyValue[] info) throws SQLException {
checkDisposed();
if (!acceptsURL(url)) {
throw new SQLException(); // FIXME
}
return getDataDefinitionByConnection(connect(url, info));
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql;
import com.sun.star.lib.uno.helper.WeakBase;
import com.sun.star.sdbc.DataType;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XResultSetMetaData;
public class PostgresqlResultSetMetaData extends WeakBase implements XResultSetMetaData {
private XResultSetMetaData impl;
public PostgresqlResultSetMetaData(XResultSetMetaData impl) {
this.impl = impl;
}
public String getCatalogName(int arg0) throws SQLException {
return impl.getCatalogName(arg0);
}
public int getColumnCount() throws SQLException {
return impl.getColumnCount();
}
public int getColumnDisplaySize(int arg0) throws SQLException {
return impl.getColumnDisplaySize(arg0);
}
public String getColumnLabel(int arg0) throws SQLException {
return impl.getColumnLabel(arg0);
}
public String getColumnName(int arg0) throws SQLException {
return impl.getColumnName(arg0);
}
public String getColumnServiceName(int arg0) throws SQLException {
return impl.getColumnServiceName(arg0);
}
public int getColumnType(int column) throws SQLException {
int columnType = impl.getColumnType(column);
if (columnType == DataType.BIT) {
String columnName = getColumnTypeName(column);
if (columnName.equals("bool")) {
columnType = DataType.BOOLEAN;
}
}
return columnType;
}
public String getColumnTypeName(int column) throws SQLException {
return impl.getColumnTypeName(column);
}
public int getPrecision(int arg0) throws SQLException {
return impl.getPrecision(arg0);
}
public int getScale(int arg0) throws SQLException {
return impl.getScale(arg0);
}
public String getSchemaName(int arg0) throws SQLException {
return impl.getSchemaName(arg0);
}
public String getTableName(int arg0) throws SQLException {
return impl.getTableName(arg0);
}
public boolean isAutoIncrement(int arg0) throws SQLException {
return impl.isAutoIncrement(arg0);
}
public boolean isCaseSensitive(int arg0) throws SQLException {
return impl.isCaseSensitive(arg0);
}
public boolean isCurrency(int arg0) throws SQLException {
return impl.isCurrency(arg0);
}
public boolean isDefinitelyWritable(int arg0) throws SQLException {
return impl.isDefinitelyWritable(arg0);
}
public int isNullable(int arg0) throws SQLException {
return impl.isNullable(arg0);
}
public boolean isReadOnly(int arg0) throws SQLException {
return impl.isReadOnly(arg0);
}
public boolean isSearchable(int arg0) throws SQLException {
return impl.isSearchable(arg0);
}
public boolean isSigned(int arg0) throws SQLException {
return impl.isSigned(arg0);
}
public boolean isWritable(int arg0) throws SQLException {
return impl.isWritable(arg0);
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql;
import java.util.concurrent.atomic.AtomicBoolean;
import com.sun.star.beans.PropertyVetoException;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertyChangeListener;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.XPropertySetInfo;
import com.sun.star.beans.XVetoableChangeListener;
import com.sun.star.lang.DisposedException;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lib.uno.helper.ComponentBase;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XCloseable;
import com.sun.star.sdbc.XConnection;
import com.sun.star.sdbc.XMultipleResults;
import com.sun.star.sdbc.XResultSet;
import com.sun.star.sdbc.XStatement;
import com.sun.star.sdbc.XWarningsSupplier;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.XCancellable;
public class PostgresqlStatement extends ComponentBase
implements XCloseable, XPropertySet, XCancellable, XStatement, XWarningsSupplier, XMultipleResults {
private XStatement impl;
private XCloseable implCloseable;
private XPropertySet implPropertySet;
private XCancellable implCancellable;
private XWarningsSupplier implWarningsSupplier;
private XMultipleResults implMultipleResults;
private XConnection connection;
private AtomicBoolean isDisposed = new AtomicBoolean(false);
public PostgresqlStatement(XStatement impl, XConnection connection) {
this.impl = impl;
this.implCloseable = UnoRuntime.queryInterface(XCloseable.class, impl);
this.implPropertySet = UnoRuntime.queryInterface(XPropertySet.class, impl);
this.implCancellable = UnoRuntime.queryInterface(XCancellable.class, impl);
this.implWarningsSupplier = UnoRuntime.queryInterface(XWarningsSupplier.class, impl);
this.implMultipleResults = UnoRuntime.queryInterface(XMultipleResults.class, impl);
this.connection = connection;
}
// XComponentBase:
@Override
protected void postDisposing() {
isDisposed.set(true);
try {
implCloseable.close();
} catch (SQLException sqlException) {
}
}
private void checkDisposed() throws DisposedException {
if (isDisposed.get()) {
throw new DisposedException();
}
}
// XStatement:
public boolean execute(String arg0) throws SQLException {
checkDisposed();
System.out.println(arg0);
return impl.execute(arg0);
}
public XResultSet executeQuery(String arg0) throws SQLException {
checkDisposed();
XResultSet results = impl.executeQuery(arg0);
return new PostgresqlResultSet(results, this);
}
public int executeUpdate(String arg0) throws SQLException {
checkDisposed();
return impl.executeUpdate(arg0);
}
public XConnection getConnection() throws SQLException {
checkDisposed();
return connection;
}
// XCloseable:
public void close() throws SQLException {
dispose();
}
// XPropertySet:
public void addPropertyChangeListener(String arg0, XPropertyChangeListener arg1) throws UnknownPropertyException, WrappedTargetException {
checkDisposed();
implPropertySet.addPropertyChangeListener(arg0, arg1);
}
public void addVetoableChangeListener(String arg0, XVetoableChangeListener arg1) throws UnknownPropertyException, WrappedTargetException {
checkDisposed();
implPropertySet.addVetoableChangeListener(arg0, arg1);
}
public XPropertySetInfo getPropertySetInfo() {
checkDisposed();
return implPropertySet.getPropertySetInfo();
}
public Object getPropertyValue(String arg0) throws UnknownPropertyException, WrappedTargetException {
checkDisposed();
return implPropertySet.getPropertyValue(arg0);
}
public void removePropertyChangeListener(String arg0, XPropertyChangeListener arg1) throws UnknownPropertyException, WrappedTargetException {
checkDisposed();
implPropertySet.removePropertyChangeListener(arg0, arg1);
}
public void removeVetoableChangeListener(String arg0, XVetoableChangeListener arg1) throws UnknownPropertyException, WrappedTargetException {
checkDisposed();
implPropertySet.removeVetoableChangeListener(arg0, arg1);
}
public void setPropertyValue(String arg0, Object arg1)
throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException {
checkDisposed();
implPropertySet.setPropertyValue(arg0, arg1);
}
// XCancellable:
public void cancel() {
checkDisposed();
implCancellable.cancel();
}
// XWarningsSupplier:
public void clearWarnings() throws SQLException {
checkDisposed();
implWarningsSupplier.clearWarnings();
}
public Object getWarnings() throws SQLException {
checkDisposed();
return implWarningsSupplier.getWarnings();
}
// XMultipleResults:
public boolean getMoreResults() throws SQLException {
checkDisposed();
return implMultipleResults.getMoreResults();
}
public XResultSet getResultSet() throws SQLException {
checkDisposed();
return new PostgresqlResultSet(implMultipleResults.getResultSet(), this);
}
public int getUpdateCount() throws SQLException {
checkDisposed();
return implMultipleResults.getUpdateCount();
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql;
import java.util.List;
import java.util.Map;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.ElementExistException;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XConnection;
import com.sun.star.sdbcx.comp.postgresql.comphelper.CompHelper;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.OColumnContainer;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.OContainer;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.OIndexContainer;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.OKey;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.OKeyContainer;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.OTable;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.SqlTableHelper;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.SqlTableHelper.ColumnDescription;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.descriptors.SdbcxTableDescriptor;
public class PostgresqlTable extends OTable {
private PostgresqlTable(Object lock, XConnection connection, OContainer tables, String name,
String catalogName, String schemaName, String description, String type) {
super(lock, name, true, connection, tables);
super.catalogName = catalogName;
super.schemaName = schemaName;
super.description = description;
super.type = type;
}
public static PostgresqlTable create(XConnection connection, OContainer tables, String name,
String catalogName, String schemaName, String description, String type) {
Object lock = new Object();
return new PostgresqlTable(lock, connection, tables, name, catalogName, schemaName, description, type);
}
@Override
public XPropertySet createDataDescriptor() {
SdbcxTableDescriptor descriptor = SdbcxTableDescriptor.create(true);
synchronized (lock) {
CompHelper.copyProperties(this, descriptor);
}
return descriptor;
}
@Override
public void setName(String name) {
// TODO Auto-generated method stub
}
@Override
public void rename(String name) throws SQLException, ElementExistException {
// TODO Auto-generated method stub
}
@Override
public void alterColumnByIndex(int index, XPropertySet descriptor) throws SQLException, IndexOutOfBoundsException {
// TODO Auto-generated method stub
}
@Override
public void alterColumnByName(String name, XPropertySet descriptor) throws SQLException, NoSuchElementException {
// TODO Auto-generated method stub
}
@Override
protected OContainer refreshColumns() {
try {
List<ColumnDescription> columns = new SqlTableHelper().readColumns(getConnection().getMetaData(), catalogName, schemaName, getName());
return new OColumnContainer(lock, isCaseSensitive(), columns, this, getConnection().getMetaData());
} catch (SQLException sqlException) {
return null;
}
}
@Override
protected OContainer refreshIndexes() {
try {
List<String> indexes = new SqlTableHelper().readIndexes(getConnection().getMetaData(), catalogName, schemaName, getName(), this);
return new OIndexContainer(lock, indexes, isCaseSensitive(), this);
} catch (SQLException sqlException) {
return null;
}
}
@Override
protected OContainer refreshKeys() {
try {
Map<String, OKey> keys = new SqlTableHelper().readKeys(
getConnection().getMetaData(), catalogName, schemaName, getName(), isCaseSensitive(), this);
return OKeyContainer.create(isCaseSensitive(), keys, this);
} catch (SQLException sqlException) {
return null;
}
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql;
import java.util.List;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XDatabaseMetaData;
import com.sun.star.sdbc.XResultSet;
import com.sun.star.sdbc.XRow;
import com.sun.star.sdbc.XStatement;
import com.sun.star.sdbcx.comp.postgresql.comphelper.CompHelper;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.OContainer;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.descriptors.SdbcxTableDescriptor;
import com.sun.star.sdbcx.comp.postgresql.util.ComposeRule;
import com.sun.star.sdbcx.comp.postgresql.util.DbTools;
import com.sun.star.sdbcx.comp.postgresql.util.PropertyIds;
import com.sun.star.sdbcx.comp.postgresql.util.StandardSQLState;
import com.sun.star.sdbcx.comp.postgresql.util.DbTools.NameComponents;
import com.sun.star.uno.Any;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.UnoRuntime;
public class PostgresqlTables extends OContainer {
private XDatabaseMetaData metadata;
private PostgresqlCatalog catalog;
public PostgresqlTables(Object lock, XDatabaseMetaData metadata, PostgresqlCatalog catalog, List<String> names) {
super(lock, true, names);
this.metadata = metadata;
this.catalog = catalog;
}
@Override
public XPropertySet createObject(String name) throws SQLException {
NameComponents nameComponents = DbTools.qualifiedNameComponents(metadata, name, ComposeRule.InDataManipulation);
Object queryCatalog = nameComponents.getCatalog().isEmpty() ? Any.VOID : nameComponents.getCatalog();
XPropertySet ret = null;
XResultSet results = null;
try {
results = metadata.getTables(
queryCatalog, nameComponents.getSchema(), nameComponents.getTable(), new String[] { "VIEW", "TABLE", "%" });
if (results != null) {
XRow row = UnoRuntime.queryInterface(XRow.class, results);
if (results.next()) {
String type = row.getString(4);
String remarks = row.getString(5);
ret = PostgresqlTable.create(metadata.getConnection(), this, nameComponents.getTable(),
nameComponents.getCatalog(), nameComponents.getSchema(), remarks, type);
}
}
} finally {
CompHelper.disposeComponent(results);
}
return ret;
}
@Override
public void dropObject(int index, String name) throws SQLException {
try {
Object object = getObject(index);
NameComponents nameComponents = DbTools.qualifiedNameComponents(metadata, name, ComposeRule.InDataManipulation);
boolean isView = false;
XPropertySet propertySet = UnoRuntime.queryInterface(XPropertySet.class, object);
if (propertySet != null) {
isView = AnyConverter.toString(propertySet.getPropertyValue(PropertyIds.TYPE.name)).equals("VIEW");
}
String composedName = DbTools.composeTableName(metadata, nameComponents.getCatalog(), nameComponents.getSchema(), nameComponents.getTable(),
true, ComposeRule.InDataManipulation);
String sql = String.format("DROP %s %s", isView ? "VIEW" : "TABLE", composedName);
XStatement statement = null;
try {
statement = metadata.getConnection().createStatement();
statement.execute(sql);
} finally {
CompHelper.disposeComponent(statement);
}
// FIXME: delete it from our views
} catch (IllegalArgumentException illegalArgumentException) {
throw new SQLException("Error", this, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, illegalArgumentException);
} catch (UnknownPropertyException unknownPropertyException) {
throw new SQLException("Error", this, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, unknownPropertyException);
} catch (WrappedTargetException wrappedTargetException) {
throw new SQLException("Error", this, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, wrappedTargetException);
}
}
@Override
public void impl_refresh() {
catalog.refreshTables();
}
@Override
public XPropertySet createDescriptor() {
return SdbcxTableDescriptor.create(true);
}
@Override
public XPropertySet appendObject(String name, XPropertySet descriptor) throws SQLException {
createTable(descriptor);
return createObject(name);
}
void createTable(XPropertySet descriptor) throws SQLException {
XStatement statement = null;
try {
String sql = DbTools.createSqlCreateTableStatement(descriptor, metadata.getConnection(), null, "(M,D)");
statement = metadata.getConnection().createStatement();
statement.execute(sql);
} catch (IndexOutOfBoundsException indexOutOfBoundsException) {
throw new SQLException("Error", this, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, indexOutOfBoundsException);
} catch (IllegalArgumentException illegalArgumentException) {
throw new SQLException("Error", this, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, illegalArgumentException);
} catch (UnknownPropertyException unknownPropertyException) {
throw new SQLException("Error", this, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, unknownPropertyException);
} catch (WrappedTargetException wrappedTargetException) {
throw new SQLException("Error", this, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, wrappedTargetException);
} finally {
CompHelper.disposeComponent(statement);
}
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.comphelper;
import com.sun.star.beans.Property;
import com.sun.star.beans.PropertyAttribute;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.XPropertySetInfo;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.uno.UnoRuntime;
public class CompHelper {
/**
* If the given parameter is an XComponent, calls dispose() on it.
* @param object the UNO interface to try dispose; may be null.
*/
public static void disposeComponent(final Object object) {
final XComponent component = UnoRuntime.queryInterface(XComponent.class, object);
if (component != null) {
component.dispose();
}
}
public static void copyProperties(final XPropertySet src, final XPropertySet dst) {
if (src == null || dst == null) {
return;
}
XPropertySetInfo srcPropertySetInfo = src.getPropertySetInfo();
XPropertySetInfo dstPropertySetInfo = dst.getPropertySetInfo();
for (Property srcProperty : srcPropertySetInfo.getProperties()) {
if (dstPropertySetInfo.hasPropertyByName(srcProperty.Name)) {
try {
Property dstProperty = dstPropertySetInfo.getPropertyByName(srcProperty.Name);
if ((dstProperty.Attributes & PropertyAttribute.READONLY) == 0) {
Object value = src.getPropertyValue(srcProperty.Name);
if ((dstProperty.Attributes & PropertyAttribute.MAYBEVOID) == 0 || value != null) {
dst.setPropertyValue(srcProperty.Name, value);
}
}
} catch (Exception e) {
String error = "Could not copy property '" + srcProperty.Name +
"' to the destination set";
XServiceInfo serviceInfo = UnoRuntime.queryInterface(XServiceInfo.class, dst);
if (serviceInfo != null) {
error += " (a '" + serviceInfo.getImplementationName() + "' implementation)";
}
}
}
}
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.comphelper;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.container.XEnumeration;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lib.uno.helper.WeakBase;
public class OArrayEnumeration extends WeakBase implements XEnumeration {
private Object[] elements;
private int position;
public OArrayEnumeration(Object[] elements) {
this.elements = elements;
}
@Override
public boolean hasMoreElements() {
synchronized (this) {
return position < elements.length;
}
}
@Override
public Object nextElement()
throws NoSuchElementException, WrappedTargetException {
synchronized (this) {
if (position < elements.length) {
return elements[position++];
} else {
throw new NoSuchElementException();
}
}
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.comphelper;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.container.XEnumeration;
import com.sun.star.container.XIndexAccess;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XEventListener;
import com.sun.star.lib.uno.helper.WeakBase;
import com.sun.star.uno.UnoRuntime;
public class OEnumerationByIndex extends WeakBase implements XEnumeration, XEventListener {
private XIndexAccess collection;
private int position;
boolean isListening;
public OEnumerationByIndex(XIndexAccess collection) {
this.collection = collection;
startDisposeListening();
}
@Override
public void disposing(EventObject event) {
synchronized (this) {
if (event.Source == collection) {
collection = null;
}
}
}
@Override
public boolean hasMoreElements() {
synchronized (this) {
if (collection != null) {
if (position < collection.getCount()) {
return true;
} else {
stopDisposeListening();
collection = null;
}
}
return false;
}
}
@Override
public Object nextElement()
throws NoSuchElementException, WrappedTargetException {
Object value = null;
synchronized (this) {
if (collection != null) {
if (position < collection.getCount()) {
try {
value = collection.getByIndex(position++);
} catch (com.sun.star.lang.IndexOutOfBoundsException indexOutOfBoundsException) {
// can't happen
}
}
if (position >= collection.getCount()) {
stopDisposeListening();
collection = null;
}
}
}
if (value == null) {
throw new NoSuchElementException();
}
return value;
}
private void startDisposeListening() {
synchronized (this) {
if (isListening) {
return;
}
XComponent component = UnoRuntime.queryInterface(XComponent.class, collection);
if (component != null) {
component.addEventListener(this);
isListening = true;
}
}
}
private void stopDisposeListening() {
synchronized (this) {
if (!isListening) {
return;
}
XComponent component = UnoRuntime.queryInterface(XComponent.class, collection);
if (component != null) {
component.removeEventListener(this);
isListening = false;
}
}
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.comphelper;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.container.XEnumeration;
import com.sun.star.container.XNameAccess;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XEventListener;
import com.sun.star.lib.uno.helper.WeakBase;
import com.sun.star.uno.UnoRuntime;
public class OEnumerationByName extends WeakBase implements XEnumeration, XEventListener {
private String[] names;
private int position;
private XNameAccess collection;
private boolean isListening;
public OEnumerationByName(XNameAccess collection) {
this.collection = collection;
names = collection.getElementNames();
startDisposeListening();
}
@Override
public void disposing(EventObject event) {
synchronized (this) {
if (event.Source == collection) {
collection = null;
}
}
}
@Override
public boolean hasMoreElements() {
synchronized (this) {
if (collection != null) {
if (position < names.length) {
return true;
} else {
stopDisposeListening();
collection = null;
}
}
return false;
}
}
@Override
public Object nextElement()
throws NoSuchElementException, WrappedTargetException {
Object value = null;
synchronized (this) {
if (collection != null) {
if (position < names.length) {
value = collection.getByName(names[position++]);
}
if (position >= names.length) {
stopDisposeListening();
collection = null;
}
}
}
if (value == null) {
throw new NoSuchElementException();
}
return value;
}
private void startDisposeListening() {
synchronized (this) {
if (isListening) {
return;
}
XComponent component = UnoRuntime.queryInterface(XComponent.class, collection);
if (component != null) {
component.addEventListener(this);
isListening = true;
}
}
}
private void stopDisposeListening() {
synchronized (this) {
if (!isListening) {
return;
}
XComponent component = UnoRuntime.queryInterface(XComponent.class, collection);
if (component != null) {
component.removeEventListener(this);
isListening = false;
}
}
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.comphelper;
import com.sun.star.beans.PropertyVetoException;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XFastPropertySet;
import com.sun.star.beans.XMultiPropertySet;
import com.sun.star.beans.XPropertiesChangeListener;
import com.sun.star.beans.XPropertyChangeListener;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.XPropertySetInfo;
import com.sun.star.beans.XVetoableChangeListener;
import com.sun.star.lang.DisposedException;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lib.uno.helper.ComponentBase;
import com.sun.star.sdbcx.comp.postgresql.comphelper.PropertySetAdapter.PropertyGetter;
import com.sun.star.sdbcx.comp.postgresql.comphelper.PropertySetAdapter.PropertySetter;
import com.sun.star.uno.Type;
public class PropertySet extends ComponentBase implements XPropertySet, XFastPropertySet, XMultiPropertySet {
private final PropertySetAdapter impl;
protected PropertySet(Object lock) {
impl = new PropertySetAdapter(lock, this);
}
@Override
protected void postDisposing() {
impl.dispose();
}
public void registerProperty(String propertyName, int handle, Type type, short attributes, PropertyGetter getter, PropertySetter setter) {
impl.registerProperty(propertyName, handle, type, attributes, getter, setter);
}
public void registerProperty(String propertyName, Type type, short attributes, PropertyGetter getter, PropertySetter setter) {
impl.registerProperty(propertyName, type, attributes, getter, setter);
}
public void addPropertyChangeListener(String propertyName, XPropertyChangeListener listener) throws UnknownPropertyException, WrappedTargetException {
// only add listeners if you are not disposed
if (!bInDispose && !bDisposed) {
impl.addPropertyChangeListener(propertyName, listener);
}
}
public void addVetoableChangeListener(String propertyName, XVetoableChangeListener listener) throws UnknownPropertyException, WrappedTargetException {
// only add listeners if you are not disposed
if (!bInDispose && !bDisposed) {
impl.addVetoableChangeListener(propertyName, listener);
}
}
public void addPropertiesChangeListener(String[] propertyNames, XPropertiesChangeListener listener) {
// only add listeners if you are not disposed
if (!bInDispose && !bDisposed) {
impl.addPropertiesChangeListener(propertyNames, listener);
}
}
public XPropertySetInfo getPropertySetInfo() {
return impl.getPropertySetInfo();
}
public Object getPropertyValue(String propertyName) throws UnknownPropertyException, WrappedTargetException {
if (bInDispose || bDisposed) {
throw new DisposedException("Component is already disposed");
}
return impl.getPropertyValue(propertyName);
}
@Override
public Object getFastPropertyValue(int handle) throws UnknownPropertyException, WrappedTargetException {
if (bInDispose || bDisposed) {
throw new DisposedException("Component is already disposed");
}
return impl.getFastPropertyValue(handle);
}
public Object[] getPropertyValues(String[] propertyNames) {
if (bInDispose || bDisposed) {
throw new DisposedException("Component is already disposed");
}
return impl.getPropertyValues(propertyNames);
}
public void removePropertyChangeListener(String propertyName, XPropertyChangeListener listener) throws UnknownPropertyException, WrappedTargetException {
// all listeners are automatically released in a dispose call
if (!bInDispose && !bDisposed) {
impl.removePropertyChangeListener(propertyName, listener);
}
}
public void removeVetoableChangeListener(String propertyName, XVetoableChangeListener listener) throws UnknownPropertyException, WrappedTargetException {
// all listeners are automatically released in a dispose call
if (!bInDispose && !bDisposed) {
impl.removeVetoableChangeListener(propertyName, listener);
}
}
public void removePropertiesChangeListener(XPropertiesChangeListener listener) {
// all listeners are automatically released in a dispose call
if (!bInDispose && !bDisposed) {
impl.removePropertiesChangeListener(listener);
}
}
public void setPropertyValue(String propertyName, Object value)
throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException {
if (bInDispose || bDisposed) {
throw new DisposedException("Component is already disposed");
}
impl.setPropertyValue(propertyName, value);
}
public void setFastPropertyValue(int handle, Object value)
throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException {
if (bInDispose || bDisposed) {
throw new DisposedException("Component is already disposed");
}
impl.setFastPropertyValue(handle, value);
}
public void setPropertyValues(String[] propertyNames, Object[] values) throws PropertyVetoException, IllegalArgumentException, WrappedTargetException {
if (bInDispose || bDisposed) {
throw new DisposedException("Component is already disposed");
}
impl.setPropertyValues(propertyNames, values);
}
public void firePropertiesChangeEvent(String[] propertyNames, XPropertiesChangeListener listener) {
if (bInDispose || bDisposed) {
throw new DisposedException("Component is already disposed");
}
impl.firePropertiesChangeEvent(propertyNames, listener);
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.sdbcx;
import com.sun.star.beans.XPropertySet;
public interface ISQLStatementHelper {
void addComment(XPropertySet propertySet, StringBuilder sql);
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.sdbcx;
import com.sun.star.container.XNameAccess;
import com.sun.star.lang.DisposedException;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lib.uno.helper.ComponentBase;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XDatabaseMetaData;
import com.sun.star.sdbc.XRow;
import com.sun.star.sdbcx.XGroupsSupplier;
import com.sun.star.sdbcx.XTablesSupplier;
import com.sun.star.sdbcx.XUsersSupplier;
import com.sun.star.sdbcx.XViewsSupplier;
import com.sun.star.sdbcx.comp.postgresql.util.ComposeRule;
import com.sun.star.sdbcx.comp.postgresql.util.DbTools;
public abstract class OCatalog extends ComponentBase
implements XTablesSupplier, XViewsSupplier, XUsersSupplier, XGroupsSupplier, XServiceInfo {
private static final String[] services = {
"com.sun.star.sdbcx.DatabaseDefinition"
};
protected final Object lock = new Object();
// Deleted on destruction, weakly held by caller:
protected OContainer tables;
protected OContainer views;
protected OContainer groups;
protected OContainer users;
protected XDatabaseMetaData metadata;
public OCatalog(XDatabaseMetaData metadata) {
this.metadata = metadata;
}
private void checkDisposed() throws DisposedException {
if (bInDispose || bDisposed) {
throw new DisposedException();
}
}
@Override
protected void postDisposing() {
synchronized (lock) {
if (tables != null) {
tables.dispose();
}
if (views != null) {
views.dispose();
}
if (groups != null) {
groups.dispose();
}
if (users != null) {
users.dispose();
}
}
}
// XServiceInfo
@Override
public String getImplementationName() {
return "com.sun.star.comp.connectivity.OCatalog";
}
@Override
public String[] getSupportedServiceNames() {
return services.clone();
}
@Override
public boolean supportsService(String serviceName) {
for (String service : getSupportedServiceNames()) {
if (service.equals(serviceName)) {
return true;
}
}
return false;
}
// X(Tables/Views/Groups/Users)Supplier
@Override
public XNameAccess getTables() {
checkDisposed();
synchronized (lock) {
if (tables == null) {
tables = refreshTables();
}
return tables;
}
}
@Override
public XNameAccess getViews() {
checkDisposed();
synchronized (lock) {
if (views == null) {
views = refreshViews();
}
return views;
}
}
@Override
public XNameAccess getGroups() {
checkDisposed();
synchronized (lock) {
if (groups == null) {
groups = refreshGroups();
}
return groups;
}
}
@Override
public XNameAccess getUsers() {
checkDisposed();
synchronized (lock) {
if (users == null) {
users = refreshUsers();
}
return users;
}
}
protected String buildName(XRow row) throws SQLException {
String catalog = row.getString(1);
if (row.wasNull()) {
catalog = "";
}
String schema = row.getString(2);
if (row.wasNull()) {
schema = null;
}
String table = row.getString(3);
if (row.wasNull()) {
table = "";
}
return DbTools.composeTableName(metadata, catalog, schema, table, false, ComposeRule.InDataManipulation);
}
public abstract OContainer refreshTables();
public abstract OContainer refreshViews();
public abstract OContainer refreshGroups();
public abstract OContainer refreshUsers();
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.sdbcx;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XNameAccess;
import com.sun.star.sdbc.ColumnValue;
import com.sun.star.sdbc.DataType;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XDatabaseMetaData;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.SqlTableHelper.ColumnDescription;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.descriptors.SdbcxColumnDescriptor;
import com.sun.star.sdbcx.comp.postgresql.util.DbTools;
import com.sun.star.uno.UnoRuntime;
public class OColumnContainer extends OContainer {
private OTable table;
private XDatabaseMetaData metadata;
private Map<String,ColumnDescription> columnDescriptions = new HashMap<>();
private Map<String,ExtraColumnInfo> extraColumnInfo = new HashMap<>();
/// The XDatabaseMetaData.getColumns() data stored in columnDescriptions doesn't provide everything we need, so this class stores the rest.
public static class ExtraColumnInfo {
public boolean isAutoIncrement;
public boolean isCurrency;
public int dataType;
}
public OColumnContainer(Object lock, boolean isCaseSensitive, List<ColumnDescription> columnDescriptions, OTable table, XDatabaseMetaData metadata) {
super(lock, isCaseSensitive, toColumnNames(columnDescriptions));
this.table = table;
this.metadata = metadata;
for (ColumnDescription columnDescription : columnDescriptions) {
this.columnDescriptions.put(columnDescription.columnName, columnDescription);
}
}
private static List<String> toColumnNames(List<ColumnDescription> columns) {
List<String> columnNames = new ArrayList<>(columns.size());
for (ColumnDescription columnDescription : columns) {
columnNames.add(columnDescription.columnName);
}
return columnNames;
}
@Override
public XPropertySet createObject(String name) throws SQLException {
boolean queryInfo = true;
boolean isAutoIncrement = false;
boolean isCurrency = false;
int dataType = DataType.OTHER;
ExtraColumnInfo columnInfo = extraColumnInfo.get(name);
if (columnInfo == null) {
String composedName = DbTools.composeTableNameForSelect(metadata.getConnection(), table);
extraColumnInfo = DbTools.collectColumnInformation(metadata.getConnection(), composedName, "*");
columnInfo = extraColumnInfo.get(name);
}
if (columnInfo != null) {
queryInfo = false;
isAutoIncrement = columnInfo.isAutoIncrement;
isCurrency = columnInfo.isCurrency;
dataType = columnInfo.dataType;
}
ColumnDescription columnDescription = columnDescriptions.get(name);
if (columnDescription != null) {
XNameAccess primaryKeyColumns = DbTools.getPrimaryKeyColumns(UnoRuntime.queryInterface(XPropertySet.class, table));
int nullable = columnDescription.nullable;
if (nullable != ColumnValue.NO_NULLS && primaryKeyColumns != null && primaryKeyColumns.hasByName(name)) {
nullable = ColumnValue.NO_NULLS;
}
return OColumn.create(name, columnDescription.typeName, columnDescription.defaultValue, columnDescription.remarks,
nullable, columnDescription.columnSize, columnDescription.decimalDigits, columnDescription.type,
isAutoIncrement, false, isCurrency, isCaseSensitive());
} else {
// FIXME: do something like the C++ implementation does?
throw new SQLException();
}
}
@Override
public XPropertySet createDescriptor() {
return SdbcxColumnDescriptor.create(isCaseSensitive());
}
@Override
public void impl_refresh() {
extraColumnInfo.clear();
table.refreshColumns();
}
@Override
public XPropertySet appendObject(String _rForName, XPropertySet descriptor) throws SQLException {
return null;
}
@Override
public void dropObject(int index, String name) throws SQLException {
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.sdbcx;
import com.sun.star.beans.PropertyAttribute;
import com.sun.star.sdbcx.comp.postgresql.comphelper.PropertySet;
import com.sun.star.sdbcx.comp.postgresql.comphelper.PropertySetAdapter.PropertyGetter;
import com.sun.star.sdbcx.comp.postgresql.comphelper.PropertySetAdapter.PropertySetter;
import com.sun.star.sdbcx.comp.postgresql.util.PropertyIds;
import com.sun.star.uno.Type;
public class ODescriptor extends PropertySet {
private String name;
private final boolean isCaseSensitive;
protected final Object lock;
public ODescriptor(Object lock, String name, boolean isCaseSensitive, boolean isReadOnly) {
super(lock);
this.lock = lock;
this.name = name;
this.isCaseSensitive = isCaseSensitive;
registerProperties(isReadOnly);
}
public ODescriptor(Object lock, String name, boolean isCaseSensitive) {
this(lock, name, isCaseSensitive, true);
}
private void registerProperties(boolean isReadOnly) {
registerProperty(PropertyIds.NAME.name, PropertyIds.NAME.id, Type.STRING, isReadOnly ? PropertyAttribute.READONLY : 0,
new PropertyGetter() {
@Override
public Object getValue() {
return name;
}
},
isReadOnly ? null : new PropertySetter() {
@Override
public void setValue(Object value) {
name = (String) value;
}
});
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isCaseSensitive() {
return isCaseSensitive;
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.sdbcx;
import java.util.List;
import com.sun.star.beans.PropertyAttribute;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XNameAccess;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbcx.XColumnsSupplier;
import com.sun.star.sdbcx.XDataDescriptorFactory;
import com.sun.star.sdbcx.comp.postgresql.comphelper.CompHelper;
import com.sun.star.sdbcx.comp.postgresql.comphelper.PropertySetAdapter.PropertyGetter;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.descriptors.SdbcxIndexDescriptor;
import com.sun.star.sdbcx.comp.postgresql.util.DbTools;
import com.sun.star.sdbcx.comp.postgresql.util.PropertyIds;
import com.sun.star.uno.Type;
public class OIndex extends ODescriptor implements XColumnsSupplier, XDataDescriptorFactory {
protected String catalogName;
protected boolean isUnique;
protected boolean isPrimaryKeyIndex;
protected boolean isClustered;
private OTable table;
private OContainer columns;
protected OIndex(Object lock, String name, boolean isCaseSensitive, String catalogName,
boolean isUnique, boolean isPrimaryKeyIndex, boolean isClustered, List<String> columnNames, OTable table) {
super(lock, name, isCaseSensitive);
this.catalogName = catalogName;
this.isUnique = isUnique;
this.isPrimaryKeyIndex = isPrimaryKeyIndex;
this.isClustered = isClustered;
this.table = table;
columns = new OIndexColumnContainer(lock, this, columnNames);
registerProperties();
}
public static OIndex create(String name, boolean isCaseSensitive, String catalogName,
boolean isUnique, boolean isPrimaryKeyIndex, boolean isClustered, List<String> columnNames, OTable table) {
final Object lock = new Object();
return new OIndex(lock, name, isCaseSensitive, catalogName, isUnique, isPrimaryKeyIndex, isClustered, columnNames, table);
}
private void registerProperties() {
registerProperty(PropertyIds.CATALOG.name, PropertyIds.CATALOG.id, Type.STRING, (short)PropertyAttribute.READONLY,
new PropertyGetter() {
@Override
public Object getValue() {
return catalogName;
}
}, null);
registerProperty(PropertyIds.ISPRIMARYKEYINDEX.name, PropertyIds.ISPRIMARYKEYINDEX.id, Type.BOOLEAN, (short)PropertyAttribute.READONLY,
new PropertyGetter() {
@Override
public Object getValue() {
return isPrimaryKeyIndex;
}
}, null);
registerProperty(PropertyIds.ISCLUSTERED.name, PropertyIds.ISCLUSTERED.id, Type.BOOLEAN, (short)PropertyAttribute.READONLY,
new PropertyGetter() {
@Override
public Object getValue() {
return isClustered;
}
}, null);
registerProperty(PropertyIds.ISUNIQUE.name, PropertyIds.ISUNIQUE.id, Type.BOOLEAN, (short)PropertyAttribute.READONLY,
new PropertyGetter() {
@Override
public Object getValue() {
return isUnique;
}
}, null);
}
@Override
public XPropertySet createDataDescriptor() {
SdbcxIndexDescriptor descriptor = SdbcxIndexDescriptor.create(isCaseSensitive());
CompHelper.copyProperties(this, descriptor);
try {
DbTools.cloneDescriptorColumns(this, descriptor);
} catch (SQLException sqlException) {
}
return descriptor;
}
@Override
public XNameAccess getColumns() {
return columns;
}
public OTable getTable() {
return table;
}
@Override
public String toString() {
return "OIndex [catalogName=" + catalogName + ", isUnique=" + isUnique + ", isPrimaryKeyIndex=" + isPrimaryKeyIndex + ", isClustered=" + isClustered
+ ", name=" + getName() + "]";
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.sdbcx;
import com.sun.star.beans.PropertyAttribute;
import com.sun.star.beans.XPropertySet;
import com.sun.star.sdbcx.comp.postgresql.comphelper.CompHelper;
import com.sun.star.sdbcx.comp.postgresql.comphelper.PropertySetAdapter.PropertyGetter;
import com.sun.star.sdbcx.comp.postgresql.sdbcx.descriptors.SdbcxIndexColumnDescriptor;
import com.sun.star.sdbcx.comp.postgresql.util.PropertyIds;
import com.sun.star.uno.Type;
public class OIndexColumn extends OColumn {
protected boolean isAscending;
protected OIndexColumn(
final Object lock,
final boolean isAscending,
final String name,
final String typeName,
final String defaultValue,
final String description,
final int isNullable,
final int precision,
final int scale,
final int type,
final boolean isAutoIncrement,
final boolean isRowVersion,
final boolean isCurrency,
final boolean isCaseSensitive) {
super(lock, name, typeName, defaultValue, description, isNullable,
precision, scale, type, isAutoIncrement, isRowVersion, isCurrency, isCaseSensitive);
this.isAscending = isAscending;
registerProperties();
}
public static OIndexColumn create(
final boolean isAscending,
final String name,
final String typeName,
final String defaultValue,
final int isNullable,
final int precision,
final int scale,
final int type,
final boolean isAutoIncrement,
final boolean isRowVersion,
final boolean isCurrency,
final boolean isCaseSensitive) {
final Object lock = new Object();
return new OIndexColumn(lock, isAscending, name, typeName,
defaultValue, "", isNullable, precision, scale,
type, isAutoIncrement, isRowVersion, isCurrency, isCaseSensitive);
}
private void registerProperties() {
registerProperty(PropertyIds.ISASCENDING.name, PropertyIds.ISASCENDING.id, Type.BOOLEAN, PropertyAttribute.READONLY,
new PropertyGetter() {
@Override
public Object getValue() {
return isAscending;
}
}, null);
}
// XDataDescriptorFactory
@Override
public XPropertySet createDataDescriptor() {
SdbcxIndexColumnDescriptor descriptor = SdbcxIndexColumnDescriptor.create(isCaseSensitive());
synchronized (lock) {
CompHelper.copyProperties(this, descriptor);
}
return descriptor;
}
}
/**************************************************************
*
* 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 com.sun.star.sdbcx.comp.postgresql.sdbcx;
public class Resources {
public static final int STR_COMMON_BASE = 1200;
public static final int STR_STRING_LENGTH_EXCEEDED = (STR_COMMON_BASE + 1);
public static final int STR_CANNOT_CONVERT_STRING = (STR_COMMON_BASE + 2);
public static final int STR_URI_SYNTAX_ERROR = (STR_COMMON_BASE + 3);
public static final int STR_COULD_NOT_LOAD_FILE = (STR_COMMON_BASE + 4);
public static final int STR_QUERY_TOO_COMPLEX = (STR_COMMON_BASE + 5);
public static final int STR_OPERATOR_TOO_COMPLEX = (STR_COMMON_BASE + 6);
public static final int STR_QUERY_INVALID_LIKE_COLUMN = (STR_COMMON_BASE + 7);
public static final int STR_QUERY_INVALID_LIKE_STRING = (STR_COMMON_BASE + 8);
public static final int STR_QUERY_NOT_LIKE_TOO_COMPLEX = (STR_COMMON_BASE + 9);
public static final int STR_QUERY_LIKE_WILDCARD = (STR_COMMON_BASE + 10);
public static final int STR_QUERY_LIKE_WILDCARD_MANY = (STR_COMMON_BASE + 11);
public static final int STR_INVALID_COLUMNNAME = (STR_COMMON_BASE + 12);
public static final int STR_NO_CLASSNAME = (STR_COMMON_BASE + 13);
public static final int STR_NO_CLASSNAME_PATH = (STR_COMMON_BASE + 14);
public static final int STR_UNKNOWN_PARA_TYPE = (STR_COMMON_BASE + 15);
public static final int STR_INVALID_COLUMN_SELECTION = (STR_COMMON_BASE + 16);
public static final int STR_PARA_ONLY_PREPARED = (STR_COMMON_BASE + 17);
public static final int STR_COLUMN_NOT_UPDATEABLE = (STR_COMMON_BASE + 18);
public static final int STR_ROW_ALREADY_DELETED = (STR_COMMON_BASE + 19);
public static final int STR_UNKNOWN_COLUMN_TYPE = (STR_COMMON_BASE + 20);
public static final int STR_FORMULA_WRONG = (STR_COMMON_BASE + 21);
public static final int STR_NO_JAVA = (STR_COMMON_BASE + 22);
public static final int STR_NO_RESULTSET = (STR_COMMON_BASE + 23);
public static final int STR_NO_ROWCOUNT = (STR_COMMON_BASE + 24);
public static final int STR_ERRORMSG_SEQUENCE = (STR_COMMON_BASE + 25);
public static final int STR_INVALID_INDEX = (STR_COMMON_BASE + 26);
public static final int STR_UNSUPPORTED_FUNCTION = (STR_COMMON_BASE + 27);
public static final int STR_UNSUPPORTED_FEATURE = (STR_COMMON_BASE + 28);
public static final int STR_UNKNOWN_COLUMN_NAME = (STR_COMMON_BASE + 29);
public static final int STR_INVALID_PARA_COUNT = (STR_COMMON_BASE + 30);
public static final int STR_PRIVILEGE_NOT_GRANTED = (STR_COMMON_BASE + 31);
public static final int STR_PRIVILEGE_NOT_REVOKED = (STR_COMMON_BASE + 32);
public static final int STR_INVALID_BOOKMARK = (STR_COMMON_BASE + 33);
public static final int STR_NO_ELEMENT_NAME = (STR_COMMON_BASE + 34);
public static final int STR_NO_INPUTSTREAM = (STR_COMMON_BASE + 35);
public static final int STR_INPUTSTREAM_WRONG_LEN = (STR_COMMON_BASE + 36);
public static final int STR_WRONG_PARAM_INDEX = (STR_COMMON_BASE + 37);
public static final int STR_NO_CONNECTION_GIVEN = (STR_COMMON_BASE + 38);
}
cn connectivity : shell L10N:l10n comphelper SO:moz_prebuilt svl UNIXODBC:unixODBC unoil javaunohelper HSQLDB:hsqldb qadevOOo officecfg LIBXSLT:libxslt NULL
cn connectivity : shell L10N:l10n comphelper SO:moz_prebuilt svl UNIXODBC:unixODBC unoil javaunohelper HSQLDB:hsqldb qadevOOo officecfg LIBXSLT:libxslt apache-commons NULL
cn connectivity usr1 - all cn_mkout NULL
cn connectivity\inc nmake - all cn_inc NULL
cn connectivity\java\sdbc_hsqldb nmake - all cn_jhsqldbdb cn_hsqldb cn_inc NULL
cn connectivity\java\sdbc_postgresql nmake - all cn_postgresqldb cn_dbtools cn_inc NULL
cn connectivity\source\commontools nmake - all cn_cmtools cn_parse cn_inc NULL
cn connectivity\source\manager nmake - all cn_manager cn_dbtools cn_inc NULL
cn connectivity\source\cpool nmake - all cn_cpool cn_dbtools cn_inc NULL
......
This diff is collapsed.
......@@ -21,7 +21,8 @@
.INCLUDE : target.mk
#.INCLUDE : target.mk
.INCLUDE : ant.mk
COMPONENT_CONFIG_SCHEMA*=$(TARGET).xcs
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment