ongoing work on xml-writer

git-svn-id: https://svn.code.sf.net/p/jailer/code/trunk@370 3dd849cd-670e-4645-a7cd-dd197c8d0e81
This commit is contained in:
rwisser
2008-06-10 14:45:24 +00:00
parent ccdbf058a3
commit 33f72dc0d4
15 changed files with 743 additions and 108 deletions
+1 -1
View File
@@ -5,4 +5,4 @@ JL_ENTITY
JL_DEPENDENCY
JL_TMP
JL_DUAL
JL_CONFIG
1 # tables to be excluded from DB introspection
5 JL_DEPENDENCY
6 JL_TMP
7 JL_DUAL
8 JL_CONFIG
+10
View File
@@ -2,6 +2,7 @@ DROP TABLE JL_ENTITY;
DROP TABLE JL_DEPENDENCY;
DROP TABLE JL_SET;
DROP TABLE JL_GRAPH;
DROP TABLE JL_CONFIG;
CREATE TABLE JL_GRAPH
(
@@ -52,3 +53,12 @@ CREATE TABLE JL_DEPENDENCY
CREATE INDEX jl_dep_from ON JL_DEPENDENCY (r_entitygraph, assoc, {5});
CREATE INDEX jl_dep_to ON JL_DEPENDENCY (r_entitygraph, {6});
CREATE TABLE JL_CONFIG
(
jversion varchar(10) NOT NULL,
jkey varchar(200),
jvalue varchar(500)
);
INSERT INTO JL_CONFIG(jversion, jkey, jvalue) values(''{7}'', ''upk'', ''{0}'');
+41 -3
View File
@@ -17,6 +17,9 @@ package net.sf.jailer;
import java.io.File;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import net.sf.jailer.database.StatementExecutor;
import net.sf.jailer.datamodel.DataModel;
@@ -37,14 +40,16 @@ public class DDLCreator {
DataModel dataModel = new DataModel();
String template = "script/ddl-template.sql";
Object[] arguments = new Object[] {
dataModel.getUniversalPrimaryKey().toSQL(null),
String universalPrimaryKey = dataModel.getUniversalPrimaryKey().toSQL(null);
Object[] arguments = new Object[] {
universalPrimaryKey,
dataModel.getUniversalPrimaryKey().toSQL("PRE_", false),
dataModel.getUniversalPrimaryKey().toSQL("FROM_"),
dataModel.getUniversalPrimaryKey().toSQL("TO_"),
dataModel.getUniversalPrimaryKey().columnList(null),
dataModel.getUniversalPrimaryKey().columnList("FROM_"),
dataModel.getUniversalPrimaryKey().columnList("TO_")
dataModel.getUniversalPrimaryKey().columnList("TO_"),
Jailer.VERSION
};
String ddl = PrintUtil.applyTemplate(template, arguments);
@@ -65,5 +70,38 @@ public class DDLCreator {
return true;
}
/**
* Checks whether working-tables schema is up-to-date.
*
* @return <code>true</code> if working-tables schema is up-to-date
*/
public static boolean isUptodate(String driverClass, String dbUrl, String user, String password) {
try {
if (driverClass != null) {
StatementExecutor statementExecutor = new StatementExecutor(driverClass, dbUrl, user, password);
try {
final boolean[] uptodate = new boolean[] { false };
final DataModel datamodel = new DataModel();
statementExecutor.executeQuery("Select jvalue from JL_CONFIG where jversion='" + Jailer.VERSION + "' and jkey='upk'", new StatementExecutor.ResultSetReader() {
public void readCurrentRow(ResultSet resultSet) throws SQLException {
uptodate[0] = resultSet.getString(1).equals(datamodel.getUniversalPrimaryKey().toSQL(null));
}
public void close() {
}
});
return uptodate[0];
} catch (Exception e) {
return false;
} finally {
statementExecutor.shutDown();
}
}
} catch (Exception e) {
return false;
}
return false;
}
}
+3 -1
View File
@@ -57,6 +57,7 @@ import net.sf.jailer.util.JobManager;
import net.sf.jailer.util.PrintUtil;
import net.sf.jailer.util.SqlScriptExecutor;
import net.sf.jailer.util.SqlUtil;
import net.sf.jailer.xml.XmlExportReader;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
@@ -494,7 +495,8 @@ public class Jailer {
entityGraph.markRoots();
for (Table table: sortedTables) {
ResultSetReader reader = new ExportReader(table, result, CommandLineParser.getInstance().upsertOnly, CommandLineParser.getInstance().numberOfEntities);
ResultSetReader reader = new XmlExportReader(table, result, entityGraph, progress);
_log.info("exporting table " + table.getName());
entityGraph.readMarkedEntities(table, reader);
}
+129 -63
View File
@@ -28,7 +28,9 @@ import java.util.HashMap;
import java.util.List;
import net.sf.jailer.ExplainTool;
import net.sf.jailer.Jailer;
import net.sf.jailer.datamodel.Column;
import net.sf.jailer.datamodel.DataModel;
import net.sf.jailer.datamodel.PrimaryKey;
import net.sf.jailer.util.SqlUtil;
@@ -150,85 +152,104 @@ public class SQLDialect {
*/
public static void guessDialect(PrimaryKey primaryKey,
StatementExecutor statementExecutor) {
log("begin guessing SQL dialect");
statementExecutor.setSilent(true);
String drop = "DROP TABLE JL_TMP";
String create = "CREATE TABLE JL_TMP(c1 INTEGER, c2 INTEGER)";
try {
statementExecutor.execute(drop);
} catch (Exception e) {
_sqllog.info(e.getMessage());
}
try {
statementExecutor.execute(create);
} catch (Exception e) {
_sqllog.info(e.getMessage());
}
try {
statementExecutor.execute("DROP TABLE JL_DUAL");
} catch (Exception e) {
_sqllog.info(e.getMessage());
}
try {
statementExecutor.execute("CREATE TABLE JL_DUAL(D INTEGER)");
} catch (Exception e) {
_sqllog.info(e.getMessage());
String dialectName = readConfigValue("sqldialect", statementExecutor);
SQLDialect dialect = null;
if (dialectName != null) {
for (SQLDialect sqlDialect: sqlDialects) {
if (sqlDialect.name.equals(dialectName)) {
dialect = sqlDialect;
break;
}
}
}
for (SQLDialect sqlDialect: sqlDialects) {
boolean ok = true;
if (dialect != null) {
currentDialect = dialect;
log("SQL dialect is " + dialect.name);
} else {
log("begin guessing SQL dialect");
statementExecutor.setSilent(true);
String drop = "DROP TABLE JL_TMP";
String create = "CREATE TABLE JL_TMP(c1 INTEGER, c2 INTEGER)";
try {
String values = sqlDialect.needsValuesKeywordForDeletes? "values " : "";
statementExecutor.execute("DELETE FROM JL_TMP where (c1, c2) IN (" + values + "(1,2), (3,4))");
statementExecutor.execute(drop);
} catch (Exception e) {
ok = false;
_sqllog.info(e.getMessage());
}
if (!ok) {
continue;
}
boolean multiRow;
try {
statementExecutor.execute("INSERT INTO JL_TMP(c1, c2) values (1,2), (3,4)");
multiRow = true;
statementExecutor.execute(create);
} catch (Exception e) {
multiRow = false;
_sqllog.info(e.getMessage());
}
if (multiRow != sqlDialect.supportsMultiRowInserts) {
ok = false;
}
if (!ok) {
continue;
}
try {
statementExecutor.execute(sqlDialect.upsertMode.testSQL);
statementExecutor.execute("DROP TABLE JL_DUAL");
} catch (Exception e) {
ok = false;
_sqllog.info(e.getMessage());
}
if (!ok) {
continue;
try {
statementExecutor.execute("CREATE TABLE JL_DUAL(D INTEGER)");
} catch (Exception e) {
_sqllog.info(e.getMessage());
}
currentDialect = sqlDialect;
log("SQL dialect is " + sqlDialect.name);
break;
}
try {
statementExecutor.execute("DROP TABLE JL_DUAL");
} catch (Exception e) {
_sqllog.info(e.getMessage());
}
try {
statementExecutor.execute(drop);
} catch (Exception e) {
_sqllog.info(e.getMessage());
}
log("end guessing SQL dialect");
for (SQLDialect sqlDialect: sqlDialects) {
boolean ok = true;
try {
String values = sqlDialect.needsValuesKeywordForDeletes? "values " : "";
statementExecutor.execute("DELETE FROM JL_TMP where (c1, c2) IN (" + values + "(1,2), (3,4))");
} catch (Exception e) {
ok = false;
_sqllog.info(e.getMessage());
}
if (!ok) {
continue;
}
boolean multiRow;
try {
statementExecutor.execute("INSERT INTO JL_TMP(c1, c2) values (1,2), (3,4)");
multiRow = true;
} catch (Exception e) {
multiRow = false;
_sqllog.info(e.getMessage());
}
if (multiRow != sqlDialect.supportsMultiRowInserts) {
ok = false;
}
if (!ok) {
continue;
}
try {
statementExecutor.execute(sqlDialect.upsertMode.testSQL);
} catch (Exception e) {
ok = false;
_sqllog.info(e.getMessage());
}
if (!ok) {
continue;
}
currentDialect = sqlDialect;
setConfigValue("sqldialect", sqlDialect.name, statementExecutor);
log("SQL dialect is " + sqlDialect.name);
break;
}
log("begin guessing dummy-values");
try {
statementExecutor.execute("DROP TABLE JL_DUAL");
} catch (Exception e) {
_sqllog.info(e.getMessage());
}
try {
statementExecutor.execute(drop);
} catch (Exception e) {
_sqllog.info(e.getMessage());
}
log("end guessing SQL dialect");
}
log("begin guessing PK-values");
for (Column column : primaryKey.getColumns()) {
guessDummyValues(column, statementExecutor);
}
@@ -236,7 +257,7 @@ public class SQLDialect {
guessDummyValues(new Column("C", "DATE", 0, -1), statementExecutor);
guessDummyValues(new Column("C", "TIMESTAMP", 0, -1), statementExecutor);
statementExecutor.setSilent(false);
log("end guessing dummy values");
log("end guessing PK-values");
}
/**
@@ -247,6 +268,13 @@ public class SQLDialect {
*/
private static void guessDummyValues(Column column,
StatementExecutor statementExecutor) {
String nullValue = readConfigValue(column.toSQL(null), statementExecutor);
if (nullValue != null) {
column.nullValue = nullValue;
return;
}
Calendar cal = Calendar.getInstance();
cal.set(2000, 0, 30, 9, 59, 30);
cal.set(Calendar.MILLISECOND, 456);
@@ -334,7 +362,8 @@ public class SQLDialect {
}
}
if (column.nullValue != null) {
log("dummy value for " + column + " is " + column.nullValue);
log("PK-value for " + column + " is " + column.nullValue);
setConfigValue(column.toSQL(null), column.nullValue, statementExecutor);
break;
}
}
@@ -366,6 +395,43 @@ public class SQLDialect {
column.nullValue = nv;
}
/**
* Reads value from JL_CONFIG table.
*
* @param key key for value lookup
* @param statementExecutor for executing sql statements
* @return value for given key or <code>null</code> if no value for given key can be found
*/
private static String readConfigValue(String key, StatementExecutor statementExecutor) {
try {
final String[] value = new String[] { null };
statementExecutor.executeQuery("Select jvalue from JL_CONFIG where jversion='" + Jailer.VERSION + "' and jkey='" + key + "'", new StatementExecutor.ResultSetReader() {
public void readCurrentRow(ResultSet resultSet) throws SQLException {
value[0] = resultSet.getString(1);
}
public void close() {
}
});
return value[0];
} catch (Exception e) {
return null;
}
}
/**
* Sets value from JL_CONFIG table.
*
* @param key key for value
* @param value for given key or <code>null</code> if no value for given key can be found
* @param statementExecutor for executing sql statements
*/
private static void setConfigValue(String key, String value, StatementExecutor statementExecutor) {
try {
statementExecutor.executeUpdate("Insert into JL_CONFIG(jversion, jkey, jvalue) values ('" + Jailer.VERSION + "', " + SqlUtil.toSql(key) + ", " + SqlUtil.toSql(value) + ")");
} catch (Exception e) {
}
}
/**
* Logs a message.
*
+8 -1
View File
@@ -382,5 +382,12 @@ public class Association extends ModelElement {
}
return id;
}
/**
* Gets data-model to which this association belongs to.
*/
public DataModel getDataModel() {
return dataModel;
}
}
@@ -83,6 +83,11 @@ public class DataModel {
*/
public static final String EXCLUDE_FROM_DELETION_FILE = "datamodel/exclude-from-deletion.csv";
/**
* Export modus, SQL or XML. (GUI support).
*/
private String exportModus;
/**
* Gets a table by name.
*
@@ -341,4 +346,18 @@ public class DataModel {
}
}
/**
* Gets export modus, SQL or XML. (GUI support).
*/
public String getExportModus() {
return exportModus;
}
/**
* Sets export modus, SQL or XML. (GUI support).
*/
public void setExportModus(String modus) {
exportModus = modus;
}
}
+58 -6
View File
@@ -22,8 +22,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import net.sf.jailer.database.StatementExecutor;
import net.sf.jailer.database.StatementExecutor.ResultSetReader;
import net.sf.jailer.datamodel.Association;
@@ -31,6 +29,9 @@ import net.sf.jailer.datamodel.Column;
import net.sf.jailer.datamodel.PrimaryKey;
import net.sf.jailer.datamodel.Table;
import net.sf.jailer.util.SqlScriptExecutor;
import net.sf.jailer.util.SqlUtil;
import org.apache.log4j.Logger;
/**
* Persistent graph of entities.
@@ -553,21 +554,72 @@ public class EntityGraph {
return 0;
}
/**
* Reads all entities which depends on given entity.
*
* @param table the table from which to read entities
* @param association the dependency
* @param resultSet current row is given entity
* @param reader reads the entities
*/
public void readDependentEntities(Table table, Association association, ResultSet resultSet, ResultSetReader reader, Map<String, Integer> typeCache) throws SQLException {
String select = "Select T.* from " + table.getName() + " T join " + DEPENDENCY + " D on " +
pkEqualsEntityID(table, "T", "D", "TO_") + " and D.TO_TYPE='" + table.getName() + "'" +
" Where " + pkEqualsEntityID(association.source, resultSet, "D", "FROM_", typeCache) +
" and D.FROM_TYPE='" + association.source.getName() + "' and assoc=" + association.reversalAssociation.getId() +
" and D.R_ENTITYGRAPH=" + graphID;
statementExecutor.executeQuery(select, reader);
}
/**
* Gets a SQL comparition expression for comparing rows with given entity.
*
* @param table the table
* @param resultSet
* @return a SQL comparition expression for comparing rows of <code>table</code> with current row of resultSet
*/
private String pkEqualsEntityID(Table table, ResultSet resultSet, String alias, String columnPrefix, Map<String, Integer> typeCache) throws SQLException {
Map<Column, Column> match = universalPrimaryKey.match(table.primaryKey);
StringBuffer sb = new StringBuffer();
for (Column column: universalPrimaryKey.getColumns()) {
if (sb.length() > 0) {
sb.append(" and ");
}
sb.append(alias + "." + columnPrefix + column.name + "=");
Column tableColumn = match.get(column);
if (tableColumn != null) {
sb.append(SqlUtil.toSql(SqlUtil.getObject(resultSet, tableColumn.name, typeCache)));
} else {
sb.append(column.getNullValue());
}
}
return sb.toString();
}
/**
* Gets a SQL comparition expression for comparing rows with entities.
*
* @param table the table
*
* @return a SQL comparision expression for comparing rows of <code>table</code> with entities
* @return a SQL comparition expression for comparing rows of <code>table</code> with entities
*/
private String pkEqualsEntityID(Table table, String tableAlias, String entityAlias) {
return pkEqualsEntityID(table, tableAlias, entityAlias, "");
}
/**
* Gets a SQL comparition expression for comparing rows with entities.
*
* @param table the table
* @return a SQL comparition expression for comparing rows of <code>table</code> with entities
*/
private String pkEqualsEntityID(Table table, String tableAlias, String entityAlias, String columnPrefix) {
Map<Column, Column> match = universalPrimaryKey.match(table.primaryKey);
StringBuffer sb = new StringBuffer();
for (Column column: universalPrimaryKey.getColumns()) {
if (sb.length() > 0) {
sb.append(" and ");
}
sb.append(entityAlias + "." + column.name + "=");
sb.append(entityAlias + "." + columnPrefix + column.name + "=");
Column tableColumn = match.get(column);
if (tableColumn != null) {
sb.append(tableAlias + "." + tableColumn.name);
@@ -594,7 +646,7 @@ public class EntityGraph {
*
* @param table the table
* @param tableAlias the alias for table
* @return columnAliasPrefix optional prefix for column names
* @param columnAliasPrefix optional prefix for column names
*/
private String pkList(Table table, String tableAlias, String columnAliasPrefix) {
Map<Column, Column> match = universalPrimaryKey.match(table.primaryKey);
@@ -17,6 +17,7 @@ package net.sf.jailer.extractionmodel;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.sf.jailer.datamodel.AggregationSchema;
@@ -81,7 +82,7 @@ public class ExtractionModel {
this.dataModel = dataModel;
}
}
/**
* Constructor for empty restriction models.
*
@@ -172,6 +173,13 @@ public class ExtractionModel {
association.setAggregationTagName(tag);
}
}
// read export modus
List<CsvFile.Line> exportModusFile = new CsvFile(new File(fileName), "export modus").getLines();
Iterator<CsvFile.Line> i = exportModusFile.iterator();
if (i.hasNext()) {
dataModel.setExportModus(i.next().cells.get(0));
}
if (embedded) {
break;
@@ -6,6 +6,8 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
</Container>
<Component class="javax.swing.ButtonGroup" name="buttonGroup1">
</Component>
</NonVisualComponents>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
@@ -15,7 +17,7 @@
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,2,-16,0,0,2,127"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,2,-16,0,0,3,-29"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
@@ -51,7 +53,7 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel2">
<Container class="javax.swing.JPanel" name="editorPanel">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
@@ -124,7 +126,7 @@
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="4" gridWidth="2" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
<GridBagConstraints gridX="0" gridY="14" gridWidth="2" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
</Constraint>
</Constraints>
@@ -148,7 +150,7 @@
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="3" gridWidth="2" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="4" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
<GridBagConstraints gridX="0" gridY="13" gridWidth="2" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="4" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
@@ -171,7 +173,66 @@
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="2" insetsLeft="0" insetsBottom="0" insetsRight="2" anchor="13" weightX="0.0" weightY="0.0"/>
<GridBagConstraints gridX="1" gridY="12" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="2" anchor="13" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel4">
<Properties>
<Property name="text" type="java.lang.String" value="As"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="8" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JRadioButton" name="asXml">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="buttonGroup1"/>
</Property>
<Property name="selected" type="boolean" value="true"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
<Property name="text" type="java.lang.String" value="XML"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="onExportModusChanged"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="9" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JRadioButton" name="asSql">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="buttonGroup1"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
<Property name="text" type="java.lang.String" value="SQL"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="asSqlActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="8" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
@@ -260,7 +321,7 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
</Container>
<Container class="javax.swing.JPanel" name="jPanel6">
<Container class="javax.swing.JPanel" name="xmlMappingPanel">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
+105 -23
View File
@@ -146,6 +146,8 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
*/
GraphicalDataModelView graphView;
private boolean exportAsXml = false;
/**
* Creates new form ModelTree.
*
@@ -267,6 +269,15 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
needsSave = saveNeedsSave;
extractionModelFrame.updateTitle(needsSave);
if ("XML".equals(dataModel.getExportModus())) {
exportAsXml = true;
asXml.setSelected(true);
} else {
exportAsXml = false;
asSql.setSelected(true);
}
onExportModusChanged(null);
}
/**
@@ -304,10 +315,11 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
java.awt.GridBagConstraints gridBagConstraints;
jScrollPane2 = new javax.swing.JScrollPane();
buttonGroup1 = new javax.swing.ButtonGroup();
jSplitPane1 = new javax.swing.JSplitPane();
graphContainer = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
editorPanel = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jLabel6 = new javax.swing.JLabel();
subjectTable = new javax.swing.JComboBox();
@@ -317,12 +329,15 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
jLabel8 = new javax.swing.JLabel();
condition = new javax.swing.JTextField();
exportButton = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
asXml = new javax.swing.JRadioButton();
asSql = new javax.swing.JRadioButton();
jPanel4 = new javax.swing.JPanel();
rootTable = new javax.swing.JComboBox();
jScrollPane1 = new javax.swing.JScrollPane();
tree = new javax.swing.JTree();
inspectorHolder = new javax.swing.JPanel();
jPanel6 = new javax.swing.JPanel();
xmlMappingPanel = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
@@ -347,7 +362,7 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
jPanel1.setLayout(new java.awt.GridBagLayout());
jPanel2.setLayout(new java.awt.GridLayout(1, 4));
editorPanel.setLayout(new java.awt.GridLayout(1, 4));
jPanel3.setLayout(new java.awt.GridBagLayout());
@@ -388,7 +403,7 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridy = 14;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
@@ -399,7 +414,7 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
jLabel8.setText("Restrictions");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridy = 13;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0);
@@ -415,12 +430,54 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
exportButton.setText("Export Data");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridy = 12;
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 2);
gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 2);
jPanel3.add(exportButton, gridBagConstraints);
jPanel2.add(jPanel3);
jLabel4.setText("As");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 8;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
jPanel3.add(jLabel4, gridBagConstraints);
buttonGroup1.add(asXml);
asXml.setSelected(true);
asXml.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
asXml.setMargin(new java.awt.Insets(0, 0, 0, 0));
asXml.setText("XML");
asXml.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onExportModusChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 9;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel3.add(asXml, gridBagConstraints);
buttonGroup1.add(asSql);
asSql.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
asSql.setMargin(new java.awt.Insets(0, 0, 0, 0));
asSql.setText("SQL");
asSql.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
asSqlActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 8;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
jPanel3.add(asSql, gridBagConstraints);
editorPanel.add(jPanel3);
jPanel4.setLayout(new java.awt.BorderLayout(0, 4));
@@ -450,23 +507,23 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
jPanel4.add(jScrollPane1, java.awt.BorderLayout.CENTER);
jPanel2.add(jPanel4);
editorPanel.add(jPanel4);
inspectorHolder.setLayout(new java.awt.GridBagLayout());
inspectorHolder.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Restriction on association", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 2, 12)));
inspectorHolder.setMinimumSize(new java.awt.Dimension(100, 400));
jPanel2.add(inspectorHolder);
editorPanel.add(inspectorHolder);
jPanel6.setLayout(new java.awt.GridBagLayout());
xmlMappingPanel.setLayout(new java.awt.GridBagLayout());
jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "XML Mapping", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 2, 12)));
xmlMappingPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "XML Mapping", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 2, 12)));
jLabel1.setText(" Aggregation ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel6.add(jLabel1, gridBagConstraints);
xmlMappingPanel.add(jLabel1, gridBagConstraints);
jLabel2.setText(" Tag ");
gridBagConstraints = new java.awt.GridBagConstraints();
@@ -474,7 +531,7 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
gridBagConstraints.gridy = 5;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
jPanel6.add(jLabel2, gridBagConstraints);
xmlMappingPanel.add(jLabel2, gridBagConstraints);
jLabel3.setText(" Sketch ");
gridBagConstraints = new java.awt.GridBagConstraints();
@@ -482,7 +539,7 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
gridBagConstraints.gridy = 10;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0);
jPanel6.add(jLabel3, gridBagConstraints);
xmlMappingPanel.add(jLabel3, gridBagConstraints);
aggregationCombobox.setModel(getAggregationModel());
aggregationCombobox.addActionListener(new java.awt.event.ActionListener() {
@@ -497,7 +554,7 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
jPanel6.add(aggregationCombobox, gridBagConstraints);
xmlMappingPanel.add(aggregationCombobox, gridBagConstraints);
tagField.setMinimumSize(new java.awt.Dimension(250, 19));
tagField.addActionListener(new java.awt.event.ActionListener() {
@@ -512,7 +569,7 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 4);
jPanel6.add(tagField, gridBagConstraints);
xmlMappingPanel.add(tagField, gridBagConstraints);
xmlSketch.setColumns(10);
xmlSketch.setEditable(false);
@@ -528,7 +585,7 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(4, 20, 0, 4);
jPanel6.add(jScrollPane3, gridBagConstraints);
xmlMappingPanel.add(jScrollPane3, gridBagConstraints);
xmlMappingApplyButton.setText("apply");
xmlMappingApplyButton.addActionListener(new java.awt.event.ActionListener() {
@@ -542,9 +599,9 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
gridBagConstraints.gridy = 12;
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 4);
jPanel6.add(xmlMappingApplyButton, gridBagConstraints);
xmlMappingPanel.add(xmlMappingApplyButton, gridBagConstraints);
jPanel2.add(jPanel6);
editorPanel.add(xmlMappingPanel);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
@@ -552,7 +609,7 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
jPanel1.add(jPanel2, gridBagConstraints);
jPanel1.add(editorPanel, gridBagConstraints);
jSplitPane1.setTopComponent(jPanel1);
@@ -595,6 +652,24 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
}// </editor-fold>//GEN-END:initComponents
private void asSqlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_asSqlActionPerformed
onExportModusChanged(evt);
}//GEN-LAST:event_asSqlActionPerformed
private void onExportModusChanged(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onExportModusChanged
if (asXml.isSelected()) {
exportAsXml = true;
editorPanel.add(xmlMappingPanel);
validate();
dataModel.setExportModus("XML");
} else {
exportAsXml = false;
editorPanel.remove(xmlMappingPanel);
validate();
dataModel.setExportModus("SQL");
}
}//GEN-LAST:event_onExportModusChanged
private void xmlMappingApplyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_xmlMappingApplyButtonActionPerformed
if (currentAssociation != null) {
String tag = tagField.getText().trim();
@@ -1335,6 +1410,9 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
out.println(CsvFile.encodeCell("" + subjectTable.getSelectedItem()) + "; " + CsvFile.encodeCell(condition.getText()) + "; ; " + RestrictionModel.EMBEDDED);
saveRestrictions(out);
saveXmlMapping(out);
out.println();
out.println(CsvFile.BLOCK_INDICATOR + "export modus");
out.println(exportAsXml? "XML" : "SQL");
out.close();
needsSave = false;
extractionModelFrame.updateTitle(needsSave);
@@ -1502,9 +1580,13 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
// Variablendeklaration - nicht modifizieren//GEN-BEGIN:variables
private javax.swing.JComboBox aggregationCombobox;
private javax.swing.JRadioButton asSql;
private javax.swing.JRadioButton asXml;
private javax.swing.JLabel associatedWith;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JTextField condition;
private javax.swing.JLabel dependsOn;
private javax.swing.JPanel editorPanel;
public javax.swing.JButton exportButton;
private javax.swing.JPanel graphContainer;
private javax.swing.JLabel hasDependent;
@@ -1513,14 +1595,13 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
@@ -1533,6 +1614,7 @@ public class ExtractionModelEditor extends javax.swing.JPanel {
private javax.swing.JTextField tagField;
private javax.swing.JTree tree;
private javax.swing.JButton xmlMappingApplyButton;
private javax.swing.JPanel xmlMappingPanel;
private javax.swing.JTextArea xmlSketch;
// Ende der Variablendeklaration//GEN-END:variables
@@ -36,6 +36,7 @@ import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import net.sf.jailer.DDLCreator;
import net.sf.jailer.Jailer;
import net.sf.jailer.database.ExportReader;
import net.sf.jailer.datamodel.DataModel;
@@ -639,7 +640,7 @@ public class ExtractionModelFrame extends javax.swing.JFrame {
dbConnectionDialog.addDbArgs(ddlArgs);
ExportReader.numberOfExportedEntities = 0;
ExportReader.numberOfExportedLOBs = 0;
if (UIUtil.runJailer(this, ddlArgs, true, true, false, true,
if (DDLCreator.isUptodate(ddlArgs.get(1), ddlArgs.get(2), ddlArgs.get(3), ddlArgs.get(4)) || UIUtil.runJailer(this, ddlArgs, true, true, false, true,
"Automatic creation of working-tables failed!\n" +
"Please execute the Jailer-DDL manually (jailer_ddl.sql)\n\n" +
"Continue Data Export?", dbConnectionDialog.getPassword())) {
@@ -18,10 +18,12 @@ package net.sf.jailer.ui.graphical_view;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import net.sf.jailer.datamodel.AggregationSchema;
import net.sf.jailer.datamodel.Association;
import prefuse.Constants;
import prefuse.render.EdgeRenderer;
@@ -136,7 +138,9 @@ public class AssociationRenderer extends EdgeRenderer {
// update the endpoints for the edge shape
// need to bias this by arrow head size
if (type == Constants.EDGE_TYPE_CURVE) {
m_curArrow = null;
if (!"XML".equals(association.getDataModel().getExportModus()) || !isAggregation(association)) {
m_curArrow = null;
}
}
Point2D lineEnd = m_tmpPoints[forward?1:0];
lineEnd.setLocation(0, type == Constants.EDGE_TYPE_CURVE? 0 : -m_arrowHeight);
@@ -213,9 +217,20 @@ public class AssociationRenderer extends EdgeRenderer {
item.setStroke(new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), stroke.getLineJoin(), stroke.getMiterLimit()));
}
}
if ("XML".equals(association.getDataModel().getExportModus())) {
m_arrowHead = updateArrowHead(m_arrowWidth, m_arrowHeight, association, isSelected);
arrowIsPotAggregation = true;
} else {
if (arrowIsPotAggregation) {
m_arrowHead = updateArrowHead(m_arrowWidth, m_arrowHeight);
}
arrowIsPotAggregation = false;
}
render(g, item);
}
private boolean arrowIsPotAggregation = false;
/**
* Gets color for association.
*
@@ -257,5 +272,42 @@ public class AssociationRenderer extends EdgeRenderer {
width,width);
}
}
/**
* Render aggregation symbols.
*/
protected Polygon updateArrowHead(int w, int h, Association association, boolean isSelected) {
if (isAggregation(association)) {
if ( m_arrowHead == null ) {
m_arrowHead = new Polygon();
} else {
m_arrowHead.reset();
}
double ws = 0.9;
double hs = 2.0/3.0;
if (isSelected) {
ws /= 1.3;
hs /= 1.3;
}
m_arrowHead.addPoint(0, 0);
m_arrowHead.addPoint((int) (ws*-w), (int) (hs*(-h)));
m_arrowHead.addPoint( 0, (int) (hs*(-2*h)));
m_arrowHead.addPoint((int) (ws*w), (int) (hs*(-h)));
m_arrowHead.addPoint(0, 0);
return m_arrowHead;
} else {
return updateArrowHead(w, h);
}
}
/**
* Checks whether association must be rendered as aggregation.
*
* @param association the association to check
* @return <code>true</code> if association must be rendered as aggregation
*/
private boolean isAggregation(Association association) {
return association.reversalAssociation.getAggregationSchema() != AggregationSchema.NONE;
}
}
@@ -17,8 +17,10 @@ package net.sf.jailer.ui.graphical_view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -482,11 +484,13 @@ public class GraphicalDataModelView extends JPanel {
display.setForeground(Color.GRAY);
display.setBackground(Color.WHITE);
// now we run our action list
visualization.run("draw");
layout.run();
display.setHighQuality(true);
add(display);
}
+233
View File
@@ -0,0 +1,233 @@
/*
* Copyright 2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.jailer.xml;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.sf.jailer.database.StatementExecutor.ResultSetReader;
import net.sf.jailer.datamodel.AggregationSchema;
import net.sf.jailer.datamodel.Association;
import net.sf.jailer.datamodel.Column;
import net.sf.jailer.datamodel.Table;
import net.sf.jailer.entitygraph.EntityGraph;
import net.sf.jailer.util.SqlUtil;
/**
* A {@link ResultSetReader} that writes the read rows into an XML file.
*
* @author Ralf Wisser
*/
public class XmlExportReader implements ResultSetReader {
/**
* The table to read from.
*/
private final Table table;
/**
* The file to write to.
*/
private final OutputStreamWriter scriptFileWriter;
/**
* Number of columns.
*/
private int columnCount;
/**
* Labels of columns.
*/
private String[] columnLabel = null;
/**
* Lob columns.
*/
private List<String> lobColumns = null;
/**
* Lob columns indexes.
*/
private List<Integer> lobColumnIndexes = null;
/**
* Labels of columns as comma separated list.
*/
private String labelCSL;
/**
* Counts the exported entities. (GUI support)
*/
public static long numberOfExportedEntities;
/**
* Counts the exported LOBs. (GUI support)
*/
public static long numberOfExportedLOBs;
/**
* The entity graph.
*/
private final EntityGraph entityGraph;
/**
* Set of all tables for which entities exist in entityGraph.
*/
private final Set<Table> totalProgress;
/**
* Maps clear text SQL-types to {@link java.sql.Types}.
*/
private Map<Table, Map<String, Integer>> typeCache = new HashMap<Table, Map<String,Integer>>();
/**
* Constructor.
*
* @param table
* the table to read from
* @param scriptFileWriter
* the file to write to
* @param entityGraph the entity graph
* @param totalProgress set of all tables for which entities exist in entityGraph
*/
public XmlExportReader(Table table, OutputStreamWriter scriptFileWriter,
EntityGraph entityGraph, Set<Table> totalProgress) {
this.table = table;
this.scriptFileWriter = scriptFileWriter;
this.entityGraph = entityGraph;
this.totalProgress = totalProgress;
}
/**
* Reads result-set and writes into export-script.
*/
public void readCurrentRow(ResultSet resultSet) throws SQLException {
writeEntity(table, resultSet, new ArrayList<String>());
}
/**
* Writes entity as XML hierarchy.
*
* @param resultSet
* current row contains entity to write out
* @param ancestors
* ancestors of entity to write out
*/
private void writeEntity(Table table, ResultSet resultSet, final List<String> ancestors)
throws SQLException {
StringBuilder sb = new StringBuilder(table.getName() + "(");
boolean f = true;
for (Column pk : table.primaryKey.getColumns()) {
if (!f) {
sb.append(", ");
}
f = false;
sb.append(SqlUtil.toSql(SqlUtil.getObject(resultSet, pk.name,
getTypeCache(table))));
}
sb.append(")");
String primaryKey = sb.toString();
if (ancestors.contains(primaryKey)) {
throw new RuntimeException("cyclic aggregation: " + primaryKey
+ " aggregates itself");
}
ancestors.add(primaryKey);
try {
for (int i = 0; i < ancestors.size(); ++i) {
writeToScriptFile(" ");
}
writeToScriptFile(primaryKey + "\n");
} catch (IOException e) {
throw new RuntimeException(e);
}
for (final Association association: table.associations) {
if (totalProgress.contains(association.destination)) {
ResultSetReader reader = new ResultSetReader() {
public void readCurrentRow(ResultSet resultSet) throws SQLException {
writeEntity(association.destination, resultSet, ancestors);
}
public void close() {
}
};
if (association.getAggregationSchema() != AggregationSchema.NONE) {
entityGraph.readDependentEntities(association.destination, association, resultSet, reader, getTypeCache(association.destination));
}
}
}
// rec call
ancestors.remove(ancestors.size() - 1);
}
/**
* Gets type cache for given table.
*
* @param table the table
* @return type cache for table
*/
private Map<String, Integer> getTypeCache(Table table2) {
Map<String, Integer> cache = typeCache.get(table);
if (cache == null) {
cache = new HashMap<String, Integer>();
typeCache.put(table, cache);
}
return cache;
}
/**
* Checks if columns is part of primary key.
*
* @param column
* the column
* @return <code>true</code> if column is part of primary key
*/
private boolean isPrimaryKeyColumn(String column) {
for (Column c : table.primaryKey.getColumns()) {
if (c.name.equalsIgnoreCase(column)) {
return true;
}
}
return false;
}
/**
* Flushes the export-reader.
*/
public void close() {
}
/**
* Writes into script.
*/
private void writeToScriptFile(String content) throws IOException {
synchronized (scriptFileWriter) {
scriptFileWriter.write(content);
}
}
}