Easter cleaning
This commit is contained in:
commit
9e36078b2e
1862 changed files with 270281 additions and 0 deletions
50
nx01-mushroom-mais-mm/pom.xml
Normal file
50
nx01-mushroom-mais-mm/pom.xml
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>love.distributedrebirth.nx01</groupId>
|
||||
<artifactId>nx01</artifactId>
|
||||
<version>〇一。壬寅。一〄-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>nx01-mushroom-mais-mm</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>love.distributedrebirth.nx01</groupId>
|
||||
<artifactId>nx01-mushroom-mais</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eobjects.metamodel</groupId>
|
||||
<artifactId>MetaModel-jdbc</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-pool</groupId>
|
||||
<artifactId>commons-pool</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eobjects.metamodel</groupId>
|
||||
<artifactId>MetaModel-xml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package love.distributedrebirth.nx01.mushroom.mais.mm;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
//import org.apache.metamodel.csv.CsvDataContext;
|
||||
import org.eobjects.metamodel.doc.DocModelDataStore;
|
||||
import org.eobjects.metamodel.doc.DocModelWriter;
|
||||
import org.apache.metamodel.jdbc.JdbcDataContext;
|
||||
//import org.apache.metamodel.xml.XmlDomDataContext;
|
||||
|
||||
/// @author للَّٰهِilLצسُو
|
||||
/// @version ©Δ∞ 仙上主天
|
||||
public class MetaModelMaisWing {
|
||||
|
||||
private final DocModelDataStore dms = new DocModelDataStore();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
MetaModelMaisWing writer = new MetaModelMaisWing();
|
||||
//writer.addDocModelXml(new File("pom.xml"));
|
||||
writer.generate(new File("target/mmdoc"));
|
||||
}
|
||||
|
||||
public void loadDrivers() { // mariadb has to be forced to load in ogsi bundle, pg works fine(no osgi info)
|
||||
//try {
|
||||
//Class.forName(org.postgresql.Driver.class.getName());
|
||||
//Class.forName(org.h2.Driver.class.getName());
|
||||
//Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver.class.getName());
|
||||
//Class.forName(org.mariadb.jdbc.Driver.class.getName());
|
||||
//} catch (ClassNotFoundException e) {
|
||||
// throw new RuntimeException(e);
|
||||
//}
|
||||
}
|
||||
|
||||
public DocModelDataStore getDataStore() {
|
||||
return dms;
|
||||
}
|
||||
|
||||
public void generate(File targetPath) throws Exception {
|
||||
try {
|
||||
DocModelWriter writer = new DocModelWriter(dms);
|
||||
writer.writeModelDoc(targetPath);
|
||||
} finally {
|
||||
//dms.clearAndCloseAllSafe();
|
||||
}
|
||||
}
|
||||
|
||||
// public void addDocModelXml(File file) {
|
||||
// dms.addDataContext("xml-"+file.getName(),new XmlDomDataContext(file,false));
|
||||
// }
|
||||
//
|
||||
// public void addDocModelCsv(File file) {
|
||||
// dms.addDataContext("csv-"+file.getName(),new CsvDataContext(file));
|
||||
// }
|
||||
|
||||
public void addDocModelJdbcMy(String host, String dbName, String user, String pass) throws SQLException {
|
||||
dms.addDataContext("my-"+dbName,new JdbcDataContext(DriverManager.getConnection("jdbc:mariadb://"+host+"/"+dbName,user,pass)));
|
||||
}
|
||||
|
||||
public void addDocModelJdbcPg(String host, String dbName, String user, String pass) throws SQLException {
|
||||
dms.addDataContext("pg-"+dbName,new JdbcDataContext(DriverManager.getConnection("jdbc:postgresql://"+host+"/"+dbName,user,pass)));
|
||||
}
|
||||
|
||||
public void addDocModelJdbcMs(String host, String dbName, String user, String pass) throws SQLException {
|
||||
dms.addDataContext("ms-"+dbName,new JdbcDataContext(DriverManager.getConnection("jdbc:sqlserver://"+host+";databaseName="+dbName,user,pass)));
|
||||
}
|
||||
|
||||
// @SuppressWarnings("deprecation")
|
||||
// public void addDocModelMongoDB(String host, String dbName, String user, String pass) {
|
||||
// Mongo mongo = new Mongo(new ServerAddress(host),new MongoOptions());
|
||||
// dms.addDataContext("mongo-"+dbName,new MongoDbDataContext(mongo.getDB(dbName)));
|
||||
// }
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.metamodel.DataContext;
|
||||
import org.apache.metamodel.jdbc.JdbcDataContext;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class DocModelDataStore {
|
||||
|
||||
private Map<String,DataContext> dataContexts = null;
|
||||
|
||||
public DocModelDataStore() {
|
||||
dataContexts = new TreeMap<String,DataContext>();
|
||||
}
|
||||
|
||||
public void addDataContext(String id,DataContext dataContext) {
|
||||
dataContexts.put(id,dataContext);
|
||||
}
|
||||
|
||||
public void removeDataContext(String id) {
|
||||
dataContexts.remove(id);
|
||||
}
|
||||
|
||||
public Set<Entry<String,DataContext>> entrySet() {
|
||||
return dataContexts.entrySet();
|
||||
}
|
||||
|
||||
public List<DataContext> getDataContexts() {
|
||||
return new ArrayList<DataContext>(dataContexts.values()); // are ordered on id.
|
||||
}
|
||||
|
||||
public String getDataContextKey(DataContext dc) {
|
||||
for (Entry<String,DataContext> entry:entrySet()) {
|
||||
if (entry.getValue().equals(dc)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Could not find key for data context: "+dc.toString());
|
||||
}
|
||||
|
||||
public void clearAndCloseAllSafe() {
|
||||
for (DataContext dc:dataContexts.values()) {
|
||||
if (dc instanceof JdbcDataContext) { // TODO: only support jdbc, MM need 'DataContextLifeCycle extends DataContext'
|
||||
try {
|
||||
((JdbcDataContext)dc).getConnection().close();
|
||||
} catch (SQLException e) { // swallow exception is 'Safe' postfix.
|
||||
// TODO: logger.warn
|
||||
}
|
||||
}
|
||||
}
|
||||
dataContexts.clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,210 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.metamodel.DataContext;
|
||||
import org.apache.metamodel.schema.Column;
|
||||
import org.apache.metamodel.schema.Relationship;
|
||||
import org.apache.metamodel.schema.Schema;
|
||||
import org.apache.metamodel.schema.Table;
|
||||
import org.x4o.maisdoc.flake.MaisDocGenerator;
|
||||
import org.x4o.maisdoc.flake.DefaultPageWriterHelp;
|
||||
import org.x4o.maisdoc.flake.DefaultPageWriterIndexAll;
|
||||
import org.x4o.maisdoc.flake.DefaultPageWriterTree;
|
||||
import org.x4o.maisdoc.model.MaisDoc;
|
||||
import org.x4o.maisdoc.model.MaisDocConcept;
|
||||
import org.x4o.maisdoc.model.MaisDocNode;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class DocModelWriter {
|
||||
|
||||
private static final String[] C_DATA_STORE = {"data-store","Overview","All data stores.","The data stores of user defines resources."};
|
||||
private static final String[] C_DATA_CONTEXT = {"data-context","DataContext","The MetaModel DataContext.","The MetaModel DataContext provides the meta schema definitions."};
|
||||
private static final String[] C_SCHEMA = {"schema","Schema","The schema.","The schema hold the tables and other data types."};
|
||||
private static final String[] C_TABLE = {"table","Table","The Data Table.","The table has columns so can hold row/column data."};
|
||||
//private static final String[] C_VIEW = {"view","Table","The Data Table.","The table has columns so can hold row/column data."};
|
||||
|
||||
private static final String[] CC_RS = {"relationship","Relationship","The relationships.","The telationships data."};
|
||||
|
||||
private MaisDocGenerator writer = null;
|
||||
private MaisDoc doc = null;
|
||||
|
||||
public DocModelWriter(DocModelDataStore dmds) {
|
||||
if (dmds==null) {
|
||||
throw new NullPointerException("Can't write null "+DocModelDataStore.class.getSimpleName());
|
||||
}
|
||||
doc = buildApiDoc(dmds);
|
||||
writer = new MaisDocGenerator();
|
||||
}
|
||||
|
||||
public MaisDoc getApiDoc() {
|
||||
return doc;
|
||||
}
|
||||
|
||||
public void writeModelDoc(File basePath) throws IOException, SAXException {
|
||||
doc.checkModel();
|
||||
writer.write(doc,basePath);
|
||||
}
|
||||
|
||||
private MaisDoc buildApiDoc(DocModelDataStore dmds) {
|
||||
MaisDoc doc = new MaisDoc();
|
||||
doc.setName("MetaModel");
|
||||
doc.setDescription("MetaModel generic schema overview.");
|
||||
doc.setDocAbout("MetaModel of\nDataContexts");
|
||||
doc.createDocCopyright(System.getProperty("user.name"));
|
||||
doc.setDocPageSubTitle("MMDB 1.0 API");
|
||||
doc.addMetaKeywordAll(createLanguageKeywords());
|
||||
doc.setNoFrameAllName("All Schemas");
|
||||
doc.setFrameNavOverviewPrintParent(true);
|
||||
doc.setFrameNavPrintParent(true);
|
||||
doc.setFrameNavPrintParentParent(true);
|
||||
doc.setGroupTypeName("summary", "Summary",1);
|
||||
doc.setGroupTypeName("overview", "Overview",2);
|
||||
|
||||
//doc.addRemoteClass(new ApiDocRemoteClass("file:///home/willemc/devv/git/x4o/x4o-driver/target/apidocs"));
|
||||
//doc.addRemoteClass(new ApiDocRemoteClass("http://docs.oracle.com/javase/7/docs/api/"));
|
||||
|
||||
doc.addTreeNodeClassExclude(Relationship.class);
|
||||
|
||||
doc.setFrameNavConceptClass(Table.class);
|
||||
|
||||
doc.addTreeNodePageModeClass(DocModelDataStore.class);
|
||||
doc.addTreeNodePageModeClass(DataContext.class);
|
||||
doc.addTreeNodePageModeClass(Schema.class);
|
||||
|
||||
doc.addAnnotatedClasses(DocModelWriterSchema.class);
|
||||
doc.addAnnotatedClasses(DocModelWriterTable.class);
|
||||
|
||||
MaisDocConcept adc1 = doc.addConcept(new MaisDocConcept(null,C_DATA_STORE,DocModelDataStore.class));
|
||||
MaisDocConcept adc2 = doc.addConcept(new MaisDocConcept(adc1,C_DATA_CONTEXT,DataContext.class));
|
||||
MaisDocConcept adc3 = doc.addConcept(new MaisDocConcept(adc2,C_SCHEMA,Schema.class));
|
||||
MaisDocConcept adc4 = doc.addConcept(new MaisDocConcept(adc3,C_TABLE,Table.class));
|
||||
|
||||
adc4.addChildConcepts(new MaisDocConcept(adc4, CC_RS, Relationship.class));
|
||||
|
||||
doc.addDocPage(DefaultPageWriterTree.createDocPage());
|
||||
doc.addDocPage(DefaultPageWriterIndexAll.createDocPage());
|
||||
doc.addDocPage(DefaultPageWriterHelp.createDocPage());
|
||||
|
||||
MaisDocNode rootNode = new MaisDocNode(dmds,"data-store","DataStore","All schemas from all data contexts.");
|
||||
doc.setRootNode(rootNode);
|
||||
for (Entry<String,DataContext> entry:dmds.entrySet()) {
|
||||
MaisDocNode dcNode = rootNode.addNode(createNodeDataContext(entry));
|
||||
for (Schema schema:entry.getValue().getSchemas()) {;
|
||||
if (isInvalidDocSchema(schema)) {
|
||||
continue;
|
||||
}
|
||||
MaisDocNode schemaNode = dcNode.addNode(createNodeSchema(schema));
|
||||
for (Table table:schema.getTables()) {
|
||||
schemaNode.addNode(createNodeTable(table));
|
||||
}
|
||||
for (Relationship rs:schema.getRelationships()) {
|
||||
MaisDocNode rsNode = createNodeRelationship(rs);
|
||||
if (rsNode.getId().length() > 255) {
|
||||
// TODO-1 track BUG in meta-model
|
||||
// TODO-2 change or add code for limit as nx01/pom.xml also generated an too long path
|
||||
System.out.println("BUG ignored: " + rs);
|
||||
continue;
|
||||
}
|
||||
schemaNode.addNode(rsNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
private boolean isInvalidDocSchema(Schema schema) {
|
||||
if (schema.getName().toLowerCase().startsWith("information_schema")) {
|
||||
return true;
|
||||
}
|
||||
if (schema.getName().toLowerCase().equals("sys") || schema.getName().toLowerCase().equals("dbo") ) {
|
||||
return true;
|
||||
}
|
||||
if (schema.getTableCount()==0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private MaisDocNode createNodeDataContext(Entry<String,DataContext> entry) {
|
||||
return new MaisDocNode(entry.getValue(),entry.getKey(),entry.getKey(),entry.getKey());
|
||||
}
|
||||
private MaisDocNode createNodeSchema(Schema schema) {
|
||||
return new MaisDocNode(schema,schema.getName(),schema.getQualifiedLabel(),schema.getName());
|
||||
}
|
||||
private MaisDocNode createNodeTable(Table table) {
|
||||
return new MaisDocNode(table,table.getName(),table.getQualifiedLabel(),table.getRemarks());
|
||||
}
|
||||
private MaisDocNode createNodeRelationship(Relationship rs) {
|
||||
String name = rsName(rs);
|
||||
return new MaisDocNode(rs,name,name,name);
|
||||
}
|
||||
|
||||
// BUG in lastest meta-model code
|
||||
// java.io.IOException: java.io.FileNotFoundException: (File name too long)
|
||||
// c_validcombination_c_validcombination_id_c_validcombination_id_c_validcombination_id_c_validcombination_id_c_validcombination_id_c_validcombination_id_c_validcombination_id_c_validcombination_id_c_validcombination_id_c_acctschema_gl_currencybalancing_acct_incomesummary_acct_intercompanydueto_acct_intercompanyduefrom_acct_ppvoffset_acct_retainedearning_acct_suspensebalancing_acct_suspenseerror_acct_cfs_order_acct_rs
|
||||
|
||||
private String rsName(Relationship rs) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(rs.getPrimaryTable().getName());
|
||||
buf.append('_');
|
||||
for (Column c:rs.getPrimaryColumns()) {
|
||||
buf.append(c.getName());
|
||||
buf.append('_');
|
||||
}
|
||||
buf.append(rs.getForeignTable().getName());
|
||||
buf.append('_');
|
||||
for (Column c:rs.getForeignColumns()) {
|
||||
buf.append(c.getName());
|
||||
buf.append('_');
|
||||
}
|
||||
buf.append("RS");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private List<String> createLanguageKeywords() {
|
||||
List<String> keywords = new ArrayList<String>(10);
|
||||
keywords.add("eobjects");
|
||||
keywords.add("metamodel");
|
||||
keywords.add("meta-model");
|
||||
keywords.add("schema");
|
||||
keywords.add("schema-model");
|
||||
keywords.add("database");
|
||||
keywords.add("database-model");
|
||||
keywords.add("documentation");
|
||||
keywords.add("javadoc");
|
||||
keywords.add("x4o");
|
||||
return keywords;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.metamodel.DataContext;
|
||||
import org.apache.metamodel.data.DataSet;
|
||||
import org.apache.metamodel.query.FunctionType;
|
||||
import org.apache.metamodel.schema.Schema;
|
||||
import org.apache.metamodel.schema.Table;
|
||||
import org.apache.metamodel.schema.TableType;
|
||||
import org.x4o.maisdoc.flake.MaisDocContentCss;
|
||||
import org.x4o.maisdoc.flake.MaisDocContentWriter;
|
||||
import org.x4o.maisdoc.flake.MaisDocNodeWriterMethod;
|
||||
import org.x4o.maisdoc.model.MaisDocNode;
|
||||
import org.x4o.maisdoc.model.MaisDocNodeBody;
|
||||
import org.x4o.maisdoc.model.MaisDocWriteEvent;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class DocModelWriterSchema {
|
||||
|
||||
private List<Table> filterTables(Schema schema,TableType tableType,boolean addEquals) {
|
||||
List<Table> result = new ArrayList<Table>();
|
||||
for (Table table:schema.getTables()) {
|
||||
if (addEquals==tableType.equals(table.getType())) {
|
||||
result.add(table);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={Schema.class})
|
||||
public void writeSchemaTableSummary(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
|
||||
MaisDocContentWriter writer = event.getWriter();
|
||||
Schema schema = (Schema)event.getEventObject().getUserData();
|
||||
DataContext dc = (DataContext)event.getEventObject().getParent().getUserData();
|
||||
List<Table> tables = filterTables(schema,TableType.VIEW,false);
|
||||
if (tables.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
writer.docTableStart("Table Summary", "All tables in the schema.",MaisDocContentCss.overviewSummary);
|
||||
writer.docTableHeader("Name", "Description");
|
||||
for (Table table:tables) {
|
||||
Number tableCount = 0l;
|
||||
if (table.getColumnCount()>0) {
|
||||
DataSet ds = dc.query().from(table).select(FunctionType.COUNT, table.getColumns().get(0)).execute();
|
||||
ds.next();
|
||||
tableCount = (Number)ds.getRow().getValue(0);
|
||||
ds.close();
|
||||
}
|
||||
String link = MaisDocContentWriter.toSafeUri(table.getName())+"/index.html";
|
||||
writer.docTableRowLink(link,table.getName(),"Record Count: "+tableCount);
|
||||
}
|
||||
writer.docTableEnd();
|
||||
}
|
||||
|
||||
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={Schema.class})
|
||||
public void writeSchemaViewSummary(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
|
||||
MaisDocContentWriter writer = event.getWriter();
|
||||
Schema schema = (Schema)event.getEventObject().getUserData();
|
||||
List<Table> tables = filterTables(schema,TableType.VIEW,true);
|
||||
if (tables.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
writer.docTableStart("View Summary", "All views in the schema.",MaisDocContentCss.overviewSummary);
|
||||
writer.docTableHeader("Name", "Description");
|
||||
for (Table table:schema.getTables()) {
|
||||
if (!TableType.VIEW.equals(table.getType())) {
|
||||
continue;
|
||||
}
|
||||
String link = MaisDocContentWriter.toSafeUri(table.getName())+"/index.html";
|
||||
writer.docTableRowLink(link,table.getName(),table.getQualifiedLabel());
|
||||
}
|
||||
writer.docTableEnd();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,496 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.metamodel.DataContext;
|
||||
import org.eobjects.metamodel.doc.jdbc.DBIndex;
|
||||
import org.eobjects.metamodel.doc.jdbc.DBIndexColumn;
|
||||
import org.eobjects.metamodel.doc.jdbc.DBTable;
|
||||
import org.eobjects.metamodel.doc.jdbc.DBTableFactory;
|
||||
import org.apache.metamodel.jdbc.JdbcDataContext;
|
||||
import org.apache.metamodel.schema.Column;
|
||||
import org.apache.metamodel.schema.Relationship;
|
||||
import org.apache.metamodel.schema.Table;
|
||||
import org.apache.metamodel.schema.TableType;
|
||||
import org.x4o.maisdoc.flake.MaisDocContentCss;
|
||||
import org.x4o.maisdoc.flake.MaisDocContentWriter;
|
||||
import org.x4o.maisdoc.flake.MaisDocNodeWriterMethod;
|
||||
import org.x4o.maisdoc.model.MaisDocIndexItem;
|
||||
import org.x4o.maisdoc.model.MaisDocNode;
|
||||
import org.x4o.maisdoc.model.MaisDocNodeBody;
|
||||
import org.x4o.maisdoc.model.MaisDocWriteEvent;
|
||||
import org.x4o.sax3.SAX3WriterHtml.Tag;
|
||||
import org.x4o.sax3.io.ContentCloseable;
|
||||
|
||||
public class DocModelWriterTable {
|
||||
|
||||
private DBTableFactory dbTableFactory;
|
||||
private DBTable currentDBTable;
|
||||
|
||||
public DocModelWriterTable() {
|
||||
dbTableFactory = new DBTableFactory();
|
||||
}
|
||||
|
||||
private DBTable getDBTable(MaisDocWriteEvent<MaisDocNode> event) {
|
||||
Table table = (Table)event.getEventObject().getUserData();
|
||||
if (currentDBTable!=null && currentDBTable.getTable().getQualifiedLabel().equals(table.getQualifiedLabel()))
|
||||
{
|
||||
return currentDBTable;
|
||||
}
|
||||
DataContext dcRaw = (DataContext)event.getEventObject().getParent().getParent().getUserData();
|
||||
if (dcRaw instanceof JdbcDataContext) {
|
||||
JdbcDataContext dc = (JdbcDataContext) dcRaw;
|
||||
try {
|
||||
currentDBTable = dbTableFactory.loadMetaTable(dc, table);
|
||||
return currentDBTable;
|
||||
} catch (SQLException e) {
|
||||
throw new IllegalStateException("Could not fetch meta table: "+e.getMessage(),e);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Relationship> rsFilterColumn(Collection<Relationship> rsa,Column column,boolean filterPrimary) {
|
||||
List<Relationship> filtered = rsFilter(rsa, column.getTable(), filterPrimary);
|
||||
List<Relationship> result = new ArrayList<Relationship>(10);
|
||||
for (Relationship rs: filtered) {
|
||||
if (!filterPrimary) {
|
||||
if (!rs.getPrimaryColumns().contains(column)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (!rs.getForeignColumns().contains(column)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
result.add(rs);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Relationship> rsFilter(Collection<Relationship> rsa,Table table,boolean filterPrimary) {
|
||||
List<Relationship> result = new ArrayList<Relationship>(10);
|
||||
for (Relationship rs : rsa) {
|
||||
if (filterPrimary) {
|
||||
if (rs.getPrimaryTable().equals(table)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (rs.getForeignTable().equals(table)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
result.add(rs);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.DESCRIPTION_LINKS,targetClasses={Table.class})
|
||||
public void writeTableDescription(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
|
||||
MaisDocContentWriter writer = event.getWriter();
|
||||
Table table = (Table)event.getEventObject().getUserData();
|
||||
|
||||
if (!TableType.VIEW.equals(table.getType())) {
|
||||
Iterator<Relationship> rsIn = rsFilter(table.getRelationships(),table,false).iterator();
|
||||
Iterator<Relationship> rsOut = rsFilter(table.getRelationships(),table,true).iterator();
|
||||
writer.printTagStart(Tag.dl);
|
||||
writer.printTagCharacters(Tag.dt,"All Incoming Relations:");
|
||||
writer.printTagStart(Tag.dd);
|
||||
if (!rsIn.hasNext()) {
|
||||
writer.printCharacters("Table is not referenced.");
|
||||
}
|
||||
while (rsIn.hasNext()) {
|
||||
Relationship rs = rsIn.next();
|
||||
String uri = "../../"+MaisDocContentWriter.toSafeUri(rs.getForeignTable().getSchema().getName())+"/"+MaisDocContentWriter.toSafeUri(rs.getForeignTable().getName())+"/index.html";
|
||||
writer.printHref(uri, rs.getForeignTable().getName());
|
||||
if (rsIn.hasNext()) {
|
||||
writer.printCharacters(", ");
|
||||
}
|
||||
}
|
||||
writer.printTagEnd(Tag.dd);
|
||||
writer.printTagEnd(Tag.dl);
|
||||
|
||||
writer.printTagStart(Tag.dl);
|
||||
writer.printTagCharacters(Tag.dt,"All Referenced Tables:");
|
||||
writer.printTagStart(Tag.dd);
|
||||
if (!rsOut.hasNext()) {
|
||||
writer.printCharacters("Table has no references.");
|
||||
}
|
||||
while (rsOut.hasNext()) {
|
||||
Relationship rs = rsOut.next();
|
||||
String uri = "../../"+MaisDocContentWriter.toSafeUri(rs.getPrimaryTable().getSchema().getName())+"/"+MaisDocContentWriter.toSafeUri(rs.getPrimaryTable().getName())+"/index.html";
|
||||
writer.printHref(uri, rs.getPrimaryTable().getName());
|
||||
if (rsOut.hasNext()) {
|
||||
writer.printCharacters(", ");
|
||||
}
|
||||
}
|
||||
writer.printTagEnd(Tag.dd);
|
||||
writer.printTagEnd(Tag.dl);
|
||||
}
|
||||
}
|
||||
|
||||
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.DESCRIPTION_NODE,targetClasses={Table.class})
|
||||
public void writeTableSqlView(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
|
||||
MaisDocContentWriter writer = event.getWriter();
|
||||
Table table = (Table)event.getEventObject().getUserData();
|
||||
|
||||
// fixme or only normal
|
||||
if (!TableType.VIEW.equals(table.getType())) {
|
||||
event.getWriter().printCharacters(event.getEventObject().getDescription());
|
||||
} else {
|
||||
event.getWriter().printCharacters("View "+table.getQualifiedLabel());
|
||||
}
|
||||
DBTable tableDB = getDBTable(event);
|
||||
if (tableDB!=null && tableDB.getSqlScript()!=null) {
|
||||
try (ContentCloseable content = writer.docPageContent()) {
|
||||
writeSqlBlock(writer,tableDB.getSqlScript());
|
||||
for (DBIndex index:tableDB.getIndexes()) {
|
||||
if (index.getSqlScript()!=null) {
|
||||
writeSqlBlock(writer,index.getSqlScript());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={Table.class},nodeBodyOrders={3},contentGroup="Columns",contentGroupType="summary")
|
||||
public void writeTableSummary(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
|
||||
MaisDocContentWriter writer = event.getWriter();
|
||||
Table table = (Table)event.getEventObject().getUserData();
|
||||
if (TableType.VIEW.equals(table.getType())) {
|
||||
writer.docTableStart("Column Summary", "All column of the view.",null);
|
||||
} else {
|
||||
writer.docTableStart("Column Summary", "All column of the table.",null);
|
||||
}
|
||||
writer.docTableHeader("Name", "Description");
|
||||
for (Column column : table.getColumns()) {
|
||||
String desc = column.getRemarks();
|
||||
if (desc == null || desc.isEmpty()) {
|
||||
desc = column.getQualifiedLabel();
|
||||
}
|
||||
writer.docTableRowLink("#" + MaisDocContentWriter.toSafeUri(column.getName()), column.getName(), desc);
|
||||
}
|
||||
writer.docTableEnd();
|
||||
}
|
||||
|
||||
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={Table.class},nodeBodyOrders={1},contentGroup="Primary Key",contentGroupType="summary")
|
||||
public void writeTablePKSummary(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
|
||||
MaisDocContentWriter writer = event.getWriter();
|
||||
Table table = (Table)event.getEventObject().getUserData();
|
||||
DBTable tableDB = getDBTable(event);
|
||||
if (tableDB==null) {
|
||||
writer.docPageBlockStart("Primary Key.","primary_key",null);
|
||||
writer.printTagStart(Tag.code);
|
||||
List<Column> cols = table.getPrimaryKeys();
|
||||
for (int i=0;i<cols.size();i++) {
|
||||
Column column = cols.get(i);
|
||||
writer.printHref("#"+MaisDocContentWriter.toSafeUri(column.getName()), column.getName());
|
||||
if (i<cols.size()-1) {
|
||||
writer.printCharacters(", ");
|
||||
}
|
||||
}
|
||||
if (cols.size()==0) {
|
||||
writer.printCharacters("No primary key.");
|
||||
}
|
||||
writer.printTagEnd(Tag.code);
|
||||
writer.docPageBlockEnd();
|
||||
} else {
|
||||
List<String> cols = new ArrayList<String>(5);
|
||||
if (tableDB.getPrimaryKey()!=null) {
|
||||
cols.addAll(tableDB.getPrimaryKey().getColumnNames());
|
||||
writer.docPageBlockStart("Primary Key: "+tableDB.getPrimaryKey().getName(),"primary_key",null);
|
||||
} else {
|
||||
writer.docPageBlockStart("Primary Key: None","primary_key",null);
|
||||
}
|
||||
writer.printTagStart(Tag.code);
|
||||
|
||||
for (int i=0;i<cols.size();i++) {
|
||||
String column = cols.get(i);
|
||||
writer.printHref("#"+MaisDocContentWriter.toSafeUri(column), column);
|
||||
if (i<cols.size()-1) {
|
||||
writer.printCharacters(", ");
|
||||
}
|
||||
}
|
||||
if (cols.isEmpty()) {
|
||||
writer.printCharacters("No primary key.");
|
||||
}
|
||||
writer.printTagEnd(Tag.code);
|
||||
writer.docPageBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={Table.class},nodeBodyOrders={2},contentGroup="Indexes",contentGroupType="summary")
|
||||
public void writeTableIDXSummary(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
|
||||
MaisDocContentWriter writer = event.getWriter();
|
||||
Table table = (Table)event.getEventObject().getUserData();
|
||||
DBTable tableDB = getDBTable(event);
|
||||
if (tableDB==null) {
|
||||
List<Column> columns = table.getIndexedColumns();
|
||||
if (columns.size()==0) {
|
||||
return;
|
||||
}
|
||||
writer.printHrefNamed("column_indexes");
|
||||
writer.printTagCharacters(Tag.h3, "Indexed Columns");
|
||||
writer.printTagStart(Tag.code);
|
||||
for (Column column:columns) {
|
||||
writer.printHref("#"+MaisDocContentWriter.toSafeUri(column.getName()), column.getName());
|
||||
}
|
||||
writer.printTagEnd(Tag.code);
|
||||
} else {
|
||||
writer.printHrefNamed("column_indexes");
|
||||
//writer.printTagCharacters(Tag.h3, "Indexes");
|
||||
writer.docTableStart("Column Indexes", "All indexes of the table.",null);
|
||||
writer.docTableHeader("Name", "Columns");
|
||||
for (DBIndex index:tableDB.getIndexes()) {
|
||||
StringBuilder buf = new StringBuilder(30);
|
||||
List<DBIndexColumn> cols = index.getIndexColumns();
|
||||
for (int i=0;i<cols.size();i++) {
|
||||
DBIndexColumn col = cols.get(i);
|
||||
buf.append(col.getColumn());
|
||||
if (i<cols.size()-1) {
|
||||
buf.append(",");
|
||||
}
|
||||
}
|
||||
writer.docTableRowLink("#"+MaisDocContentWriter.toSafeUri(index.getName()),index.getName(),buf.toString());
|
||||
}
|
||||
writer.docTableEnd();
|
||||
|
||||
//writer.printTagStart(Tag.code);
|
||||
//writer.printHref("#"+ApiDocContentWriter.toSafeUri(index.getName()), index.getName());
|
||||
//writer.printTagEnd(Tag.code);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSqlBlock(MaisDocContentWriter writer,String sql) throws IOException {
|
||||
writer.printTagStart(Tag.div,MaisDocContentCss.block);
|
||||
writer.printTagStart(Tag.pre);
|
||||
writer.printCharacters(sql);
|
||||
writer.printTagEnd(Tag.pre);
|
||||
writer.printTagEnd(Tag.div);
|
||||
}
|
||||
|
||||
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.DETAIL,targetClasses={Table.class},nodeBodyOrders={1},contentGroup="Indexes",contentGroupType="overview")
|
||||
public void writeTableDetailIndex(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
|
||||
MaisDocContentWriter writer = event.getWriter();
|
||||
//Table table = (Table)event.getEventObject().getUserData();
|
||||
DBTable tableDB = getDBTable(event);
|
||||
if (tableDB==null) {
|
||||
return;
|
||||
}
|
||||
for (DBIndex index:tableDB.getIndexes()) {
|
||||
writer.printHrefNamed(index.getName());
|
||||
writer.docPageBlockStart();
|
||||
writer.printTagCharacters(Tag.h4, index.getName());
|
||||
|
||||
writer.printTagStart(Tag.pre);
|
||||
writer.printCharacters("INDEX ");
|
||||
writer.printCharacters(index.getSchema());
|
||||
writer.printCharacters(".");
|
||||
writer.printCharacters(index.getName());
|
||||
if (index.getUnique()!=null && index.getUnique()) {
|
||||
writer.printCharacters(" UNIQUE=true");
|
||||
}
|
||||
if (index.getIndexQualifier()!=null) {
|
||||
writer.printCharacters(" QUALIFIER=");
|
||||
writer.printCharacters(index.getIndexQualifier());
|
||||
}
|
||||
if (index.getCatalog()!=null) {
|
||||
writer.printCharacters(" CATELOG=");
|
||||
writer.printCharacters(index.getCatalog());
|
||||
}
|
||||
writer.printTagEnd(Tag.pre);
|
||||
|
||||
|
||||
writer.printTagStart(Tag.div,MaisDocContentCss.block);
|
||||
writer.printCharacters("Type: ");
|
||||
writer.printCharacters(index.getType().name());
|
||||
writer.printTagEnd(Tag.div);
|
||||
|
||||
if (index.getSqlScript()!=null) {
|
||||
writeSqlBlock(writer,index.getSqlScript());
|
||||
}
|
||||
|
||||
writer.printTagStart(Tag.dl);
|
||||
writer.printTagStart(Tag.dt);
|
||||
writer.printTagStart(Tag.span,MaisDocContentCss.strong);
|
||||
writer.printCharacters("Columns:");
|
||||
writer.printTagEnd(Tag.span);
|
||||
writer.printTagEnd(Tag.dt);
|
||||
for (DBIndexColumn column:index.getIndexColumns()) {
|
||||
writer.printTagStart(Tag.dd);
|
||||
writer.printTagStart(Tag.code);
|
||||
writer.printHref("#"+MaisDocContentWriter.toSafeUri(column.getColumn()), column.getColumn());
|
||||
writer.printTagEnd(Tag.code);
|
||||
writer.printCharacters(" ORDER ");
|
||||
if (column.getAscending()!=null && column.getAscending()) {
|
||||
writer.printCharacters("ASC");
|
||||
} else {
|
||||
writer.printCharacters("DESC");
|
||||
}
|
||||
writer.printTagEnd(Tag.dd);
|
||||
}
|
||||
writer.printTagEnd(Tag.dl);
|
||||
|
||||
writer.docPageBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.DETAIL,targetClasses={Table.class},nodeBodyOrders={2},contentGroup="Columns",contentGroupType="overview")
|
||||
public void writeTableDetail(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
|
||||
MaisDocContentWriter writer = event.getWriter();
|
||||
Table table = (Table)event.getEventObject().getUserData();
|
||||
DBTable tableDB = getDBTable(event);
|
||||
for (Column column:table.getColumns()) {
|
||||
|
||||
MaisDocIndexItem indexItem = new MaisDocIndexItem();
|
||||
indexItem.setLinkText(column.getName());
|
||||
event.getDoc().getNodeData().addIndexItem(indexItem);
|
||||
|
||||
writer.printHrefNamed(column.getName());
|
||||
writer.docPageBlockStart();
|
||||
writer.printTagCharacters(Tag.h4, column.getName());
|
||||
|
||||
writer.printTagStart(Tag.pre);
|
||||
writer.printCharacters(column.getQualifiedLabel());
|
||||
writer.printCharacters(" ");
|
||||
if (column.getNativeType() != null) {
|
||||
writer.printCharacters(column.getNativeType().toUpperCase());
|
||||
}
|
||||
if (column.getColumnSize()!=null) {
|
||||
writer.printCharacters(" (");
|
||||
writer.printCharacters(""+column.getColumnSize());
|
||||
writer.printCharacters(")");
|
||||
}
|
||||
if (column.isNullable()) {
|
||||
writer.printCharacters(" NULL");
|
||||
} else {
|
||||
writer.printCharacters(" NOT NULL");
|
||||
}
|
||||
if (column.isPrimaryKey()) {
|
||||
writer.printCharacters(" PRIMARY KEY");
|
||||
}
|
||||
writer.printTagEnd(Tag.pre);
|
||||
|
||||
if (column.getRemarks()!=null && !column.getRemarks().isEmpty()) {
|
||||
writer.printTagStart(Tag.div,MaisDocContentCss.block);
|
||||
writer.printCharacters(column.getRemarks());
|
||||
writer.printTagEnd(Tag.div);
|
||||
}
|
||||
|
||||
writer.printTagStart(Tag.dl);
|
||||
if (column.isIndexed()) {
|
||||
List<DBIndex> idx = null;
|
||||
if (tableDB!=null) {
|
||||
idx = tableDB.getIndexesByColumn(column.getName());
|
||||
}
|
||||
writer.printTagStart(Tag.dt);
|
||||
writer.printTagStart(Tag.span,MaisDocContentCss.strong);
|
||||
writer.printCharacters("Indexes:");
|
||||
writer.printTagEnd(Tag.span);
|
||||
writer.printTagEnd(Tag.dt);
|
||||
|
||||
if (idx!=null) {
|
||||
writer.printTagStart(Tag.dd);
|
||||
writer.printTagStart(Tag.code);
|
||||
for (int i=0;i<idx.size();i++) {
|
||||
DBIndex index = idx.get(i);
|
||||
writer.printHref("#"+MaisDocContentWriter.toSafeUri(index.getName()), index.getName());
|
||||
if (i<idx.size()-1) {
|
||||
writer.printCharacters(",");
|
||||
}
|
||||
}
|
||||
writer.printTagEnd(Tag.code);
|
||||
writer.printTagEnd(Tag.dd);
|
||||
} else {
|
||||
writer.printTagStart(Tag.dd);
|
||||
writer.printTagStart(Tag.code);
|
||||
writer.printCharacters("Unknown");
|
||||
writer.printTagEnd(Tag.code);
|
||||
writer.printCharacters(" - This column is indexed.");
|
||||
writer.printTagEnd(Tag.dd);
|
||||
}
|
||||
}
|
||||
|
||||
if (!TableType.VIEW.equals(table.getType())) {
|
||||
Iterator<Relationship> rsIn = rsFilterColumn(table.getRelationships(),column,false).iterator();
|
||||
Iterator<Relationship> rsOut = rsFilterColumn(table.getRelationships(),column,true).iterator();
|
||||
|
||||
if (rsIn.hasNext()) {
|
||||
writer.printTagStart(Tag.dt);
|
||||
writer.printTagStart(Tag.span,MaisDocContentCss.strong);
|
||||
writer.printCharacters("Referenced:");
|
||||
writer.printTagEnd(Tag.span);
|
||||
writer.printTagEnd(Tag.dt);
|
||||
|
||||
while (rsIn.hasNext()) {
|
||||
Relationship rs = rsIn.next();
|
||||
String uri = "../../"+MaisDocContentWriter.toSafeUri(rs.getForeignTable().getSchema().getName())+"/"+MaisDocContentWriter.toSafeUri(rs.getForeignTable().getName())+"/index.html";
|
||||
String cols = rs.getForeignColumns().stream().map(v -> v.getName()).collect(Collectors.joining(" - "));
|
||||
writer.printTagStart(Tag.dd);
|
||||
writer.printTagStart(Tag.code);
|
||||
writer.printHref(uri, rs.getForeignTable().getName() + "." + cols);
|
||||
writer.printTagEnd(Tag.code);
|
||||
writer.printTagEnd(Tag.dd);
|
||||
}
|
||||
}
|
||||
|
||||
if (rsOut.hasNext()) {
|
||||
writer.printTagStart(Tag.dt);
|
||||
writer.printTagStart(Tag.span,MaisDocContentCss.strong);
|
||||
writer.printCharacters("References:");
|
||||
writer.printTagEnd(Tag.span);
|
||||
writer.printTagEnd(Tag.dt);
|
||||
|
||||
while (rsOut.hasNext()) {
|
||||
Relationship rs = rsOut.next();
|
||||
String uri = "../../"+MaisDocContentWriter.toSafeUri(rs.getPrimaryTable().getSchema().getName())+"/"+MaisDocContentWriter.toSafeUri(rs.getPrimaryTable().getName())+"/index.html";
|
||||
String cols = rs.getPrimaryColumns().stream().map(v -> v.getName()).collect(Collectors.joining(" - "));
|
||||
writer.printTagStart(Tag.dd);
|
||||
writer.printTagStart(Tag.code);
|
||||
writer.printHref(uri, rs.getPrimaryTable().getName() + "." + cols);
|
||||
writer.printTagEnd(Tag.code);
|
||||
writer.printTagEnd(Tag.dd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writer.printTagEnd(Tag.dl);
|
||||
|
||||
writer.docPageBlockEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc;
|
||||
|
||||
public class DBConstrain {
|
||||
|
||||
private String name;
|
||||
}
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DBIndex {
|
||||
|
||||
private String name = null;
|
||||
private String schema = null;
|
||||
private String catalog = null;
|
||||
private Boolean unique = null;
|
||||
private String indexQualifier = null;
|
||||
private DBIndexType type = null;
|
||||
private List<DBIndexColumn> indexColumns = null;
|
||||
private String sqlScript = null;
|
||||
|
||||
public DBIndex() {
|
||||
indexColumns = new ArrayList<DBIndexColumn>(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
protected void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the schema
|
||||
*/
|
||||
public String getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param schema the schema to set
|
||||
*/
|
||||
protected void setSchema(String schema) {
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unique
|
||||
*/
|
||||
public Boolean getUnique() {
|
||||
return unique;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unique the unique to set
|
||||
*/
|
||||
protected void setUnique(Boolean unique) {
|
||||
this.unique = unique;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the indexQualifier
|
||||
*/
|
||||
public String getIndexQualifier() {
|
||||
return indexQualifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param indexQualifier the indexQualifier to set
|
||||
*/
|
||||
protected void setIndexQualifier(String indexQualifier) {
|
||||
this.indexQualifier = indexQualifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public DBIndexType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
protected void setType(DBIndexType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the catalog
|
||||
*/
|
||||
public String getCatalog() {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param catalog the catalog to set
|
||||
*/
|
||||
protected void setCatalog(String catalog) {
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the indexColumns
|
||||
*/
|
||||
public List<DBIndexColumn> getIndexColumns() {
|
||||
return indexColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param indexColumn the indexColumn to add
|
||||
*/
|
||||
protected void addIndexColumn(DBIndexColumn indexColumn) {
|
||||
this.indexColumns.add(indexColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sqlScript
|
||||
*/
|
||||
public String getSqlScript() {
|
||||
return sqlScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sqlScript the sqlScript to set
|
||||
*/
|
||||
public void setSqlScript(String sqlScript) {
|
||||
this.sqlScript = sqlScript;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc;
|
||||
|
||||
public class DBIndexColumn {
|
||||
|
||||
private String table = null;
|
||||
private String column = null;
|
||||
private Boolean ascending = null;
|
||||
|
||||
/**
|
||||
* @return the table
|
||||
*/
|
||||
public String getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param table the table to set
|
||||
*/
|
||||
public void setTable(String table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the column
|
||||
*/
|
||||
public String getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param column the column to set
|
||||
*/
|
||||
public void setColumn(String column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ascending
|
||||
*/
|
||||
public Boolean getAscending() {
|
||||
return ascending;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ascending the ascending to set
|
||||
*/
|
||||
public void setAscending(Boolean ascending) {
|
||||
this.ascending = ascending;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc;
|
||||
|
||||
import java.sql.DatabaseMetaData;
|
||||
|
||||
public enum DBIndexType {
|
||||
|
||||
STATISTIC,
|
||||
CLUSTERED,
|
||||
HASHED,
|
||||
OTHER;
|
||||
|
||||
public static DBIndexType parseJdbcMetaInfo(short dbType) {
|
||||
if (dbType==DatabaseMetaData.tableIndexClustered) {
|
||||
return CLUSTERED;
|
||||
}
|
||||
if (dbType==DatabaseMetaData.tableIndexHashed) {
|
||||
return HASHED;
|
||||
}
|
||||
if (dbType==DatabaseMetaData.tableIndexOther) {
|
||||
return OTHER;
|
||||
}
|
||||
if (dbType==DatabaseMetaData.tableIndexStatistic) {
|
||||
return STATISTIC;
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown index type: "+dbType);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DBPrimaryKey {
|
||||
|
||||
private String name = null;
|
||||
private String catalog = null;
|
||||
private String schema = null;
|
||||
private String tableName = null;
|
||||
private List<String> columnNames = null;
|
||||
|
||||
public DBPrimaryKey() {
|
||||
columnNames = new ArrayList<String>(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the catalog.
|
||||
*/
|
||||
public String getCatalog() {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param catalog the catalog to set.
|
||||
*/
|
||||
public void setCatalog(String catalog) {
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the schema.
|
||||
*/
|
||||
public String getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param schema the schema to set.
|
||||
*/
|
||||
public void setSchema(String schema) {
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tableName.
|
||||
*/
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tableName the tableName to set.
|
||||
*/
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the columnNames.
|
||||
*/
|
||||
public List<String> getColumnNames() {
|
||||
return columnNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param columnName the columnName to add.
|
||||
*/
|
||||
protected void addColumnName(String columnName) {
|
||||
this.columnNames.add(columnName);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.metamodel.schema.Table;
|
||||
|
||||
public class DBTable {
|
||||
|
||||
private Table table;
|
||||
private DBPrimaryKey primaryKey;
|
||||
private List<DBIndex> indexes;
|
||||
private String sqlScript = null;
|
||||
|
||||
public DBTable() {
|
||||
indexes = new ArrayList<DBIndex>(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the table
|
||||
*/
|
||||
public Table getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param table the table to set
|
||||
*/
|
||||
public void setTable(Table table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the primaryKey
|
||||
*/
|
||||
public DBPrimaryKey getPrimaryKey() {
|
||||
return primaryKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param primaryKey the primaryKey to set
|
||||
*/
|
||||
public void setPrimaryKey(DBPrimaryKey primaryKey) {
|
||||
this.primaryKey = primaryKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the indexes
|
||||
*/
|
||||
public List<DBIndex> getIndexes() {
|
||||
return indexes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index the indexes to add.
|
||||
*/
|
||||
public void addIndex(DBIndex index) {
|
||||
this.indexes.add(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param indexes the indexes to add.
|
||||
*/
|
||||
public void addIndexes(Collection<DBIndex> indexes) {
|
||||
this.indexes.addAll(indexes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index the indexes to remove.
|
||||
*/
|
||||
public void removeIndex(DBIndex index) {
|
||||
this.indexes.remove(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param column the indexes to add.
|
||||
*/
|
||||
public List<DBIndex> getIndexesByColumn(String column) {
|
||||
List<DBIndex> result = new ArrayList<DBIndex>(3);
|
||||
for (DBIndex index:indexes) {
|
||||
for (DBIndexColumn col:index.getIndexColumns()) {
|
||||
if (col.getColumn().equals(column)) {
|
||||
result.add(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sqlScript
|
||||
*/
|
||||
public String getSqlScript() {
|
||||
return sqlScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sqlScript the sqlScript to set
|
||||
*/
|
||||
public void setSqlScript(String sqlScript) {
|
||||
this.sqlScript = sqlScript;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.eobjects.metamodel.doc.jdbc.db.DBType;
|
||||
import org.eobjects.metamodel.doc.jdbc.db.DBTypeFactory;
|
||||
import org.apache.metamodel.jdbc.JdbcDataContext;
|
||||
import org.apache.metamodel.schema.Table;
|
||||
import org.apache.metamodel.schema.TableType;
|
||||
|
||||
public class DBTableFactory {
|
||||
|
||||
public DBTable loadMetaTable(JdbcDataContext dc,Table table) throws SQLException {
|
||||
Connection conn = dc.getConnection();
|
||||
DatabaseMetaData meta = conn.getMetaData();
|
||||
DBType dbType = DBTypeFactory.getDBType(dc.getConnection());
|
||||
Map<String,String> indexScripts = null;
|
||||
if (dbType!=null) {
|
||||
indexScripts = dbType.getIndexScripts(dc.getConnection(), table.getName());
|
||||
}
|
||||
|
||||
DBTable result = new DBTable();
|
||||
result.setPrimaryKey(fetchPrimaryKeyInfo(meta, dc, table));
|
||||
result.setTable(table);
|
||||
result.addIndexes(fetchIndexInfo(meta, dc, table, indexScripts));
|
||||
|
||||
if (dbType!=null) {
|
||||
if (TableType.VIEW.equals(table.getType())) {
|
||||
result.setSqlScript(dbType.getViewScript(dc.getConnection(), table.getName()));
|
||||
} else {
|
||||
result.setSqlScript(dbType.getTableScript(dc.getConnection(), table));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private DBPrimaryKey fetchPrimaryKeyInfo(DatabaseMetaData meta,JdbcDataContext dc,Table table) throws SQLException {
|
||||
DBPrimaryKey result = new DBPrimaryKey();
|
||||
TreeMap<Short,String> columns = new TreeMap<Short,String>();
|
||||
ResultSet indexInformation = meta.getPrimaryKeys(dc.getCatalogName(), table.getSchema().getName(), table.getName());
|
||||
while (indexInformation.next()) {
|
||||
String dbCatalog = indexInformation.getString("TABLE_CAT");
|
||||
String dbSchema = indexInformation.getString("TABLE_SCHEM");
|
||||
String dbTableName = indexInformation.getString("TABLE_NAME");
|
||||
String dbColumnName = indexInformation.getString("COLUMN_NAME");
|
||||
short dbKeySeq = indexInformation.getShort("KEY_SEQ");
|
||||
String dbPkName = indexInformation.getString("PK_NAME");
|
||||
|
||||
result.setCatalog(dbCatalog);
|
||||
result.setName(dbPkName);
|
||||
result.setSchema(dbSchema);
|
||||
result.setTableName(dbTableName);
|
||||
columns.put(dbKeySeq, dbColumnName);
|
||||
}
|
||||
if (result.getName()==null) {
|
||||
return null; // no PK on table !
|
||||
}
|
||||
result.getColumnNames().addAll(columns.values());
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<DBIndex> fetchIndexInfo(DatabaseMetaData meta,JdbcDataContext dc,Table table, Map<String,String> indexScripts) throws SQLException {
|
||||
DBIndex index = new DBIndex();
|
||||
List<DBIndex> result = new ArrayList<DBIndex>();
|
||||
ResultSet indexInformation = meta.getIndexInfo(dc.getCatalogName(), table.getSchema().getName(), table.getName(), false, false);
|
||||
while (indexInformation.next()) {
|
||||
String dbCatalog = indexInformation.getString("TABLE_CAT");
|
||||
String dbSchema = indexInformation.getString("TABLE_SCHEM");
|
||||
String dbTableName = indexInformation.getString("TABLE_NAME");
|
||||
boolean dbNoneUnique = indexInformation.getBoolean("NON_UNIQUE");
|
||||
String dbIndexQualifier = indexInformation.getString("INDEX_QUALIFIER");
|
||||
String dbIndexName = indexInformation.getString("INDEX_NAME");
|
||||
short indexType = indexInformation.getShort("TYPE");
|
||||
// short dbOrdinalPosition = indexInformation.getShort("ORDINAL_POSITION");
|
||||
String dbColumnName = indexInformation.getString("COLUMN_NAME");
|
||||
String dbAscOrDesc = indexInformation.getString("ASC_OR_DESC");
|
||||
// int dbCardinality = indexInformation.getInt("CARDINALITY");
|
||||
// int dbPages = indexInformation.getInt("PAGES");
|
||||
// String dbFilterCondition = indexInformation.getString("FILTER_CONDITION");
|
||||
|
||||
if (!dbIndexName.equals(index.getName())) {
|
||||
index = new DBIndex();
|
||||
result.add(index);
|
||||
|
||||
if (indexScripts!=null) {
|
||||
String indexScript = indexScripts.get(dbIndexName);
|
||||
index.setSqlScript(indexScript);
|
||||
}
|
||||
}
|
||||
index.setCatalog(dbCatalog);
|
||||
index.setIndexQualifier(dbIndexQualifier);
|
||||
index.setName(dbIndexName);
|
||||
index.setSchema(dbSchema);
|
||||
index.setType(DBIndexType.parseJdbcMetaInfo(indexType));
|
||||
index.setUnique(false==dbNoneUnique);
|
||||
|
||||
DBIndexColumn col = new DBIndexColumn();
|
||||
col.setTable(dbTableName);
|
||||
col.setColumn(dbColumnName);
|
||||
col.setAscending("A".equalsIgnoreCase(dbAscOrDesc));
|
||||
index.addIndexColumn(col);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc.db;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.metamodel.schema.Table;
|
||||
|
||||
public interface DBType {
|
||||
|
||||
String getDatabaseProductName();
|
||||
|
||||
Map<String,String> getIndexScripts(Connection conn,String table) throws SQLException;
|
||||
|
||||
String getViewScript(Connection conn,String viewName) throws SQLException;
|
||||
|
||||
String getTableScript(Connection conn,Table table) throws SQLException;
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc.db;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DBTypeFactory {
|
||||
|
||||
static private List<DBType> types = new ArrayList<DBType>(5);
|
||||
|
||||
static {
|
||||
types.add(new PostgresqlDBType());
|
||||
}
|
||||
|
||||
static public final DBType getDBType(Connection conn) throws SQLException {
|
||||
if (conn==null) {
|
||||
throw new NullPointerException("Can't resolve db on null connection.");
|
||||
}
|
||||
String jdbcProductName = conn.getMetaData().getDatabaseProductName();
|
||||
for (DBType type:types) {
|
||||
if (jdbcProductName.equalsIgnoreCase(type.getDatabaseProductName())) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc.db;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.metamodel.schema.Column;
|
||||
import org.apache.metamodel.schema.Table;
|
||||
|
||||
public class DBTypeTableScripter {
|
||||
|
||||
|
||||
public String createTableScript(Connection conn,Table table) {
|
||||
StringBuilder buf = new StringBuilder(100);
|
||||
buf.append("CREATE TABLE (\n");
|
||||
List<Column> cols = table.getColumns();
|
||||
for (int i=0;i<cols.size();i++) {
|
||||
Column col = cols.get(i);
|
||||
buf.append("\t");
|
||||
buf.append(col.getName());
|
||||
buf.append(" ");
|
||||
buf.append(col.getNativeType());
|
||||
if (col.getNativeType().contains("char")) {
|
||||
buf.append("(");
|
||||
buf.append(col.getColumnSize());
|
||||
buf.append(")");
|
||||
}
|
||||
if (!col.isNullable()) {
|
||||
buf.append(" NOT NULL");
|
||||
}
|
||||
//if (i<cols.length-1) {
|
||||
// buf.append(",");
|
||||
//}
|
||||
buf.append("\n");
|
||||
}
|
||||
|
||||
buf.append("\tCONSTRAINT "+table.getName()+"_pkey_todo PRIMARY KEY (");
|
||||
List<Column> pkeys = table.getPrimaryKeys();
|
||||
for (int i=0;i<pkeys.size();i++) {
|
||||
Column col = pkeys.get(i);
|
||||
buf.append(col.getName());
|
||||
if (i<pkeys.size()-1) {
|
||||
buf.append(",");
|
||||
}
|
||||
}
|
||||
buf.append(")\n");
|
||||
|
||||
buf.append(")\n");
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc.db;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.metamodel.schema.Table;
|
||||
|
||||
public class PostgresqlDBType implements DBType {
|
||||
|
||||
public String getDatabaseProductName() {
|
||||
return "postgresql";
|
||||
}
|
||||
|
||||
public Map<String,String> getIndexScripts(Connection conn,String table) throws SQLException {
|
||||
Map<String,String> result = new HashMap<String,String>();
|
||||
|
||||
Statement s = conn.createStatement();
|
||||
s.execute("select indexname,indexdef from pg_indexes where schemaname != 'pg_catalog' and schemaname != 'information_schema' and tablename= '"+table+"'");
|
||||
ResultSet rs = s.getResultSet();
|
||||
while (rs.next()) {
|
||||
result.put(rs.getString(1), rs.getString(2));
|
||||
}
|
||||
rs.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getViewScript(Connection conn,String viewName) throws SQLException {
|
||||
String result = null;
|
||||
Statement s = conn.createStatement();
|
||||
s.execute("select viewname,definition from pg_views where schemaname != 'pg_catalog' and schemaname != 'information_schema' and viewname= '"+viewName+"'");
|
||||
ResultSet rs = s.getResultSet();
|
||||
if (rs.next()) {
|
||||
result = rs.getString(2);
|
||||
}
|
||||
rs.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getTableScript(Connection conn,Table table) throws SQLException {
|
||||
return new DBTypeTableScripter().createTableScript(conn, table);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc.db;
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc.jdbc;
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright ©Δ∞ 仙上主天
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
|
||||
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
|
||||
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
|
||||
* even on air gaped systems, all information in the universe is owned by the pi creator.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.eobjects.metamodel.doc;
|
||||
Loading…
Add table
Add a link
Reference in a new issue