提交 597600a2 编写于 作者: T titou10

Denis Forveille: Initial commit for db2 plugin

上级 08e33bb8
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.jkiss.dbeaver.resources.db2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
source.. =
bin.includes = .,plugin.xml,META-INF/,drivers/db2/LICENSE.txt,drivers/db2/db2jcc.jar,drivers/db2/db2jcc_license_cu.jar
bin.includes = .,plugin.xml,META-INF/,drivers/db2/LICENSE.txt,drivers/db2/db2jcc4.jar,drivers/db2/db2jcc.jar,drivers/db2/db2jcc_license_cu.jar
src.includes =
......@@ -2,6 +2,7 @@
<plugin>
<extension point="org.jkiss.dbeaver.resources">
<resource name="drivers/db2/LICENSE.txt"/>
<resource name="drivers/db2/db2jcc4.jar"/>
<resource name="drivers/db2/db2jcc.jar"/>
<resource name="drivers/db2/db2jcc_license_cu.jar"/>
</extension>
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.jkiss.dbeaver.db2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
#Thu Dec 30 16:00:50 MSK 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
DB2 Technology Network Development and Distribution License Terms
Export Controls on the Programs
Selecting the "Accept License Agreement" button is a confirmation of your agreement that you comply, now and during the trial term, with each of the following statements:
-You are not a citizen, national, or resident of, and are not under control of, the government of Cuba, Iran, Sudan, Libya, North Korea, Syria, nor any country to which the United States has prohibited export.
-You will not download or otherwise export or re-export the Programs, directly or indirectly, to the above mentioned countries nor to citizens, nationals or residents of those countries.
-You are not listed on the United States Department of Treasury lists of Specially Designated Nationals, Specially Designated Terrorists, and Specially Designated Narcotic Traffickers, nor are you listed on the United States Department of Commerce Table of Denial Orders.
You will not download or otherwise export or re-export the Programs, directly or indirectly, to persons on the above mentioned lists.
You will not use the Programs for, and will not allow the Programs to be used for, any purposes prohibited by United States law, including, without limitation, for the development, design, manufacture or production of nuclear, chemical or biological weapons of mass destruction.
EXPORT RESTRICTIONS
You agree that U.S. export control laws and other applicable export and import laws govern your use of the programs, including technical data; additional information can be found on DB2®'s Global Trade Compliance web site (http://www.db2.com/products/export).
You agree that neither the programs nor any direct product thereof will be exported, directly, or indirectly, in violation of these laws, or will be used for any purpose prohibited by these laws including, without limitation, nuclear, chemical, or biological weapons proliferation.
DB2 Employees: Under no circumstances are DB2 Employees authorized to download software for the purpose of distributing it to customers. DB2 products are available to employees for internal use or demonstration purposes only. In keeping with DB2's trade compliance obligations under U.S. and applicable multilateral law, failure to comply with this policy could result in disciplinary action up to and including termination.
Note: You are bound by the DB2 Technology Network ("OTN") License Agreement terms. The OTN License Agreement terms also apply to all updates you receive under your Technology Track subscription.
The OTN License Agreement terms below supercede any shrinkwrap license on the OTN Technology Track software CDs and previous OTN License terms (including the DB2 Program License as modified by the OTN Program Use Certificate).
DB2 Technology Network Development and Distribution License Agreement
"We," "us," and "our" refers to DB2 America, Inc., for and on behalf of itself and its subsidiaries and affiliates under common control. "You" and "your" refers to the individual or entity that wishes to use the programs from DB2. "Programs" refers to the software product you wish to download and use and program documentation. "License" refers to your right to use the programs under the terms of this agreement. This agreement is governed by the substantive and procedural laws of California. You and DB2 agree to submit to the exclusive jurisdiction of, and venue in, the courts of San Francisco, San Mateo, or Santa Clara counties in California in any dispute arising out of or relating to this agreement.
We are willing to license the programs to you only upon the condition that you accept all of the terms contained in this agreement. Read the terms carefully and select the "Accept" button at the bottom of the page to confirm your acceptance. If you are not willing to be bound by these terms, select the "Do Not Accept" button and the registration process will not continue.
License Rights
We grant you a nonexclusive, nontransferable limited license to use the programs: (a) for purposes of developing, testing, prototyping and running applications you have developed for your own internal data processing operations; (b) to distribute the programs with applications you have developed to your customers provided that each such licensee agrees to license terms consistent with the terms of this Agreement, you do not charge your end users any additional fees for the use of the programs, and your end users may only use the programs to run your applications for their own business operations; and (c) to use the programs to provide third party demonstrations and training. You are not permitted to use the programs for any purpose other than as permitted under this Agreement. If you want to use the programs for any purpose other than as expressly permitted under this agreement you must contact us, or an DB2 reseller, to obtain the appropriate license. We may audit your use and distribution of the programs. Program documentation is either shipped with the programs, or documentation may accessed online at http://www.db2.com/technetwork/indexes/documentation/index.html.
Ownership and Restrictions
We retain all ownership and intellectual property rights in the programs. You may make a sufficient number of copies of the programs for the licensed use and one copy of the programs for backup purposes.
You may not:
- use the programs for any purpose other than as provided above;
- distribute the programs unless accompanied with your applications;
- charge your end users for use of the programs;
- remove or modify any program markings or any notice of our proprietary rights;
- use the programs to provide third party training on the content and/or functionality of the programs, except for training your licensed users;
- assign this agreement or give the programs, program access or an interest in the programs to any individual or entity except as provided under this agreement;
- cause or permit reverse engineering (unless required by law for interoperability), disassembly or decompilation of the programs;
- disclose results of any program benchmark tests without our prior consent.
Program Distribution
We grant you a nonexclusive, nontransferable right to copy and distribute the programs to your end users provided that you do not charge your end users for use of the programs and provided your end users may only use the programs to run your applications for their business operations. Prior to distributing the programs you shall require your end users to execute an agreement binding them to terms consistent with those contained in this section and the sections of this agreement entitled "License Rights," "Ownership and Restrictions," "Export," "Disclaimer of Warranties and Exclusive Remedies," "No Technical Support," "End of Agreement," "Relationship Between the Parties," and "Open Source." You must also include a provision stating that your end users shall have no right to distribute the programs, and a provision specifying us as a third party beneficiary of the agreement. You are responsible for obtaining these agreements with your end users.
You agree to: (a) defend and indemnify us against all claims and damages caused by your distribution of the programs in breach of this agreements and/or failure to include the required contractual provisions in your end user agreement as stated above; (b) keep executed end user agreements and records of end user information including name, address, date of distribution and identity of programs distributed; (c) allow us to inspect your end user agreements and records upon request; and, (d) enforce the terms of your end user agreements so as to effect a timely cure of any end user breach, and to notify us of any breach of the terms.
Export
You agree that U.S. export control laws and other applicable export and import laws govern your use of the programs, including technical data; additional information can be found on DB2's Global Trade Compliance web site located at http://www.db2.com/products/export/index.html?content.html. You agree that neither the programs nor any direct product thereof will be exported, directly, or indirectly, in violation of these laws, or will be used for any purpose prohibited by these laws including, without limitation, nuclear, chemical, or biological weapons proliferation.
Disclaimer of Warranty and Exclusive Remedies
THE PROGRAMS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. WE FURTHER DISCLAIM ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
IN NO EVENT SHALL WE BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR DAMAGES FOR LOSS OF PROFITS, REVENUE, DATA OR DATA USE, INCURRED BY YOU OR ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT, EVEN IF WE HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. OUR ENTIRE LIABILITY FOR DAMAGES HEREUNDER SHALL IN NO EVENT EXCEED ONE THOUSAND DOLLARS (U.S. $1,000).
No Technical Support
Our technical support organization will not provide technical support, phone support, or updates to you for the programs licensed under this agreement.
Restricted Rights
If you distribute a license to the United States government, the programs, including documentation, shall be considered commercial computer software and you will place a legend, in addition to applicable copyright notices, on the documentation, and on the media label, substantially similar to the following:
NOTICE OF RESTRICTED RIGHTS
"Programs delivered subject to the DOD FAR Supplement are 'commercial computer software' and use, duplication, and disclosure of the programs, including documentation, shall be subject to the licensing restrictions set forth in the applicable DB2 license agreement. Otherwise, programs delivered subject to the Federal Acquisition Regulations are 'restricted computer software' and use, duplication, and disclosure of the programs, including documentation, shall be subject to the restrictions in FAR 52.227-19, Commercial Computer Software-Restricted Rights (June 1987). DB2 America, Inc., 500 DB2 Parkway, Redwood City, CA 94065."
End of Agreement
You may terminate this agreement by destroying all copies of the programs. We have the right to terminate your right to use the programs if you fail to comply with any of the terms of this agreement, in which case you shall destroy all copies of the programs.
Relationship Between the Parties
The relationship between you and us is that of licensee/licensor. Neither party will represent that it has any authority to assume or create any obligation, express or implied, on behalf of the other party, nor to represent the other party as agent, employee, franchisee, or in any other capacity. Nothing in this agreement shall be construed to limit either party's right to independently develop or distribute software that is functionally similar to the other party's products, so long as proprietary information of the other party is not included in such software.
Open Source
"Open Source" software - software available without charge for use, modification and distribution - is often licensed under terms that require the user to make the user's modifications to the Open Source software or any software that the user 'combines' with the Open Source software freely available in source code form. If you use Open Source software in conjunction with the programs, you must ensure that your use does not: (i) create, or purport to create, obligations of us with respect to the DB2 programs; or (ii) grant, or purport to grant, to any third party any rights to or immunities under our intellectual property or proprietary rights in the DB2 programs. For example, you may not develop a software program using an DB2 program and an Open Source program where such use results in a program file(s) that contains code from both the DB2 program and the Open Source program (including without limitation libraries) if the Open Source program is licensed under a license that requires any "modifications" be made freely available. You also may not combine the DB2 program with programs licensed under the GNU General Public License ("GPL") in any manner that could cause, or could be interpreted or asserted to cause, the DB2 program or any modifications thereto to become subject to the terms of the GPL.
Entire Agreement
You agree that this agreement is the complete agreement for the programs and licenses, and this agreement supersedes all prior or contemporaneous agreements or representations. If any term of this agreement is found to be invalid or unenforceable, the remaining provisions will remain effective.
Last updated: 01/24/09
Should you have any questions concerning this License Agreement, or if you desire to contact DB2 for any reason, please write:
DB2 America, Inc.
500 DB2 Parkway,
Redwood City, CA 94065
DB2 may contact you to ask if you had a satisfactory experience installing and using this OTN software download.
\ No newline at end of file
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: DB2 Plug-in
Bundle-SymbolicName: org.jkiss.dbeaver.ext.db2;singleton:=true
Bundle-Version: 1.0.15
Bundle-Activator: org.jkiss.dbeaver.ext.db2.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.ui.views,
org.eclipse.jface,
org.eclipse.jface.text,
org.jkiss.dbeaver.core,
org.eclipse.ui.workbench.texteditor,
org.jkiss.dbeaver.resources.db2
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: Serge Rieder
Bundle-ClassPath: .
Bundle-Localization: plugin
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/,\
plugin.properties,\
plugin_ru.properties,\
plugin_zh.properties,\
plugin_it.properties,\
templates/
TODO:
Go through all "TODO" markers and flush remaining unused classes
Problems:
- sql editor is erratic
- investigate while DDL generation does not work for some tables
Missing Functions:
- a nice connection view setup customized for DB2
- Explain -> DB2 Explain structure done, all the rest is to be done (execute explain, display the result)...
- Editors / Object creators
- SQL Content assist
- Manage explain/ddl generation table creation correctly
Display:
- display timestamps with 6 microseconds
- missing PK columns indicator (Unique, foreign)
- set correct labels for properties displayed
Missing objects
- Table check constraints
- Column check constraints
- Nicknames
- Synonyms
- Servers
- DB2User
- DB2Groups
- ..
Missing relationships:
- Tables -> Tablespaces (x3) links
- Tablespace->Bufferpool link on BPName
- Tables -> referenced by triggers
Missing Dependencies for
- DB2Views
- DB2Package
- Procedure/Functions
Missing Actions
db2 reorg
db2 runstats
db2 backup
drop
rename
set integrity
call sysproc.admin_drop_schema
call sysproc.admin_copy_schema
...
Improvements:
- Transform Trigger dependencies into "real objects"
- Propgate and use monitors everywhere
- Lazy loading
- Split DB2Tables into distinct sub types:
- Regular
- MQT
- Temporary Tables
- Alias
- Hierachies..
Data available at the database level
- Applications/Sessions
- DB parameters
- DBM parameters
ALL_PROCEDURES - procedures inside of packages
ALL_OBJECTS TYPE IN (PROCEDURE,FUNCTION) - standalone procedures
ALL_ARGUMENTS - for all
ALL_SOURCES - sources
\ No newline at end of file
# Copyright (C) 2010-2013 Serge Rieder (serge@jkiss.org)
# Copyright (C) 2012 Eugene Fradkin (eugene.fradkin@gmail.com)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
tree.appobjects.node.name=Application Objects
tree.containers.node.name=Containers
tree.container.node.name=Container
tree.bufferpools.node.name=Bufferpools
tree.bufferpool.node.name=Bufferpool
tree.roleauths.node.name=Autorisations
tree.roleauth.node.name=Autorisation
tree.nicknames.node.name=Nicknames
tree.nickname.node.name=Nickname
tree.constraints.node.name=Unique Keys
tree.constraint.node.name=Unique Key
tree.indexes.node.name=Indexes
tree.index.node.name=Index
tree.functions.node.name=Functions
tree.function.node.name=Function
tree.triggerdeps.node.name=Dependencies
tree.triggerdep.node.name=Dependency
meta.org.jkiss.dbeaver.ext.db2.model.DB2Schema.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2Schema.owner.name=Owner
meta.org.jkiss.dbeaver.ext.db2.model.DB2Schema.ownerTypeDescription.name=Owner Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2Schema.createTime.name=Creation Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Schema.auditPolicyID.name=Audit Policy Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2Schema.auditPolicyName.name=Audit Policy
meta.org.jkiss.dbeaver.ext.db2.model.DB2Schema.dataCapture.name=Data Capture
meta.org.jkiss.dbeaver.ext.db2.model.DB2Schema.description.name=Description
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableBase.description.name=Description
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.tablespace.name=Tablespace
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.nPages.name=NPages (Runstats)
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.alterTime.name=Alter Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.createTime.name=Creation Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.typeDescription.name=Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.indexTablespace.name=Index Tablespace
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.longTablespace.name=Long Data Tablespace
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.invalidateTime.name=Invalidate Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.statsTime.name=Last Statistics Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.card.name=Nb Rows (Runstats)
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.fPages.name=FPages (Runstats)
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.overFLow.name=Nb Overflow Records (Runstats)
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.status.name=Status
meta.org.jkiss.dbeaver.ext.db2.model.DB2Table.schema.name=Schema
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableBase.ownerTypeDescription.name=Owner Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableBase.owner.name=Owner
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableColumn.comment.name=Comment
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableColumn.type.name=Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableColumn.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2View.status.name=Status
meta.org.jkiss.dbeaver.ext.db2.model.DB2View.description.name=Description
meta.org.jkiss.dbeaver.ext.db2.model.DB2Index.uniqueRuleDescription.name=Unique Rule
meta.org.jkiss.dbeaver.ext.db2.model.DB2Index.madeUnique.name=Made Unique?
meta.org.jkiss.dbeaver.ext.db2.model.DB2Index.uniqueColCount.name=Nb Unique Cols
meta.org.jkiss.dbeaver.ext.db2.model.DB2Index.indSchema.name=Schema
meta.org.jkiss.dbeaver.ext.db2.model.DB2Index.colCount.name=Nb Cols
meta.org.jkiss.dbeaver.ext.db2.model.DB2IndexColumn.colOrderDescription.name=Order
meta.org.jkiss.dbeaver.ext.db2.model.DB2IndexColumn.colSeq.name=Sequence
meta.org.jkiss.dbeaver.ext.db2.model.DB2IndexColumn.collationSchema.name=Collation Schema
meta.org.jkiss.dbeaver.ext.db2.model.DB2IndexColumn.collationNane.name=Collation Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2IndexColumn.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2IndexColumn.tableColumn.name=Column
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.createTime.name=Creation Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.increment.name=Increment
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.alterTime.name=Alter Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.ownerTypeDescription.name=Owner TYpe
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.nextCacheFirstValue.name=Next Cached First Value
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.precisionDescription.name=Precision
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.seqTypeDescription.name=Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.start.name=
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.seqId.name=
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.baseSchema.name=
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.baseSequence.name=
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.dataTypeId.name=
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.sourceTypeId.name=
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.originDescription.name=
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.owner.name=
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.description.name=
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.schema.name=
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.cache.name=
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.cache.name=Cache
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.schema.name=Schema
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.description.name=Description
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.minValue.name=Min
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.maxValue.name=Max
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.owner.name=Owner
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.seqId.name=Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.cycle.name=Cycle?
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.start.name=Start
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.originDescription.name=Origin
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.sourceTypeId.name=Source Type Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.dataTypeId.name=Data Type Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.baseSequence.name=Base Sequence Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.baseSchema.name=Base Sequence Schema
meta.org.jkiss.dbeaver.ext.db2.model.DB2Sequence.order.name=Order?
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.qualifier.name=Qualifier
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.createTime.name=Creation Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.ownerType.name=Owner Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.alterTime.name=Alter Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.lastRegenTime.name=Last Regeneration Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.eventDescription.name=Event
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.timeDescription.name=Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.eventUpdate.name=On Update?
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.eventDelete.name=On Delete?
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.eventInsert.name=On Insert?
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.collationSchema.nameCollation Schema
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.collationName.name=Collation Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.precompileOptions.name-Precompile Options
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.compileOptions.name=Compile Options
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.collationNameOrderBy.name=Collation Name Order By
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.collationSchemaOrderBy.name=Collation Schwma Order By
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.granularityDescription.name=Granularity
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.valid.name=Valid
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.funcPath.name=Func Path
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.secure.nameSecure
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.libId.name=LibId
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.owner.name=Owner
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.schema.name=Schema
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.description.name=Description
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.table.name=Table
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.secure.name=Secure?
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.precompileOptions.name=Precompile Options
meta.org.jkiss.dbeaver.ext.db2.model.DB2Trigger.collationSchema.name=Collation Schema
meta.org.jkiss.dbeaver.ext.db2.model.DB2TriggerDep.triggerDepTypeDescription.name=Type Dependency
meta.org.jkiss.dbeaver.ext.db2.model.DB2TriggerDep.depSchema.name=Dependent Schema
meta.org.jkiss.dbeaver.ext.db2.model.DB2TriggerDep.tabAuth.name=Authorisations Required
meta.org.jkiss.dbeaver.ext.db2.model.DB2TriggerDep.depModuleId.name=Dependent Module Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2TriggerDep.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2Bufferpool.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2Bufferpool.id.name=Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2Bufferpool.estore.name=Estore
meta.org.jkiss.dbeaver.ext.db2.model.DB2Bufferpool.blockSize.name=Block Size
meta.org.jkiss.dbeaver.ext.db2.model.DB2Bufferpool.pageSize.name=Page Size
meta.org.jkiss.dbeaver.ext.db2.model.DB2Bufferpool.dbpgName.name=Partition Group
meta.org.jkiss.dbeaver.ext.db2.model.DB2Bufferpool.nPages.name=Nb Pages
meta.org.jkiss.dbeaver.ext.db2.model.DB2Bufferpool.numBlockPages.name=Nb Block Pages
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.tbspaceId.name=Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.pageSize.name=Page Size
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.overHead.name=Overhead
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.dbpgName.name=Partiton Group
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.dataTag.name=Data Tag
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.sgName.name=Storage Group
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.sgId.name=Storage Group Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.bufferPoolId.name=Bufferpool Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.createTime.name=Creation Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.prefetchSize.name=Prefetch Size
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.transferRate.name=Transfer Rate
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.writeOverHead.name=Write Overhead
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.writeTransferRate.name=Write Transfer Rate
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.dropRecovery.name=Drop Recovery?
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.tbspaceTypeDescription.name=Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.dataTypeDescription.name=Data Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.ownerTypeDescription.name=Owner
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.effectivePrefetchSize.name=Effective Prefetch Size
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.owner.name=Owner
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.description.name=Description
meta.org.jkiss.dbeaver.ext.db2.model.DB2Tablespace.extentSize.name=Extent Size
meta.org.jkiss.dbeaver.ext.db2.model.DB2TablespaceContainer.containerId.name=Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2TablespaceContainer.containerType.name=Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2TablespaceContainer.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2Role.createTime.name=Creation Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2Role.auditPolicyName.name=Audit Policy Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2Role.auditPolicyId.name=Audit Policy Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2Role.id.name=Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2Role.description.name=Description
meta.org.jkiss.dbeaver.ext.db2.model.DB2Role.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2RoleAuth.admin.name=Admin?
meta.org.jkiss.dbeaver.ext.db2.model.DB2RoleAuth.grantor.name=Grantor
meta.org.jkiss.dbeaver.ext.db2.model.DB2RoleAuth.granteeTypeDescription.name=Grantee Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2RoleAuth.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2RoleAuth.grantorTypeDescription.name=Grantro Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.dataKind.name=Data Kind
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.scale.name=Scale
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.maxLength.name=Max Length
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.metaType.name=Meta Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.alterTime.name=Alter Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.db2TypeId.name=DB2 Type Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.owner.name=Owner
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.description.name=Description
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.schema.name=Schema
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.ownerType.name=Owner TYpe
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.createTime.name=Creation Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.typeID.name=Id
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.moduleName.name=Module Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.sourceSchema.name=Source Schema
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.sourceModuleName.name=Source Module Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.sourceName.name=Source Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.lastRegenTime.name=Last Regeneration Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.constraintText.name=Constraint Text
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.ownerType.name=Owner TYpe
meta.org.jkiss.dbeaver.ext.db2.model.DB2DataType.createTime.name=Creattion Time
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableKeyColumn.ordinalPosition.name=Position
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableKeyColumn.description.name=Description
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableKeyColumn.name.name=Name
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableKeyColumn.attribute.name=Attribute
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableUniqueKey.ownerType.name=Owner Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableUniqueKey.owner.name=Owner
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableUniqueKey.enforced.name=Enforced?
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableUniqueKey.trusted.name=Trusted?
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableUniqueKey.checkExistingData.name=Check Existing Data
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableUniqueKey.enableQueryOpt.name=Enable Query Optimisation
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableUniqueKey.constraintType.name=Type
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableUniqueKey.description.name=Description
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableForeignKey.referencedConstraint.name=Referenced Constraint
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableForeignKey.referencedTable.name=Referenced Table
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableForeignKey.updateRule.name=Update Ruke
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableForeignKey.deleteRule.name=Delete Rule
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableReference.referencedConstraint.name=Referenced Constraint
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableReference.referencedTable.name=Referenced Table
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableReference.updateRule.name=Update Rule
meta.org.jkiss.dbeaver.ext.db2.model.DB2TableReference.deleteRule.name=Delete Rule
# -----------------------
editor.package.declaration.name=Declaration
editor.package.declaration.description=Declaration source
editor.package.body.name=Body
editor.package.body.description=Body source
tree.schemas.node.name=Schemas
tree.schema.node.name=Schema
tree.tables.node.name=Tables
tree.table.node.name=Table
tree.columns.node.name=Columns
tree.column.node.name=Column
tree.constraint_columns.node.name=Constraint columns
tree.foreign_keys.node.name=Foreign Keys
tree.foreign_key.node.name=Foreign Key
tree.foreign_key_columns.node.name=Foreign key columns
tree.references.node.name=References
tree.reference_key.node.name=Reference Key
tree.reference_key_columns.node.name=Reference key columns
tree.triggers.node.name=Triggers
tree.trigger.node.name=Trigger
tree.index_columns.node.name=Index columns
tree.views.node.name=Views
tree.view.node.name=View
tree.sequences.node.name=Sequences
tree.sequence.node.name=Sequence
tree.types.node.name=Types
tree.type.node.name=Type
tree.attributes.node.name=Attributes
tree.attribute.node.name=Attribute
tree.arguments.node.name=Arguments
tree.argument.node.name=Argument
tree.packages.node.name=Packages
tree.package.node.name=Package
tree.procedures.node.name=Procedures
tree.procedure.node.name=Procedure
tree.synonyms.node.name=Synonyms
tree.synonym.node.name=Synonym
tree.global_metadata.node.name=Global metadata
tree.data_type.node.name=Data Type
tree.storage.node.name=Storage
tree.tablespaces.node.name=Tablespaces
tree.tablespace.node.name=Tablespace
tree.security.node.name=Security
tree.users.node.name=Users
tree.user.node.name=User
tree.roles.node.name=Roles
tree.role.node.name=Role
tree.profiles.node.name=Profiles
tree.profile.node.name=Profile
tree.resource.node.name=Resource
tree.administer.node.name=Administer
tree.sessions.node.name=Sessions
dialog.connection.header=DB2 Connection Settings
此差异已折叠。
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.jkiss.dbeaver.ext.db2";
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
/**
* Returns an image descriptor for the image file at the given plug-in relative path
*
* @param path
* the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2;
import org.jkiss.dbeaver.model.DBConstants;
/**
* DB2 constants
*/
public class DB2Constants {
// Display Categories
public static final String CAT_DATETIME = "Date & Time";
public static final String CAT_OWNER = "Owner";
public static final String CAT_STATS = "Statistiques";
public static final String CAT_TABLESPACE = "Tablespace";
public static final String CAT_AUDIT = "Audit";
public static final String CAT_METRICS = "Performance";
public static final String CAT_COLLATION = "Collation";
public static final String CAT_BASEBJECT = "Base Object";
public static final String CAT_COMPILER = "Compiler";
// ------------------
// TODO DF Sortout those remaining consts..
// --------------------------
public static final String CMD_COMPILE = "org.jkiss.dbeaver.ext.db2.code.compile"; //$NON-NLS-1$
public static final String PROP_CONNECTION_TYPE = DBConstants.INTERNAL_PROP_PREFIX + "connection-type@";
public static final String TYPE_NAME_XML = "XMLTYPE";
public static final String TYPE_FQ_XML = "SYS.XMLTYPE";
public static final String PROP_SOURCE_DEFINITION = "sourceDefinition";
public static final String PROP_SOURCE_DECLARATION = "sourceDeclaration";
public static final String COL_OWNER = "OWNER";
public static final String COL_TABLE_NAME = "TABLE_NAME";
public static final String COL_CONSTRAINT_NAME = "CONSTRAINT_NAME";
public static final String COL_CONSTRAINT_TYPE = "CONSTRAINT_TYPE";
public static final String[] ADVANCED_KEYWORDS = { "PACKAGE", "FUNCTION", "TYPE", "TRIGGER", "MATERIALIZED", "IF", "EACH",
"RETURN", "WRAPPED" };
public static final String PREF_KEY_DDL_FORMAT = "db2.ddl.format";
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2;
import java.util.Map;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.db2.model.DB2DataSource;
import org.jkiss.dbeaver.model.DBPConnectionInfo;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDriver;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSourceProvider;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSDataSourceContainer;
import org.jkiss.dbeaver.registry.DriverDescriptor;
import org.jkiss.utils.CommonUtils;
/**
* DB2 DataSource provider
*
* @author Denis Forveille
*
*/
public class DB2DataSourceProvider extends JDBCDataSourceProvider {
private static Map<String, String> connectionsProps;
public static Map<String, String> getConnectionsProps() {
return connectionsProps;
}
public DB2DataSourceProvider() {
}
@Override
protected String getConnectionPropertyDefaultValue(String name, String value) {
String ovrValue = connectionsProps.get(name);
return ovrValue != null ? ovrValue : super.getConnectionPropertyDefaultValue(name, value);
}
@Override
public long getFeatures() {
return FEATURE_SCHEMAS;
}
@Override
public String getConnectionURL(DBPDriver driver, DBPConnectionInfo connectionInfo) {
try {
DriverDescriptor.MetaURL metaURL = DriverDescriptor.parseSampleURL(driver.getSampleURL());
StringBuilder url = new StringBuilder();
for (String component : metaURL.getUrlComponents()) {
String newComponent = component;
if (!CommonUtils.isEmpty(connectionInfo.getHostName())) {
newComponent = newComponent.replace(makePropPattern(DriverDescriptor.PROP_HOST), connectionInfo.getHostName());
}
if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
newComponent = newComponent.replace(makePropPattern(DriverDescriptor.PROP_PORT), connectionInfo.getHostPort());
}
if (!CommonUtils.isEmpty(connectionInfo.getServerName())) {
newComponent = newComponent.replace(makePropPattern(DriverDescriptor.PROP_SERVER), connectionInfo.getServerName());
}
if (!CommonUtils.isEmpty(connectionInfo.getDatabaseName())) {
newComponent = newComponent.replace(makePropPattern(DriverDescriptor.PROP_DATABASE),
connectionInfo.getDatabaseName());
newComponent = newComponent.replace(makePropPattern(DriverDescriptor.PROP_FOLDER), connectionInfo.getDatabaseName());
newComponent = newComponent.replace(makePropPattern(DriverDescriptor.PROP_FILE), connectionInfo.getDatabaseName());
}
if (newComponent.startsWith("[")) { //$NON-NLS-1$
if (!newComponent.equals(component)) {
url.append(newComponent.substring(1, newComponent.length() - 1));
}
} else {
url.append(newComponent);
}
}
return url.toString();
} catch (DBException e) {
log.error(e);
return null;
}
}
@Override
public DBPDataSource openDataSource(DBRProgressMonitor monitor, DBSDataSourceContainer container) throws DBException {
return new DB2DataSource(monitor, container);
}
private static String makePropPattern(String prop) {
return "{" + prop + "}"; //$NON-NLS-1$ //$NON-NLS-2$
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2;
import org.eclipse.osgi.util.NLS;
public class DB2Messages extends NLS {
static final String BUNDLE_NAME = "org.jkiss.dbeaver.ext.db2.DB2Resources"; //$NON-NLS-1$
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, DB2Messages.class);
}
private DB2Messages() {
}
public static String dialog_connection_browse_button;
public static String dialog_connection_database_schema_label;
public static String dialog_connection_db_file_chooser_text;
public static String dialog_connection_db_folder_chooser_message;
public static String dialog_connection_db_folder_chooser_text;
public static String dialog_connection_edit_driver_button;
public static String dialog_connection_host_label;
public static String dialog_connection_jdbc_url_;
public static String dialog_connection_password_label;
public static String dialog_connection_path_label;
public static String dialog_connection_port_label;
public static String dialog_connection_server_label;
public static String dialog_connection_test_connection_button;
public static String dialog_connection_user_name_label;
public static String dialog_connection_advanced_tab;
public static String dialog_connection_advanced_tab_tooltip;
public static String dialog_connection_basic_tab;
public static String dialog_connection_connection_type_group;
public static String dialog_connection_custom_tab;
public static String dialog_connection_general_tab;
public static String dialog_connection_general_tab_tooltip;
public static String dialog_connection_host;
public static String dialog_connection_ora_home;
public static String dialog_connection_os_authentication;
public static String dialog_connection_password;
public static String dialog_connection_port;
public static String dialog_connection_role;
public static String dialog_connection_security_group;
public static String dialog_connection_select_ora_home_msg;
public static String dialog_connection_sid_service;
public static String dialog_connection_sid;
public static String dialog_connection_service;
public static String dialog_connection_database;
public static String dialog_connection_test_connection;
public static String dialog_connection_tns_tab;
public static String dialog_connection_user_name;
public static String dialog_connection_ver;
public static String edit_db2_constraint_manager_dialog_title;
public static String edit_db2_data_type_manager_dialog_title;
public static String edit_db2_foreign_key_manager_dialog_title;
public static String edit_db2_index_manager_dialog_title;
public static String edit_db2_package_manager_dialog_title;
public static String edit_db2_schema_manager_dialog_title;
public static String edit_db2_trigger_manager_dialog_title;
public static String editors_db2_session_editor_action__session;
public static String editors_db2_session_editor_action_disconnect;
public static String editors_db2_session_editor_action_kill;
public static String editors_db2_session_editor_confirm_action;
public static String editors_db2_session_editor_confirm_title;
public static String editors_db2_session_editor_title_disconnect_session;
public static String editors_db2_session_editor_title_kill_session;
public static String editors_db2_source_abstract_editor_action_name;
public static String editors_db2_source_abstract_editor_state;
public static String tools_script_execute_wizard_error_sqlplus_not_found;
public static String tools_script_execute_wizard_page_name;
public static String tools_script_execute_wizard_page_settings_button_browse;
public static String tools_script_execute_wizard_page_settings_group_input;
public static String tools_script_execute_wizard_page_settings_label_input_file;
public static String tools_script_execute_wizard_page_settings_page_description;
public static String tools_script_execute_wizard_page_settings_page_name;
public static String views_db2_compiler_dialog_button_compile;
public static String views_db2_compiler_dialog_button_compile_all;
public static String views_db2_compiler_dialog_column_name;
public static String views_db2_compiler_dialog_column_type;
public static String views_db2_compiler_dialog_message_compilation_error;
public static String views_db2_compiler_dialog_message_compilation_success;
public static String views_db2_compiler_dialog_message_compile_unit;
public static String views_db2_compiler_dialog_title;
public static String views_db2_compiler_log_viewer_action_clear_log;
public static String views_db2_compiler_log_viewer_action_copy;
public static String views_db2_compiler_log_viewer_action_select_all;
public static String views_db2_compiler_log_viewer_column_line;
public static String views_db2_compiler_log_viewer_column_message;
public static String views_db2_compiler_log_viewer_column_pos;
}
# Copyright (C) 2010-2013 Serge Rieder (serge@jkiss.org)
# Copyright (C) 2012 Eugene Fradkin (eugene.fradkin@gmail.com)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dialog_connection_browse_button=Browse ...
dialog_connection_database_schema_label=Database/Schema:
dialog_connection_db_file_chooser_text=Choose database file
dialog_connection_db_folder_chooser_message=Choose folder with database files
dialog_connection_db_folder_chooser_text=Choose database folder
dialog_connection_edit_driver_button=Edit Driver Settings
dialog_connection_general_tab=General
dialog_connection_general_tab_tooltip=General connection properties
dialog_connection_host_label=Host:
dialog_connection_jdbc_url_=JDBC URL:
dialog_connection_password_label=Password:
dialog_connection_path_label=Path:
dialog_connection_port_label=Port:
dialog_connection_server_label=Server:
dialog_connection_test_connection_button=Test Connection ...
dialog_connection_user_name_label=User name:
dialog_connection_advanced_tab=Advanced
dialog_connection_advanced_tab_tooltip=Advanced/custom driver properties
dialog_connection_basic_tab=Basic
dialog_connection_connection_type_group=Connection Type
dialog_connection_custom_tab=Custom
dialog_connection_general_tab=General
dialog_connection_general_tab_tooltip=General connection properties
dialog_connection_host=Host
dialog_connection_ora_home=Client
dialog_connection_os_authentication=OS Authentication
dialog_connection_password=Password
dialog_connection_port=Port
dialog_connection_role=Role
dialog_connection_security_group=Security
dialog_connection_select_ora_home_msg=Select DB2 home
dialog_connection_sid_service=SID/Service
dialog_connection_sid=SID
dialog_connection_service=Service Name
dialog_connection_database=Database
dialog_connection_test_connection=Test Connection ...
dialog_connection_tns_tab=TNS
dialog_connection_user_name=User name
dialog_connection_ver=v.
edit_db2_constraint_manager_dialog_title=Create constraint
edit_db2_data_type_manager_dialog_title=Package
edit_db2_foreign_key_manager_dialog_title=Create foreign key
edit_db2_index_manager_dialog_title=Create index
edit_db2_package_manager_dialog_title=Package
edit_db2_schema_manager_dialog_title=Schema name
edit_db2_trigger_manager_dialog_title=Trigger
editors_db2_session_editor_action__session=\ session
editors_db2_session_editor_action_disconnect=Disconnect
editors_db2_session_editor_action_kill=Kill
editors_db2_session_editor_confirm_action=Are you sure you want to {0} "{1}"?
editors_db2_session_editor_confirm_title=Immediate
editors_db2_session_editor_title_disconnect_session=Disconnect session
editors_db2_session_editor_title_kill_session=Kill Session
editors_db2_source_abstract_editor_action_name=View compile log
editors_db2_source_abstract_editor_state=State:
tools_script_execute_wizard_error_sqlplus_not_found=SQL*Plus binary not found in DB2 home "{0}"
tools_script_execute_wizard_page_name=Execute Script
tools_script_execute_wizard_page_settings_button_browse=Browse
tools_script_execute_wizard_page_settings_group_input=Input
tools_script_execute_wizard_page_settings_label_input_file=Input File
tools_script_execute_wizard_page_settings_page_description=Set script execution settings
tools_script_execute_wizard_page_settings_page_name=Script configuration
views_db2_compiler_dialog_button_compile=Compi&le
views_db2_compiler_dialog_button_compile_all=Compile &All
views_db2_compiler_dialog_column_name=Name
views_db2_compiler_dialog_column_type=Type
views_db2_compiler_dialog_message_compilation_error=Compilation errors occurred
views_db2_compiler_dialog_message_compilation_success=Successfully compiled
views_db2_compiler_dialog_message_compile_unit=Compile {0} "{1}" ...
views_db2_compiler_dialog_title=Compile object(s)
views_db2_compiler_log_viewer_action_clear_log=Clear Log
views_db2_compiler_log_viewer_action_copy=Copy
views_db2_compiler_log_viewer_action_select_all=Select All
views_db2_compiler_log_viewer_column_line=Line
views_db2_compiler_log_viewer_column_message=Message
views_db2_compiler_log_viewer_column_pos=Pos
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2;
import java.sql.Clob;
import java.sql.SQLException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.db2.model.DB2DataSource;
import org.jkiss.dbeaver.ext.db2.model.DB2Table;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCCallableStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCExecutionContext;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
/**
*
* DB2 Utils
*
* @author Denis Forveille
*
*/
public class DB2Utils {
private static final Log LOG = LogFactory.getLog(DB2Utils.class);
private static final String CALL_DB2LK_GEN = "CALL SYSPROC.DB2LK_GENERATE_DDL(?,?)";
private static final String CALL_DB2LK_CLEAN = "CALL SYSPROC.DB2LK_CLEAN_TABLE(?)";
private static final String SEL_DB2LK = "SELECT SQL_STMT FROM SYSTOOLS.DB2LOOK_INFO_V WHERE OP_TOKEN = ? ORDER BY OP_SEQUENCE";
private static final String CALL_INST_OBJ = "CALL SYSPROC.SYSINSTALLOBJECTS(?,?,?,?)";
private static final String LINE_SEP = "\n";
// Generate DDL
public static String generateDDLforTable(DBRProgressMonitor monitor,
String statementDelimiter,
DB2DataSource dataSource,
DB2Table db2Table) throws DBException {
LOG.debug("generate DDL for " + db2Table.getFullQualifiedName());
// TODO DF: Systools tables must exist first
monitor.beginTask("Generating DDL", 1);
// DF: Use "Undocumented SYSPROC.DB2LK_GENERATE_DDL stored proc
// Ref to db2look :
// http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.admin.cmd.doc/doc/r0002051.html
//
// Option that do not seem to work: -dp
StringBuilder sb = new StringBuilder(2048);
JDBCExecutionContext context = dataSource.openContext(monitor, DBCExecutionPurpose.META, "Generate DDL");
JDBCCallableStatement stmtSP = null;
JDBCCallableStatement stmtSPClean = null;
JDBCPreparedStatement stmtSel = null;
JDBCResultSet dbResult = null;
Integer token = 0;
String command = "-e -td " + statementDelimiter + " -t " + db2Table.getFullQualifiedName();
try {
LOG.debug("Calling Stored Proc with command : " + command);
stmtSP = context.prepareCall(CALL_DB2LK_GEN);
stmtSP.registerOutParameter(2, java.sql.Types.INTEGER);
stmtSP.setString(1, command);
stmtSP.executeUpdate();
token = stmtSP.getInt(2);
LOG.debug("Token = " + token);
// Read result
stmtSel = context.prepareStatement(SEL_DB2LK);
stmtSel.setInt(1, token);
dbResult = stmtSel.executeQuery();
Clob ddlStmt;
Long ddlLength;
Long ddlStart = 1L;
while (dbResult.next()) {
ddlStmt = dbResult.getClob(1);
ddlLength = ddlStmt.length() + 1L;
sb.append(ddlStmt.getSubString(ddlStart, ddlLength.intValue()));
sb.append(LINE_SEP);
ddlStmt.free();
}
// Clean
stmtSPClean = context.prepareCall(CALL_DB2LK_CLEAN);
stmtSPClean.setInt(1, token);
stmtSPClean.executeUpdate();
LOG.debug("Terminated OK");
return sb.toString();
} catch (SQLException e) {
LOG.error("SQLException occured during DDL generation", e);
throw new DBException(e);
} finally {
if (dbResult != null) {
dbResult.close();
}
if (stmtSP != null) {
stmtSP.close();
}
if (stmtSel != null) {
stmtSel.close();
}
if (stmtSPClean != null) {
stmtSPClean.close();
}
if (context != null) {
context.close();
}
monitor.done();
}
}
private static void createSystoolsTables(DBRProgressMonitor monitor, DB2DataSource dataSource) throws DBException {
LOG.debug("Create SYSTOOLS tables ");
// TODO DF: Systools tables can be created in different Tablespace/schema..
monitor.beginTask("Create SYSTOOLS Tables", 1);
JDBCExecutionContext context = dataSource.openContext(monitor, DBCExecutionPurpose.META, "Create SYSTOOLS Tables");
JDBCCallableStatement stmtSP = null;
try {
LOG.debug("Calling Stored Proc");
stmtSP = context.prepareCall(CALL_INST_OBJ);
stmtSP.setString(1, "EXPLAIN"); //
stmtSP.setString(2, "C"); // Create
stmtSP.setString(3, "SYSTOOLS"); // Tablespace
stmtSP.setString(4, "SYSTOOLS"); // Schema
stmtSP.executeUpdate();
LOG.debug("Terminated OK");
} catch (SQLException e) {
LOG.error("SQLException occured during SYSTOOLS Table Creation", e);
throw new DBException(e);
} finally {
if (stmtSP != null) {
stmtSP.close();
}
if (context != null) {
context.close();
}
monitor.done();
}
}
private DB2Utils() {
// Pure utility class, no instanciation allowed
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.actions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.menus.UIElement;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.ext.db2.model.DB2ObjectType;
import org.jkiss.dbeaver.ext.db2.model.source.DB2SourceObject;
import org.jkiss.dbeaver.ext.db2.views.DB2CompilerDialog;
import org.jkiss.dbeaver.model.DBPEvent;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.exec.DBCStatement;
import org.jkiss.dbeaver.model.exec.DBCStatementType;
import org.jkiss.dbeaver.model.exec.compile.DBCCompileError;
import org.jkiss.dbeaver.model.exec.compile.DBCCompileLog;
import org.jkiss.dbeaver.model.exec.compile.DBCCompileLogBase;
import org.jkiss.dbeaver.model.exec.compile.DBCSourceHost;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCExecutionContext;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.model.struct.DBSObjectState;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.ui.TextUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.utils.CommonUtils;
import java.lang.reflect.InvocationTargetException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class CompileHandler extends AbstractHandler implements IElementUpdater {
static final Log log = LogFactory.getLog(CompileHandler.class);
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final List<DB2SourceObject> objects = getSelectedObjects(event);
if (!objects.isEmpty()) {
final Shell activeShell = HandlerUtil.getActiveShell(event);
if (objects.size() == 1) {
final DB2SourceObject unit = objects.get(0);
final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
DBCSourceHost sourceHost = RuntimeUtils.getObjectAdapter(activePart, DBCSourceHost.class);
if (sourceHost == null) {
sourceHost = (DBCSourceHost) activePart.getAdapter(DBCSourceHost.class);
}
if (sourceHost != null && sourceHost.getSourceObject() != unit) {
sourceHost = null;
}
final DBCCompileLog compileLog = sourceHost == null ? new DBCCompileLogBase() : sourceHost.getCompileLog();
compileLog.clearLog();
Throwable error = null;
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
compileUnit(monitor, compileLog, unit);
} catch (DBCException e) {
throw new InvocationTargetException(e);
}
}
});
if (compileLog.getError() != null) {
error = compileLog.getError();
}
} catch (InvocationTargetException e) {
error = e.getTargetException();
} catch (InterruptedException e) {
return null;
}
if (error != null) {
UIUtils.showErrorDialog(activeShell, "Unexpected compilation error", null, error);
} else if (!CommonUtils.isEmpty(compileLog.getErrorStack())) {
// Show compile errors
int line = -1, position = -1;
StringBuilder fullMessage = new StringBuilder();
for (DBCCompileError oce : compileLog.getErrorStack()) {
fullMessage.append(oce.toString()).append(ContentUtils.getDefaultLineSeparator());
if (line < 0) {
line = oce.getLine();
position = oce.getPosition();
}
}
// If compiled object is currently open in editor - try to position on error line
if (sourceHost != null && sourceHost.getSourceObject() == unit && line > 0 && position > 0) {
sourceHost.positionSource(line, position);
activePart.getSite().getPage().activate(activePart);
}
String errorTitle = unit.getName() + " compilation failed";
if (sourceHost != null) {
sourceHost.setCompileInfo(errorTitle, true);
sourceHost.showCompileLog();
}
UIUtils.showErrorDialog(activeShell, errorTitle, fullMessage.toString());
} else {
String message = unit.getName() + " compiled successfully";
if (sourceHost != null) {
sourceHost.setCompileInfo(message, true);
}
UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
}
} else {
DB2CompilerDialog dialog = new DB2CompilerDialog(activeShell, objects);
dialog.open();
}
}
return null;
}
private List<DB2SourceObject> getSelectedObjects(ExecutionEvent event) {
List<DB2SourceObject> objects = new ArrayList<DB2SourceObject>();
final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof IStructuredSelection && !currentSelection.isEmpty()) {
for (Iterator<?> iter = ((IStructuredSelection) currentSelection).iterator(); iter.hasNext();) {
final Object element = iter.next();
final DB2SourceObject sourceObject = RuntimeUtils.getObjectAdapter(element, DB2SourceObject.class);
if (sourceObject != null) {
objects.add(sourceObject);
}
}
}
if (objects.isEmpty()) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final DB2SourceObject sourceObject = RuntimeUtils.getObjectAdapter(activePart, DB2SourceObject.class);
if (sourceObject != null) {
objects.add(sourceObject);
}
}
return objects;
}
@Override
public void updateElement(UIElement element, Map parameters) {
List<DB2SourceObject> objects = new ArrayList<DB2SourceObject>();
IWorkbenchPartSite partSite = UIUtils.getWorkbenchPartSite(element.getServiceLocator());
if (partSite != null) {
final ISelectionProvider selectionProvider = partSite.getSelectionProvider();
if (selectionProvider != null) {
ISelection selection = selectionProvider.getSelection();
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext();) {
final Object item = iter.next();
final DB2SourceObject sourceObject = RuntimeUtils.getObjectAdapter(item, DB2SourceObject.class);
if (sourceObject != null) {
objects.add(sourceObject);
}
}
}
}
if (objects.isEmpty()) {
final IWorkbenchPart activePart = partSite.getPart();
final DB2SourceObject sourceObject = RuntimeUtils.getObjectAdapter(activePart, DB2SourceObject.class);
if (sourceObject != null) {
objects.add(sourceObject);
}
}
}
if (!objects.isEmpty()) {
if (objects.size() > 1) {
element.setText("Compile " + objects.size() + " objects");
} else {
final DB2SourceObject sourceObject = objects.get(0);
String objectType = TextUtils.formatWord(sourceObject.getSourceType().name());
element.setText("Compile " + objectType/* + " '" + sourceObject.getName() + "'" */);
}
}
}
public static boolean compileUnit(DBRProgressMonitor monitor, Log compileLog, DB2SourceObject unit) throws DBCException {
final IDatabasePersistAction[] compileActions = unit.getCompileActions();
if (CommonUtils.isEmpty(compileActions)) {
return true;
}
final JDBCExecutionContext context = unit.getDataSource().openContext(monitor, DBCExecutionPurpose.UTIL,
"Compile '" + unit.getName() + "'");
try {
boolean success = true;
for (IDatabasePersistAction action : compileActions) {
final String script = action.getScript();
compileLog.trace(script);
if (monitor.isCanceled()) {
break;
}
try {
final DBCStatement dbStat = context.prepareStatement(DBCStatementType.QUERY, script, false, false, false);
try {
dbStat.executeStatement();
} finally {
dbStat.close();
}
action.handleExecute(null);
} catch (DBCException e) {
action.handleExecute(e);
throw e;
}
if (action instanceof DB2ObjectPersistAction) {
if (!logObjectErrors(context, compileLog, unit, ((DB2ObjectPersistAction) action).getObjectType())) {
success = false;
}
}
}
final DBSObjectState oldState = unit.getObjectState();
unit.refreshObjectState(monitor);
if (unit.getObjectState() != oldState) {
unit.getDataSource().getContainer().fireEvent(new DBPEvent(DBPEvent.Action.OBJECT_UPDATE, unit));
}
return success;
} finally {
context.close();
}
}
public static boolean logObjectErrors(JDBCExecutionContext context,
Log compileLog,
DB2SourceObject unit,
DB2ObjectType objectType) {
try {
final JDBCPreparedStatement dbStat = context
.prepareStatement("SELECT * FROM SYS.ALL_ERRORS WHERE OWNER=? AND NAME=? AND TYPE=? ORDER BY SEQUENCE");
try {
dbStat.setString(1, unit.getSchema().getName());
dbStat.setString(2, unit.getName());
dbStat.setString(3, objectType.getTypeName());
final ResultSet dbResult = dbStat.executeQuery();
try {
boolean hasErrors = false;
while (dbResult.next()) {
DBCCompileError error = new DBCCompileError("ERROR".equals(dbResult.getString("ATTRIBUTE")),
dbResult.getString("TEXT"),
dbResult.getInt("LINE"),
dbResult.getInt("POSITION"));
hasErrors = true;
if (error.isError()) {
compileLog.error(error);
} else {
compileLog.warn(error);
}
}
return !hasErrors;
} finally {
dbResult.close();
}
} finally {
dbStat.close();
}
} catch (Exception e) {
log.error("Can't read user errors", e);
return false;
}
}
}
\ No newline at end of file
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.actions;
import org.eclipse.core.runtime.IAdapterFactory;
import org.jkiss.dbeaver.ext.IDatabaseEditor;
import org.jkiss.dbeaver.ext.db2.model.source.DB2SourceObject;
import org.jkiss.dbeaver.ext.db2.model.source.DB2SourceObjectEx;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.editors.DatabaseEditorInput;
/**
* DB2 object adapter
*/
public class DB2ObjectAdapter implements IAdapterFactory {
public DB2ObjectAdapter() {
}
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (DB2SourceObject.class.isAssignableFrom(adapterType)) {
DBSObject dbObject = null;
if (adaptableObject instanceof DBNDatabaseNode) {
dbObject = ((DBNDatabaseNode) adaptableObject).getObject();
} else if (adaptableObject instanceof IDatabaseEditor) {
dbObject = ((IDatabaseEditor) adaptableObject).getEditorInput().getDatabaseObject();
} else if (adaptableObject instanceof DatabaseEditorInput) {
dbObject = ((DatabaseEditorInput) adaptableObject).getDatabaseObject();
}
if (dbObject != null && adapterType.isAssignableFrom(dbObject.getClass())) {
return dbObject;
}
}
return null;
}
@Override
public Class[] getAdapterList() {
return new Class[] { DB2SourceObject.class, DB2SourceObjectEx.class };
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.actions;
import org.jkiss.dbeaver.ext.db2.model.DB2ObjectType;
import org.jkiss.dbeaver.model.impl.edit.AbstractDatabasePersistAction;
/**
* DB2 persist action
*/
public class DB2ObjectPersistAction extends AbstractDatabasePersistAction {
private final DB2ObjectType objectType;
public DB2ObjectPersistAction(DB2ObjectType objectType, String title, String script) {
super(title, script);
this.objectType = objectType;
}
public DB2ObjectPersistAction(DB2ObjectType objectType, String script) {
super(script);
this.objectType = objectType;
}
public DB2ObjectType getObjectType() {
return objectType;
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.data;
import org.eclipse.swt.graphics.Image;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.DBDPreferences;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.data.DBDValueHandlerProvider;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
/**
* DB2 data types provider
*/
public class DB2ValueHandlerProvider implements DBDValueHandlerProvider {
@Override
public Image getTypeImage(DBSTypedObject type) {
return DBUtils.getDataIcon(type).getImage();
}
@Override
public DBDValueHandler getHandler(DBDPreferences preferences, String typeName, int valueType) {
// TODO DF: yet to be implemented
throw new UnsupportedOperationException("Not yet implemented");
}
}
\ No newline at end of file
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.edit;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.jkiss.dbeaver.ext.db2.DB2Messages;
import org.jkiss.dbeaver.ext.db2.model.DB2Table;
import org.jkiss.dbeaver.ext.db2.model.DB2TableUniqueKey;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.jdbc.edit.struct.JDBCConstraintManager;
import org.jkiss.dbeaver.model.struct.DBSEntityConstraintType;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.dialogs.struct.EditConstraintDialog;
/**
* DB2 constraint manager
*/
public class DB2ConstraintManager extends JDBCConstraintManager<DB2TableUniqueKey, DB2Table> {
@Override
public DBSObjectCache<? extends DBSObject, DB2TableUniqueKey> getObjectsCache(DB2TableUniqueKey object) {
return object.getParentObject().getSchema().getConstraintCache();
}
@Override
protected DB2TableUniqueKey createDatabaseObject(IWorkbenchWindow workbenchWindow,
DBECommandContext context,
DB2Table parent,
Object from) {
EditConstraintDialog editDialog = new EditConstraintDialog(workbenchWindow.getShell(),
DB2Messages.edit_db2_constraint_manager_dialog_title,
parent,
new DBSEntityConstraintType[] {
DBSEntityConstraintType.PRIMARY_KEY,
DBSEntityConstraintType.UNIQUE_KEY });
if (editDialog.open() != IDialogConstants.OK_ID) {
return null;
}
// final DB2TableConstraint constraint = new DB2TableConstraint(
// parent,
// null,
// editDialog.getConstraintType(),
// null,
// DB2ObjectStatus.ENABLED);
// constraint.setName(DBObjectNameCaseTransformer.transformName(constraint, CommonUtils.escapeIdentifier(parent.getName()) + "_PK")); //$NON-NLS-1$
// int colIndex = 1;
// for (DBSEntityAttribute tableColumn : editDialog.getSelectedColumns())
// {
// constraint.addColumn(
// new DB2TableConstraintColumn(
// constraint,
// (DB2TableColumn) tableColumn,
// colIndex++));
// }
// return constraint;
return null;
}
@Override
protected String getDropConstraintPattern(DB2TableUniqueKey constraint) {
String clause;
if (constraint.getConstraintType() == DBSEntityConstraintType.PRIMARY_KEY) {
clause = "PRIMARY KEY"; //$NON-NLS-1$
} else {
clause = "KEY"; //$NON-NLS-1$
}
return "ALTER TABLE " + PATTERN_ITEM_TABLE + " DROP " + clause + " " + PATTERN_ITEM_CONSTRAINT; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.edit;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.ext.db2.DB2Messages;
import org.jkiss.dbeaver.ext.db2.model.DB2DataType;
import org.jkiss.dbeaver.ext.db2.model.DB2Schema;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.AbstractDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.jdbc.edit.struct.JDBCObjectEditor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.dialogs.struct.CreateEntityDialog;
/**
* DB2DataTypeManager
*/
public class DB2DataTypeManager extends JDBCObjectEditor<DB2DataType, DB2Schema> {
@Override
public DBSObjectCache<? extends DBSObject, DB2DataType> getObjectsCache(DB2DataType object) {
// return object.getSchema().getDataTypeCache();
return null;
}
@Override
protected DB2DataType createDatabaseObject(IWorkbenchWindow workbenchWindow,
DBECommandContext context,
DB2Schema parent,
Object copyFrom) {
CreateEntityDialog dialog = new CreateEntityDialog(workbenchWindow.getShell(),
parent.getDataSource(),
DB2Messages.edit_db2_data_type_manager_dialog_title);
if (dialog.open() != IDialogConstants.OK_ID) {
return null;
}
// DB2DataType dataType = new DB2DataType(
// parent,
// dialog.getEntityName(),
// false);
// dataType.setSourceDeclaration("TYPE " + dataType.getName() + " AS OBJECT\n" + //$NON-NLS-1$ //$NON-NLS-2$
// "(\n" + //$NON-NLS-1$
// ")"); //$NON-NLS-1$
// return dataType;
return null;
}
@Override
protected IDatabasePersistAction[] makeObjectCreateActions(ObjectCreateCommand objectCreateCommand) {
return createOrReplaceProcedureQuery(objectCreateCommand.getObject());
}
@Override
protected IDatabasePersistAction[] makeObjectDeleteActions(ObjectDeleteCommand objectDeleteCommand) {
final DB2DataType object = objectDeleteCommand.getObject();
return new IDatabasePersistAction[] { new AbstractDatabasePersistAction("Drop type",
"DROP TYPE " + object.getFullQualifiedName()) //$NON-NLS-1$
};
}
@Override
protected IDatabasePersistAction[] makeObjectModifyActions(ObjectChangeCommand objectChangeCommand) {
return createOrReplaceProcedureQuery(objectChangeCommand.getObject());
}
@Override
public long getMakerOptions() {
return FEATURE_EDITOR_ON_CREATE;
}
private IDatabasePersistAction[] createOrReplaceProcedureQuery(DB2DataType dataType) {
// List<IDatabasePersistAction> actions = new
// ArrayList<IDatabasePersistAction>();
// String header = DB2Utils.normalizeSourceName(dataType, false);
// if (!CommonUtils.isEmpty(header)) {
// actions.add(
// new AbstractDatabasePersistAction(
// "Create type header",
// "CREATE OR REPLACE " + header)); //$NON-NLS-1$
// }
// String body = DB2Utils.normalizeSourceName(dataType, true);
// if (!CommonUtils.isEmpty(body)) {
// actions.add(
// new AbstractDatabasePersistAction(
// "Create type body",
// "CREATE OR REPLACE " + body)); //$NON-NLS-1$
// }
// // DB2Utils.addSchemaChangeActions(actions, dataType);
// return actions.toArray(new IDatabasePersistAction[actions.size()]);
return null;
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.edit;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.jkiss.dbeaver.ext.db2.DB2Messages;
import org.jkiss.dbeaver.ext.db2.model.DB2Table;
import org.jkiss.dbeaver.ext.db2.model.DB2TableForeignKey;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.jdbc.edit.struct.JDBCForeignKeyManager;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.rdb.DBSForeignKeyModifyRule;
import org.jkiss.dbeaver.ui.dialogs.struct.EditForeignKeyDialog;
/**
* DB2 foreign key manager
*/
public class DB2ForeignKeyManager extends JDBCForeignKeyManager<DB2TableForeignKey, DB2Table> {
@Override
public DBSObjectCache<? extends DBSObject, DB2TableForeignKey> getObjectsCache(DB2TableForeignKey object) {
// return object.getParentObject().getSchema().getTableFKCache();
return null;
}
@Override
protected DB2TableForeignKey createDatabaseObject(IWorkbenchWindow workbenchWindow,
DBECommandContext context,
DB2Table table,
Object from) {
EditForeignKeyDialog editDialog = new EditForeignKeyDialog(workbenchWindow.getShell(),
DB2Messages.edit_db2_foreign_key_manager_dialog_title,
table,
new DBSForeignKeyModifyRule[] { DBSForeignKeyModifyRule.NO_ACTION,
DBSForeignKeyModifyRule.CASCADE,
DBSForeignKeyModifyRule.RESTRICT,
DBSForeignKeyModifyRule.SET_NULL,
DBSForeignKeyModifyRule.SET_DEFAULT });
if (editDialog.open() != IDialogConstants.OK_ID) {
return null;
}
// final DB2TableFK foreignKey = new DB2TableFK(table, null, null,
// (DB2TableConstraint) editDialog.getUniqueConstraint(),
// editDialog.getOnDeleteRule());
// foreignKey.setName(DBObjectNameCaseTransformer.transformName(foreignKey, CommonUtils.escapeIdentifier(table.getName()) + "_" + //$NON-NLS-1$
// CommonUtils.escapeIdentifier(editDialog.getUniqueConstraint().getParentObject().getName()) + "_FK")); //$NON-NLS-1$
// int colIndex = 1;
// for (EditForeignKeyDialog.FKColumnInfo tableColumn :
// editDialog.getColumns()) {
// foreignKey.addColumn(new DB2TableFKColumn(foreignKey, (DB2TableColumn)
// tableColumn.getOwnColumn(), colIndex++));
// }
// return foreignKey;
return null;
}
@Override
protected String getDropForeignKeyPattern(DB2TableForeignKey foreignKey) {
return "ALTER TABLE " + PATTERN_ITEM_TABLE + " DROP FOREIGN KEY " + PATTERN_ITEM_CONSTRAINT; //$NON-NLS-1$ //$NON-NLS-2$
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.edit;
import java.util.Collections;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.jkiss.dbeaver.ext.db2.DB2Messages;
import org.jkiss.dbeaver.ext.db2.model.DB2Table;
import org.jkiss.dbeaver.ext.db2.model.DB2Index;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.jdbc.edit.struct.JDBCIndexManager;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.rdb.DBSIndexType;
import org.jkiss.dbeaver.ui.dialogs.struct.EditIndexDialog;
import org.jkiss.utils.CommonUtils;
/**
* DB2 index manager
*/
public class DB2IndexManager extends JDBCIndexManager<DB2Index, DB2Table> {
@Override
public DBSObjectCache<? extends DBSObject, DB2Index> getObjectsCache(DB2Index object) {
return object.getParentObject().getSchema().getIndexCache();
}
@Override
protected DB2Index createDatabaseObject(IWorkbenchWindow workbenchWindow, DBECommandContext context, DB2Table parent, Object from) {
EditIndexDialog editDialog = new EditIndexDialog(workbenchWindow.getShell(),
DB2Messages.edit_db2_index_manager_dialog_title,
parent,
Collections.singletonList(DBSIndexType.OTHER));
if (editDialog.open() != IDialogConstants.OK_ID) {
return null;
}
StringBuilder idxName = new StringBuilder(64);
idxName.append(CommonUtils.escapeIdentifier(parent.getName())).append("_") //$NON-NLS-1$
.append(CommonUtils.escapeIdentifier(editDialog.getSelectedColumns().iterator().next().getName())).append("_IDX"); //$NON-NLS-1$
// final DB2TableIndex index = new DB2TableIndex(parent.getSchema(),parent, DBObjectNameCaseTransformer.transformName(
// (DBPDataSource) parent.getDataSource(), idxName.toString()), false, editDialog.getIndexType());
// int colIndex = 1;
// for (DBSEntityAttribute tableColumn : editDialog.getSelectedColumns()) {
// index.addColumn(new DB2TableIndexColumn(index, (DB2TableColumn) tableColumn, colIndex++, true));
// }
// return index;
return null;
}
@Override
protected String getDropIndexPattern(DB2Index index) {
return "ALTER TABLE " + PATTERN_ITEM_TABLE + " DROP INDEX " + PATTERN_ITEM_INDEX_SHORT; //$NON-NLS-1$ //$NON-NLS-2$
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.edit;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.ext.db2.DB2Messages;
import org.jkiss.dbeaver.ext.db2.model.DB2Package;
import org.jkiss.dbeaver.ext.db2.model.DB2Schema;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.AbstractDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.jdbc.edit.struct.JDBCObjectEditor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.dialogs.struct.CreateEntityDialog;
/**
* DB2PackageManager
*/
public class DB2PackageManager extends JDBCObjectEditor<DB2Package, DB2Schema> {
@Override
public DBSObjectCache<? extends DBSObject, DB2Package> getObjectsCache(DB2Package object) {
return object.getSchema().getPackageCache();
}
@Override
protected DB2Package createDatabaseObject(IWorkbenchWindow workbenchWindow,
DBECommandContext context,
DB2Schema parent,
Object copyFrom) {
CreateEntityDialog dialog = new CreateEntityDialog(workbenchWindow.getShell(),
parent.getDataSource(),
DB2Messages.edit_db2_package_manager_dialog_title);
if (dialog.open() != IDialogConstants.OK_ID) {
return null;
}
// return new DB2Package(
// parent,
// dialog.getEntityName());
return null;
}
@Override
protected IDatabasePersistAction[] makeObjectCreateActions(ObjectCreateCommand objectCreateCommand) {
return createOrReplaceProcedureQuery(objectCreateCommand.getObject());
}
@Override
protected IDatabasePersistAction[] makeObjectDeleteActions(ObjectDeleteCommand objectDeleteCommand) {
final DB2Package object = objectDeleteCommand.getObject();
return new IDatabasePersistAction[] { new AbstractDatabasePersistAction("Drop package",
"DROP PACKAGE " + object.getFullQualifiedName()) //$NON-NLS-1$
};
}
@Override
protected IDatabasePersistAction[] makeObjectModifyActions(ObjectChangeCommand objectChangeCommand) {
return createOrReplaceProcedureQuery(objectChangeCommand.getObject());
}
@Override
public long getMakerOptions() {
return FEATURE_EDITOR_ON_CREATE;
}
private IDatabasePersistAction[] createOrReplaceProcedureQuery(DB2Package pack) {
List<IDatabasePersistAction> actions = new ArrayList<IDatabasePersistAction>();
// String header = DB2Utils.normalizeSourceName(pack, false);
// if (!CommonUtils.isEmpty(header)) {
// actions.add(
// new AbstractDatabasePersistAction(
// "Create package header",
// "CREATE OR REPLACE " + header)); //$NON-NLS-1$
// }
// String body = DB2Utils.normalizeSourceName(pack, true);
// if (!CommonUtils.isEmpty(body)) {
// actions.add(
// new AbstractDatabasePersistAction(
// "Create package body",
// "CREATE OR REPLACE " + body)); //$NON-NLS-1$
// } else {
// actions.add(
// new AbstractDatabasePersistAction(
// "Drop package header",
// "DROP PACKAGE BODY " + pack.getFullQualifiedName(), IDatabasePersistAction.ActionType.OPTIONAL) //$NON-NLS-1$
// );
// }
// DB2Utils.addSchemaChangeActions(actions, pack);
return actions.toArray(new IDatabasePersistAction[actions.size()]);
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.edit;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.ext.db2.model.DB2Routine;
import org.jkiss.dbeaver.ext.db2.model.DB2Schema;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.jdbc.edit.struct.JDBCObjectEditor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.dialogs.struct.CreateProcedureDialog;
/**
* DB2ProcedureManager
*/
public class DB2ProcedureManager extends JDBCObjectEditor<DB2Routine, DB2Schema> {
@Override
public DBSObjectCache<? extends DBSObject, DB2Routine> getObjectsCache(DB2Routine object) {
// return object.getSchema().getRoutineCache();
return null;
}
@Override
protected DB2Routine createDatabaseObject(IWorkbenchWindow workbenchWindow,
DBECommandContext context,
DB2Schema parent,
Object copyFrom) {
CreateProcedureDialog dialog = new CreateProcedureDialog(workbenchWindow.getShell(), parent.getDataSource());
if (dialog.open() != IDialogConstants.OK_ID) {
return null;
}
// return new DB2RoutineBase(parent, dialog.getProcedureName(),
// dialog.getProcedureType());
return null;
}
@Override
protected IDatabasePersistAction[] makeObjectCreateActions(ObjectCreateCommand objectCreateCommand) {
// return createOrReplaceProcedureQuery(objectCreateCommand.getObject());
return null;
}
@Override
protected IDatabasePersistAction[] makeObjectDeleteActions(ObjectDeleteCommand objectDeleteCommand) {
// final DB2RoutineBase object = objectDeleteCommand.getObject();
// return new IDatabasePersistAction[] { new
// AbstractDatabasePersistAction("Drop procedure",
// "DROP " + object.getProcedureType().name() + " " + object.getFullQualifiedName()) //$NON-NLS-1$ //$NON-NLS-2$
// };
return null;
}
@Override
protected IDatabasePersistAction[] makeObjectModifyActions(ObjectChangeCommand objectChangeCommand) {
// return createOrReplaceProcedureQuery(objectChangeCommand.getObject());
return null;
}
@Override
public long getMakerOptions() {
return FEATURE_EDITOR_ON_CREATE;
}
private IDatabasePersistAction[] createOrReplaceProcedureQuery(DB2Routine procedure) {
// String source = DB2Utils.normalizeSourceName(procedure, false);
// if (source == null) {
// return null;
// }
// List<IDatabasePersistAction> actions = new
// ArrayList<IDatabasePersistAction>();
// actions.add(new AbstractDatabasePersistAction("Create procedure", "CREATE OR REPLACE " + source)); //$NON-NLS-2$
// DB2Utils.addSchemaChangeActions(actions, procedure);
// return actions.toArray(new IDatabasePersistAction[actions.size()]);
return null;
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.edit;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchWindow;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.ext.db2.model.DB2DataSource;
import org.jkiss.dbeaver.ext.db2.model.DB2Schema;
import org.jkiss.dbeaver.ext.db2.model.DB2User;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEObjectRenamer;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.AbstractDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.jdbc.edit.struct.JDBCObjectEditor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.UIUtils;
/**
* DB2SchemaManager
*/
public class DB2SchemaManager extends JDBCObjectEditor<DB2Schema, DB2DataSource> implements DBEObjectRenamer<DB2Schema> {
@Override
public long getMakerOptions() {
return FEATURE_SAVE_IMMEDIATELY;
}
@Override
public DBSObjectCache<? extends DBSObject, DB2Schema> getObjectsCache(DB2Schema object) {
return object.getDataSource().getSchemaCache();
}
@Override
protected DB2Schema createDatabaseObject(IWorkbenchWindow workbenchWindow,
DBECommandContext context,
DB2DataSource parent,
Object copyFrom) {
NewUserDialog dialog = new NewUserDialog(workbenchWindow.getShell(), parent);
if (dialog.open() != IDialogConstants.OK_ID) {
return null;
}
DB2Schema newSchema = new DB2Schema(parent, null);
newSchema.setName(dialog.getUser().getName());
return newSchema;
}
@Override
protected IDatabasePersistAction[] makeObjectCreateActions(ObjectCreateCommand command) {
StringBuilder sb = new StringBuilder(64);
sb.append("CREATE SCHEMA ");
sb.append(command.getObject().getName());
return new IDatabasePersistAction[] { new AbstractDatabasePersistAction("Create schema", sb.toString()) };
}
@Override
protected IDatabasePersistAction[] makeObjectDeleteActions(ObjectDeleteCommand command) {
StringBuilder sb = new StringBuilder(64);
sb.append("DROP SCHEMA ");
sb.append(command.getObject().getName());
sb.append(" RESTRICT");
IDatabasePersistAction[] actions = new IDatabasePersistAction[1];
actions[0] = new AbstractDatabasePersistAction("Drop schema", sb.toString()); //$NON-NLS-2$
return actions;
}
@Override
public void renameObject(DBECommandContext commandContext, DB2Schema schema, String newName) throws DBException {
throw new DBException("Direct schema rename is not yet implemented in DB2. You should use export/import functions for that.");
}
static class NewUserDialog extends Dialog {
private DB2User user;
private Text nameText;
private Text passwordText;
public NewUserDialog(Shell parentShell, DB2DataSource dataSource) {
super(parentShell);
// this.user = new DB2User(dataSource);
}
public DB2User getUser() {
return user;
}
@Override
protected boolean isResizable() {
return true;
}
@Override
protected Control createDialogArea(Composite parent) {
getShell().setText("Set schema/user properties");
Control container = super.createDialogArea(parent);
Composite composite = UIUtils.createPlaceholder((Composite) container, 2);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
nameText = UIUtils.createLabelText(composite, "Schema/User Name", null);
nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
passwordText = UIUtils.createLabelText(composite, "User Password", null, SWT.BORDER | SWT.PASSWORD);
passwordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
return parent;
}
@Override
protected void okPressed() {
// user.setName(DBObjectNameCaseTransformer.transformName(user, nameText.getText()));
// user.setPassword(passwordText.getText());
super.okPressed();
}
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.edit;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.ui.IWorkbenchWindow;
import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.ext.db2.model.DB2TableBase;
import org.jkiss.dbeaver.ext.db2.model.DB2TableColumn;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.prop.DBECommandComposite;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.AbstractDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.jdbc.edit.struct.JDBCTableColumnManager;
import org.jkiss.dbeaver.model.struct.DBSDataType;
import org.jkiss.dbeaver.model.struct.DBSObject;
/**
* DB2 table column manager
*/
public class DB2TableColumnManager extends JDBCTableColumnManager<DB2TableColumn, DB2TableBase> {
@Override
public DBSObjectCache<? extends DBSObject, DB2TableColumn> getObjectsCache(DB2TableColumn object) {
// return object.getParentObject().getContainer().getTableCache().getChildrenCache(object.getParentObject());
return null;
}
@Override
public StringBuilder getNestedDeclaration(DB2TableBase owner, DBECommandComposite<DB2TableColumn, PropertyHandler> command) {
StringBuilder decl = super.getNestedDeclaration(owner, command);
final DB2TableColumn column = command.getObject();
// if (!CommonUtils.isEmpty(column.getComment())) {
// decl.append(" COMMENT '").append(column.getComment()).append("'"); //$NON-NLS-1$ //$NON-NLS-2$
// }
return decl;
}
@Override
protected DB2TableColumn createDatabaseObject(IWorkbenchWindow workbenchWindow,
DBECommandContext context,
DB2TableBase parent,
Object copyFrom) {
DBSDataType columnType = findBestDataType(parent.getDataSource(), "varchar2"); //$NON-NLS-1$
// final DB2TableColumn column = new DB2TableColumn(parent);
// column.setName(DBObjectNameCaseTransformer.transformName(column, getNewColumnName(context, parent)));
// // column.setType((DB2DataType) columnType);
// column.setTypeName(columnType == null ? "INTEGER" : columnType.getName()); //$NON-NLS-1$
// column.setMaxLength(columnType != null && columnType.getDataKind() == DBSDataKind.STRING ? 100 : 0);
// column.setValueType(columnType == null ? Types.INTEGER : columnType.getTypeID());
// column.setOrdinalPosition(-1);
// return column;
return null;
}
@Override
protected IDatabasePersistAction[] makeObjectModifyActions(ObjectChangeCommand command) {
final DB2TableColumn column = command.getObject();
List<IDatabasePersistAction> actions = new ArrayList<IDatabasePersistAction>(2);
boolean hasComment = command.getProperty("comment") != null;
if (!hasComment || command.getProperties().size() > 1) {
actions.add(new AbstractDatabasePersistAction("Modify column", "ALTER TABLE " + column.getTable().getFullQualifiedName() + //$NON-NLS-1$
" MODIFY " + getNestedDeclaration(column.getTable(), command))); //$NON-NLS-1$
}
if (hasComment) {
actions.add(new AbstractDatabasePersistAction("Comment column", "COMMENT ON COLUMN "
+ column.getTable().getFullQualifiedName() + "." + DBUtils.getQuotedIdentifier(column) + " IS '"
+ column.getComment() + "'"));
}
return actions.toArray(new IDatabasePersistAction[actions.size()]);
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.edit;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.ui.IWorkbenchWindow;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.ext.db2.model.DB2Index;
import org.jkiss.dbeaver.ext.db2.model.DB2Schema;
import org.jkiss.dbeaver.ext.db2.model.DB2Table;
import org.jkiss.dbeaver.ext.db2.model.DB2TableColumn;
import org.jkiss.dbeaver.ext.db2.model.DB2TableForeignKey;
import org.jkiss.dbeaver.ext.db2.model.DB2TableUniqueKey;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEObjectRenamer;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.AbstractDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.jdbc.edit.struct.JDBCTableManager;
import org.jkiss.dbeaver.model.struct.DBSObject;
/**
* DB2 table manager
*/
public class DB2TableManager extends JDBCTableManager<DB2Table, DB2Schema> implements DBEObjectRenamer<DB2Table> {
private static final Class<?>[] CHILD_TYPES = { DB2TableColumn.class, DB2TableUniqueKey.class, DB2TableForeignKey.class,
DB2Index.class };
@Override
public DBSObjectCache<? extends DBSObject, DB2Table> getObjectsCache(DB2Table object) {
return (DBSObjectCache) object.getSchema().getTableCache();
}
@Override
protected DB2Table createDatabaseObject(IWorkbenchWindow workbenchWindow,
DBECommandContext context,
DB2Schema parent,
Object copyFrom) {
return null;
//return new DB2Table(parent, DBObjectNameCaseTransformer.transformName(parent, "NewTable")); //$NON-NLS-1$
}
@Override
protected IDatabasePersistAction[] makeObjectModifyActions(ObjectChangeCommand command) {
final DB2Table table = command.getObject();
boolean hasComment = command.getProperty("comment") != null;
List<IDatabasePersistAction> actions = new ArrayList<IDatabasePersistAction>(2);
if (!hasComment || command.getProperties().size() > 1) {
StringBuilder query = new StringBuilder("ALTER TABLE "); //$NON-NLS-1$
query.append(command.getObject().getFullQualifiedName()).append(" "); //$NON-NLS-1$
appendTableModifiers(command.getObject(), command, query);
actions.add(new AbstractDatabasePersistAction(query.toString()));
}
if (hasComment) {
// actions.add(new AbstractDatabasePersistAction("Comment table", "COMMENT ON TABLE " + table.getFullQualifiedName()
// + " IS '" + table.getRemarks() + "'"));
}
return actions.toArray(new IDatabasePersistAction[actions.size()]);
}
@Override
protected void appendTableModifiers(DB2Table table, NestedObjectCommand tableProps, StringBuilder ddl) {
}
@Override
protected IDatabasePersistAction[] makeObjectRenameActions(ObjectRenameCommand command) {
StringBuilder sb = new StringBuilder(256);
sb.append("RENAME TABLE ");
sb.append(command.getObject().getName());
sb.append(" TO ");
sb.append(command.getNewName());
IDatabasePersistAction[] actions = new IDatabasePersistAction[1];
actions[0] = new AbstractDatabasePersistAction("Rename table", sb.toString()); //$NON-NLS-1$
return actions;
}
@Override
public Class<?>[] getChildTypes() {
return CHILD_TYPES;
}
@Override
public void renameObject(DBECommandContext commandContext, DB2Table object, String newName) throws DBException {
processObjectRename(commandContext, object, newName);
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.edit;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.ext.db2.DB2Messages;
import org.jkiss.dbeaver.ext.db2.model.DB2Table;
import org.jkiss.dbeaver.ext.db2.model.DB2Trigger;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.jdbc.edit.struct.JDBCObjectEditor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.dialogs.struct.CreateEntityDialog;
import org.jkiss.utils.CommonUtils;
/**
* DB2TriggerManager
*/
public class DB2TriggerManager extends JDBCObjectEditor<DB2Trigger, DB2Table> {
@Override
public long getMakerOptions() {
return FEATURE_EDITOR_ON_CREATE;
}
@Override
protected void validateObjectProperties(ObjectChangeCommand command) throws DBException {
if (CommonUtils.isEmpty(command.getObject().getName())) {
throw new DBException("Trigger name cannot be empty");
}
}
@Override
public DBSObjectCache<? extends DBSObject, DB2Trigger> getObjectsCache(DB2Trigger object) {
return object.getSchema().getTriggerCache();
}
@Override
protected DB2Trigger createDatabaseObject(IWorkbenchWindow workbenchWindow,
DBECommandContext context,
DB2Table parent,
Object copyFrom) {
CreateEntityDialog dialog = new CreateEntityDialog(workbenchWindow.getShell(),
parent.getDataSource(),
DB2Messages.edit_db2_trigger_manager_dialog_title);
if (dialog.open() != IDialogConstants.OK_ID) {
return null;
}
// DB2TableTrigger newTrigger = new DB2TableTrigger(parent.getContainer(), parent, dialog.getEntityName());
// newTrigger.setSourceDeclaration("TRIGGER " + dialog.getEntityName() + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
// "BEGIN\n" + //$NON-NLS-1$
// "END;"); //$NON-NLS-1$
// return newTrigger;
return null;
}
@Override
protected IDatabasePersistAction[] makeObjectCreateActions(ObjectCreateCommand command) {
return createOrReplaceViewQuery(command.getObject());
}
@Override
protected IDatabasePersistAction[] makeObjectModifyActions(ObjectChangeCommand command) {
return createOrReplaceViewQuery(command.getObject());
}
@Override
protected IDatabasePersistAction[] makeObjectDeleteActions(ObjectDeleteCommand command) {
// return new IDatabasePersistAction[] {
// new AbstractDatabasePersistAction("Drop trigger", "DROP TRIGGER " + command.getObject().getFullQualifiedName()) //$NON-NLS-2$
// };
return null;
}
private IDatabasePersistAction[] createOrReplaceViewQuery(DB2Trigger trigger) {
// String source = DB2Utils.normalizeSourceName(trigger, false);
// if (source == null) {
// return null;
// }
// List<IDatabasePersistAction> actions = new ArrayList<IDatabasePersistAction>();
// actions.add(new AbstractDatabasePersistAction("Create trigger", "CREATE OR REPLACE " + source)); //$NON-NLS-2$
// DB2Utils.addSchemaChangeActions(actions, trigger);
// return actions.toArray(new IDatabasePersistAction[actions.size()]);
return null;
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.edit;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.ui.IWorkbenchWindow;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.IDatabasePersistAction;
import org.jkiss.dbeaver.ext.db2.model.DB2Schema;
import org.jkiss.dbeaver.ext.db2.model.DB2View;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.prop.DBECommandComposite;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.AbstractDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.jdbc.edit.struct.JDBCObjectEditor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.utils.CommonUtils;
/**
* DB2ViewManager
*/
public class DB2ViewManager extends JDBCObjectEditor<DB2View, DB2Schema> {
@Override
public long getMakerOptions() {
return FEATURE_EDITOR_ON_CREATE;
}
@Override
protected void validateObjectProperties(ObjectChangeCommand command) throws DBException {
if (CommonUtils.isEmpty(command.getObject().getName())) {
throw new DBException("View name cannot be empty");
}
}
@Override
public DBSObjectCache<? extends DBSObject, DB2View> getObjectsCache(DB2View object) {
return (DBSObjectCache) object.getSchema().getTableCache();
}
@Override
protected DB2View createDatabaseObject(IWorkbenchWindow workbenchWindow,
DBECommandContext context,
DB2Schema parent,
Object copyFrom) {
// DB2View newView = new DB2View(parent, "NewView"); //$NON-NLS-1$
// return newView;
return null;
}
@Override
protected IDatabasePersistAction[] makeObjectCreateActions(ObjectCreateCommand command) {
return createOrReplaceViewQuery(command);
}
@Override
protected IDatabasePersistAction[] makeObjectModifyActions(ObjectChangeCommand command) {
return createOrReplaceViewQuery(command);
}
@Override
protected IDatabasePersistAction[] makeObjectDeleteActions(ObjectDeleteCommand command) {
return new IDatabasePersistAction[] { new AbstractDatabasePersistAction("Drop view", "DROP VIEW " + command.getObject().getFullQualifiedName()) //$NON-NLS-2$
};
}
private IDatabasePersistAction[] createOrReplaceViewQuery(DBECommandComposite<DB2View, PropertyHandler> command) {
final DB2View view = command.getObject();
boolean hasComment = command.getProperty("comment") != null;
List<IDatabasePersistAction> actions = new ArrayList<IDatabasePersistAction>(2);
if (!hasComment || command.getProperties().size() > 1) {
StringBuilder decl = new StringBuilder(200);
final String lineSeparator = ContentUtils.getDefaultLineSeparator();
// decl.append("CREATE OR REPLACE VIEW ").append(view.getFullQualifiedName()).append(lineSeparator) //$NON-NLS-1$
// .append("AS ").append(view.getAdditionalInfo().getText()); //$NON-NLS-1$
actions.add(new AbstractDatabasePersistAction("Create view", decl.toString()));
}
if (hasComment) {
// actions.add(new AbstractDatabasePersistAction(
// "Comment table",
// "COMMENT ON TABLE " + view.getFullQualifiedName() +
// " IS '" + view.getRemarks() + "'"));
}
return actions.toArray(new IDatabasePersistAction[actions.size()]);
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.editors;
import org.eclipse.jface.action.ControlContribution;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.db2.DB2Constants;
import org.jkiss.dbeaver.ext.db2.model.DB2DDLFormat;
import org.jkiss.dbeaver.ext.db2.model.DB2Table;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorNested;
import org.jkiss.utils.CommonUtils;
/**
* DB2ObjectDDLEditor
*/
public class DB2ObjectDDLEditor extends SQLEditorNested<DB2Table> {
private DB2DDLFormat ddlFormat = DB2DDLFormat.FULL;
public DB2ObjectDDLEditor() {
}
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
}
@Override
public boolean isReadOnly() {
return true;
}
@Override
protected String getSourceText(DBRProgressMonitor monitor) throws DBException {
String ddlFormatString = getEditorInput().getDatabaseObject().getDataSource().getContainer().getPreferenceStore()
.getString(DB2Constants.PREF_KEY_DDL_FORMAT);
if (!CommonUtils.isEmpty(ddlFormatString)) {
try {
ddlFormat = DB2DDLFormat.valueOf(ddlFormatString);
} catch (IllegalArgumentException e) {
log.error(e);
}
}
return ((DB2Table) getEditorInput().getDatabaseObject()).getDDL(monitor, ddlFormat);
}
@Override
protected void setSourceText(String sourceText) {
}
@Override
protected void contributeEditorCommands(ToolBarManager toolBarManager) {
super.contributeEditorCommands(toolBarManager);
toolBarManager.add(new Separator());
toolBarManager.add(new ControlContribution("DDLFormat") {
@Override
protected Control createControl(Composite parent) {
final Combo ddlFormatCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN);
ddlFormatCombo.setToolTipText("DDL Format");
for (DB2DDLFormat format : DB2DDLFormat.values()) {
ddlFormatCombo.add(format.getTitle());
if (format == ddlFormat) {
ddlFormatCombo.select(ddlFormatCombo.getItemCount() - 1);
}
}
ddlFormatCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (DB2DDLFormat format : DB2DDLFormat.values()) {
if (format.ordinal() == ddlFormatCombo.getSelectionIndex()) {
ddlFormat = format;
getEditorInput().getDatabaseObject().getDataSource().getContainer().getPreferenceStore()
.setValue(DB2Constants.PREF_KEY_DDL_FORMAT, ddlFormat.name());
refreshPart(this, true);
break;
}
}
}
});
return ddlFormatCombo;
}
});
}
}
\ No newline at end of file
/*
* Copyright (C) 2010-2013 Serge Rieder serge@jkiss.org
* Copyright (C) 2011-2012 Eugene Fradkin eugene.fradkin@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.editors;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Composite;
import org.jkiss.dbeaver.ext.IDatabaseEditorInput;
import org.jkiss.dbeaver.ext.db2.DB2Messages;
import org.jkiss.dbeaver.ext.db2.model.DB2DataSource;
import org.jkiss.dbeaver.ext.db2.model.session.DB2ServerSessionManager;
import org.jkiss.dbeaver.model.admin.sessions.DBAServerSession;
import org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager;
import org.jkiss.dbeaver.ui.DBIcon;
import org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog;
import org.jkiss.dbeaver.ui.editors.SinglePageDatabaseEditor;
import org.jkiss.dbeaver.ui.views.session.SessionManagerViewer;
import java.util.HashMap;
import java.util.Map;
/**
* DB2SessionEditor
*/
public class DB2SessionEditor extends SinglePageDatabaseEditor<IDatabaseEditorInput> {
private SessionManagerViewer sessionsViewer;
private DisconnectSessionAction killSessionAction;
private DisconnectSessionAction disconnectSessionAction;
@Override
public void dispose() {
sessionsViewer.dispose();
super.dispose();
}
@Override
public void createPartControl(Composite parent) {
killSessionAction = new DisconnectSessionAction(true);
disconnectSessionAction = new DisconnectSessionAction(false);
sessionsViewer = new SessionManagerViewer(this, parent, new DB2ServerSessionManager((DB2DataSource) getDataSource())) {
@Override
protected void contributeToToolbar(DBAServerSessionManager sessionManager, ToolBarManager toolBar) {
toolBar.add(killSessionAction);
toolBar.add(disconnectSessionAction);
toolBar.add(new Separator());
}
@Override
protected void onSessionSelect(DBAServerSession session) {
super.onSessionSelect(session);
killSessionAction.setEnabled(session != null);
disconnectSessionAction.setEnabled(session != null);
}
};
sessionsViewer.refreshSessions();
}
@Override
public void refreshPart(Object source, boolean force) {
sessionsViewer.refreshSessions();
}
private class DisconnectSessionAction extends Action {
private final boolean kill;
public DisconnectSessionAction(boolean kill) {
super(kill ? DB2Messages.editors_db2_session_editor_title_kill_session
: DB2Messages.editors_db2_session_editor_title_disconnect_session, kill ? DBIcon.REJECT.getImageDescriptor()
: DBIcon.SQL_DISCONNECT.getImageDescriptor());
this.kill = kill;
}
@Override
public void run() {
final DBAServerSession session = sessionsViewer.getSelectedSession();
final String action = (kill ? DB2Messages.editors_db2_session_editor_action_kill
: DB2Messages.editors_db2_session_editor_action_disconnect)
+ DB2Messages.editors_db2_session_editor_action__session;
ConfirmationDialog dialog = new ConfirmationDialog(getSite().getShell(),
action,
null,
NLS.bind(DB2Messages.editors_db2_session_editor_confirm_action,
action.toLowerCase(), session),
MessageDialog.CONFIRM,
new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL },
0,
DB2Messages.editors_db2_session_editor_confirm_title,
false);
if (dialog.open() == IDialogConstants.YES_ID) {
Map<String, Object> options = new HashMap<String, Object>();
if (kill) {
options.put(DB2ServerSessionManager.PROP_KILL_SESSION, kill);
}
if (dialog.getToggleState()) {
options.put(DB2ServerSessionManager.PROP_IMMEDIATE, true);
}
sessionsViewer.alterSession(session, options);
}
}
}
}
\ No newline at end of file
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.editors;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.db2.DB2Constants;
import org.jkiss.dbeaver.ext.db2.model.source.DB2SourceObject;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorNested;
/**
* DB2 source declaration editor
*/
public class DB2SourceDeclarationEditor extends SQLEditorNested<DB2SourceObject> {
@Override
protected String getCompileCommandId() {
return DB2Constants.CMD_COMPILE;
}
@Override
protected String getSourceText(DBRProgressMonitor monitor) throws DBException {
return getSourceObject().getSourceDeclaration(monitor);
}
@Override
protected void setSourceText(String sourceText) {
getEditorInput().getPropertySource().setPropertyValue(DB2Constants.PROP_SOURCE_DECLARATION, sourceText);
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.editors;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.db2.DB2Constants;
import org.jkiss.dbeaver.ext.db2.model.source.DB2SourceObjectEx;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorNested;
/**
* DB2 source definition editor
*/
public class DB2SourceDefinitionEditor extends SQLEditorNested<DB2SourceObjectEx> {
@Override
protected String getCompileCommandId() {
return DB2Constants.CMD_COMPILE;
}
@Override
protected String getSourceText(DBRProgressMonitor monitor) throws DBException {
return getSourceObject().getSourceDefinition(monitor);
}
@Override
protected void setSourceText(String sourceText) {
getEditorInput().getPropertySource().setPropertyValue(DB2Constants.PROP_SOURCE_DEFINITION, sourceText);
}
}
/*
* Copyright (C) 2010-2013 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.db2.editors;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.db2.DB2Constants;
import org.jkiss.dbeaver.ext.db2.model.DB2DataSource;
import org.jkiss.dbeaver.ext.db2.model.DB2ObjectType;
import org.jkiss.dbeaver.ext.db2.model.DB2Schema;
import org.jkiss.dbeaver.ext.db2.model.DB2Table;
import org.jkiss.dbeaver.ext.db2.model.dict.DB2ConstraintType;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCExecutionContext;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSEntityConstraintType;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSObjectReference;
import org.jkiss.dbeaver.model.struct.DBSObjectType;
import org.jkiss.dbeaver.model.struct.DBSStructureAssistant;
import org.jkiss.utils.CommonUtils;
/**
* DB2StructureAssistant
*/
public class DB2StructureAssistant implements DBSStructureAssistant {
static protected final Log log = LogFactory.getLog(DB2StructureAssistant.class);
private final DB2DataSource dataSource;
public DB2StructureAssistant(DB2DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public DBSObjectType[] getSupportedObjectTypes() {
return new DBSObjectType[] { DB2ObjectType.TABLE, DB2ObjectType.CONSTRAINT, DB2ObjectType.FOREIGN_KEY, DB2ObjectType.INDEX,
DB2ObjectType.PROCEDURE, DB2ObjectType.TRIGGER, };
}
@Override
public DBSObjectType[] getHyperlinkObjectTypes() {
return new DBSObjectType[] { DB2ObjectType.TABLE, DB2ObjectType.VIEW, };
}
@Override
public DBSObjectType[] getAutoCompleteObjectTypes() {
return new DBSObjectType[] { DB2ObjectType.TABLE, DB2ObjectType.VIEW, };
}
@Override
public Collection<DBSObjectReference> findObjectsByMask(DBRProgressMonitor monitor,
DBSObject parentObject,
DBSObjectType[] objectTypes,
String objectNameMask,
boolean caseSensitive,
int maxResults) throws DBException {
DB2Schema schema = parentObject instanceof DB2Schema ? (DB2Schema) parentObject : null;
JDBCExecutionContext context = dataSource.openContext(monitor, DBCExecutionPurpose.META, "Find objects by name");
try {
List<DBSObjectReference> objects = new ArrayList<DBSObjectReference>();
// Search all objects
searchAllObjects(context, schema, objectNameMask, objectTypes, caseSensitive, maxResults, objects);
if (CommonUtils.contains(objectTypes, DB2ObjectType.CONSTRAINT, DB2ObjectType.FOREIGN_KEY) && objects.size() < maxResults) {
// Search constraints
findConstraintsByMask(context, schema, objectNameMask, objectTypes, maxResults, objects);
}
return objects;
} catch (SQLException ex) {
throw new DBException(ex);
} finally {
context.close();
}
}
private void findConstraintsByMask(JDBCExecutionContext context,
final DB2Schema schema,
String constrNameMask,
DBSObjectType[] objectTypes,
int maxResults,
List<DBSObjectReference> objects) throws SQLException, DBException {
DBRProgressMonitor monitor = context.getProgressMonitor();
List<DBSObjectType> objectTypesList = Arrays.asList(objectTypes);
final boolean hasFK = objectTypesList.contains(DB2ObjectType.FOREIGN_KEY);
final boolean hasConstraints = objectTypesList.contains(DB2ObjectType.CONSTRAINT);
// Load tables
JDBCPreparedStatement dbStat = context.prepareStatement("SELECT \n"
+ "OWNER, TABLE_NAME, CONSTRAINT_NAME, CONSTRAINT_TYPE, SEARCH_CONDITION, STATUS\n" + "FROM SYS.ALL_CONSTRAINTS\n"
+ "WHERE CONSTRAINT_NAME like ?" + (!hasFK ? " AND CONSTRAINT_TYPE<>'R'" : "")
+ (schema != null ? " AND OWNER=?" : ""));
try {
dbStat.setString(1, constrNameMask);
if (schema != null) {
dbStat.setString(2, schema.getName());
}
JDBCResultSet dbResult = dbStat.executeQuery();
try {
int tableNum = maxResults;
while (dbResult.next() && tableNum-- > 0) {
if (monitor.isCanceled()) {
break;
}
final String schemaName = JDBCUtils.safeGetString(dbResult, DB2Constants.COL_OWNER);
final String tableName = JDBCUtils.safeGetString(dbResult, DB2Constants.COL_TABLE_NAME);
final String constrName = JDBCUtils.safeGetString(dbResult, DB2Constants.COL_CONSTRAINT_NAME);
final String constrType = JDBCUtils.safeGetString(dbResult, DB2Constants.COL_CONSTRAINT_TYPE);
final DBSEntityConstraintType type = DB2ConstraintType.getConstraintType(constrType);
objects.add(new AbstractObjectReference(constrName,
dataSource.getSchema(context.getProgressMonitor(), schemaName),
null,
type == DBSEntityConstraintType.FOREIGN_KEY ? DB2ObjectType.FOREIGN_KEY
: DB2ObjectType.CONSTRAINT) {
@Override
public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
DB2Schema tableSchema = schema != null ? schema : dataSource.getSchema(monitor, schemaName);
if (tableSchema == null) {
throw new DBException("Constraint schema '" + schemaName + "' not found");
}
DB2Table table = tableSchema.getTable(monitor, tableName);
if (table == null) {
throw new DBException("Constraint table '" + tableName + "' not found in catalog '" + tableSchema.getName()
+ "'");
}
DBSObject constraint = null;
if (hasFK && type == DBSEntityConstraintType.FOREIGN_KEY) {
constraint = table.getAssociation(monitor, constrName);
}
if (hasConstraints && type != DBSEntityConstraintType.FOREIGN_KEY) {
constraint = table.getConstraint(monitor, constrName);
}
if (constraint == null) {
throw new DBException("Constraint '" + constrName + "' not found in table '" + table.getFullQualifiedName()
+ "'");
}
return constraint;
}
});
}
} finally {
dbResult.close();
}
} finally {
dbStat.close();
}
}
private void searchAllObjects(final JDBCExecutionContext context,
final DB2Schema schema,
String objectNameMask,
DBSObjectType[] objectTypes,
boolean caseSensitive,
int maxResults,
List<DBSObjectReference> objects) throws SQLException, DBException {
StringBuilder objectTypeClause = new StringBuilder(100);
final List<DB2ObjectType> db2ObjectTypes = new ArrayList<DB2ObjectType>(objectTypes.length + 2);
for (DBSObjectType objectType : objectTypes) {
if (objectType instanceof DB2ObjectType) {
db2ObjectTypes.add((DB2ObjectType) objectType);
if (objectType == DB2ObjectType.PROCEDURE) {
db2ObjectTypes.add(DB2ObjectType.FUNCTION);
} else if (objectType == DB2ObjectType.TABLE) {
db2ObjectTypes.add(DB2ObjectType.VIEW);
db2ObjectTypes.add(DB2ObjectType.MATERIALIZED_VIEW);
}
}
}
for (DB2ObjectType objectType : db2ObjectTypes) {
if (objectTypeClause.length() > 0)
objectTypeClause.append(",");
objectTypeClause.append("'").append(objectType.getTypeName()).append("'");
}
if (objectTypeClause.length() == 0) {
return;
}
// Seek for objects (join with public synonyms)
JDBCPreparedStatement dbStat = context
.prepareStatement("SELECT DISTINCT OWNER,OBJECT_NAME,OBJECT_TYPE FROM (SELECT OWNER,OBJECT_NAME,OBJECT_TYPE FROM ALL_OBJECTS WHERE "
+ "OBJECT_TYPE IN ("
+ objectTypeClause
+ ") AND OBJECT_NAME LIKE ? "
+ (schema == null ? "" : " AND OWNER=?")
+ "UNION ALL\n"
+ "SELECT O.OWNER,O.OBJECT_NAME,O.OBJECT_TYPE\n"
+ "FROM ALL_SYNONYMS S,ALL_OBJECTS O\n"
+ "WHERE O.OWNER=S.TABLE_OWNER AND O.OBJECT_NAME=S.TABLE_NAME AND S.OWNER='PUBLIC' AND S.SYNONYM_NAME LIKE ?)"
+ "\nORDER BY OBJECT_NAME");
try {
if (!caseSensitive) {
objectNameMask = objectNameMask.toUpperCase();
}
dbStat.setString(1, objectNameMask);
if (schema != null) {
dbStat.setString(2, schema.getName());
}
dbStat.setString(schema != null ? 3 : 2, objectNameMask);
dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
JDBCResultSet dbResult = dbStat.executeQuery();
try {
while (objects.size() < maxResults && dbResult.next()) {
if (context.getProgressMonitor().isCanceled()) {
break;
}
final String schemaName = JDBCUtils.safeGetString(dbResult, "OWNER");
final String objectName = JDBCUtils.safeGetString(dbResult, "OBJECT_NAME");
final String objectTypeName = JDBCUtils.safeGetString(dbResult, "OBJECT_TYPE");
final DB2ObjectType objectType = DB2ObjectType.getByType(objectTypeName);
if (objectType != null && objectType.isBrowsable() && db2ObjectTypes.contains(objectType)) {
DB2Schema objectSchema = dataSource.getSchema(context.getProgressMonitor(), schemaName);
if (objectSchema == null) {
log.debug("Schema '" + schemaName + "' not found. Probably was filtered");
continue;
}
objects.add(new AbstractObjectReference(objectName, objectSchema, null, objectType) {
@Override
public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
DB2Schema tableSchema = (DB2Schema) getContainer();
DBSObject object = objectType.findObject(context.getProgressMonitor(), tableSchema, objectName);
if (object == null) {
throw new DBException(objectTypeName + " '" + objectName + "' not found in schema '"
+ tableSchema.getName() + "'");
}
return object;
}
});
}
}
} finally {
dbResult.close();
}
} finally {
dbStat.close();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册