Revision: 4067
Author: [email protected]
Date: Tue Mar 31 21:03:24 2015 UTC
Log: Added a property of quoting column name during 'forward
engineering' ( feature of 'SQL Power Architect' ) using Postgres database.
Related to Bug 3157.
https://code.google.com/p/power-architect/source/detail?r=4067
Modified:
/trunk/src/main/java/ca/sqlpower/architect/ddl/DDLGenerator.java
/trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
/trunk/src/main/java/ca/sqlpower/architect/ddl/HSQLDBDDLGenerator.java
/trunk/src/main/java/ca/sqlpower/architect/ddl/LiquibaseDDLGenerator.java
/trunk/src/main/java/ca/sqlpower/architect/ddl/MySqlDDLGenerator.java
/trunk/src/main/java/ca/sqlpower/architect/ddl/OracleDDLGenerator.java
/trunk/src/main/java/ca/sqlpower/architect/ddl/PostgresDDLGenerator.java
/trunk/src/main/java/ca/sqlpower/architect/ddl/SQLServerDDLGenerator.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectPropertiesDataSourceTypeOptionPanel.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/ExportDDLAction.java
/trunk/src/main/resources/ca/sqlpower/architect/swingui/messages.properties
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/DDLGenerator.java Thu
Nov 25 21:42:55 2010 UTC
+++ /trunk/src/main/java/ca/sqlpower/architect/ddl/DDLGenerator.java Tue
Mar 31 21:03:24 2015 UTC
@@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
+import ca.sqlpower.architect.swingui.ArchitectSwingSession;
import ca.sqlpower.diff.DiffChunk;
import ca.sqlpower.sqlobject.SQLColumn;
import ca.sqlpower.sqlobject.SQLIndex;
@@ -70,13 +71,14 @@
* and transaction start and end statements (if supported by the
target platform).
* This script is appropriate to feed into a target database using a
vendor-supplied
* tool for executing SQL scripts.
+ * @param architectSwingSession
*
* @param tables The collection of tables the generated script should
create.
* @return The String representation of the generated DDL script.
* @throws SQLException If there is a problem getting type info from
the target DB.
* @throws SQLObjectException If there are problems with the Architect
objects.
*/
- public String generateDDLScript(Collection<SQLTable> tables) throws
SQLException, SQLObjectException;
+ public String generateDDLScript(ArchitectSwingSession
architectSwingSession, Collection<SQLTable> tables) throws SQLException,
SQLObjectException;
/**
@@ -351,4 +353,13 @@
*/
public boolean supportsEnumeration();
+
+ /**
+ * @param object; is SQLObject
+ * @return the physical name used for object in a physical database
system.
+ * return physical name with quotes only if databaseType supports
quoting a name.
+ *
+ */
+ public String getPhysicalName(SQLObject object);
+
}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
Thu Nov 25 21:42:55 2010 UTC
+++ /trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
Tue Mar 31 21:03:24 2015 UTC
@@ -37,10 +37,14 @@
import ca.sqlpower.architect.DepthFirstSearch;
import ca.sqlpower.architect.ddl.DDLStatement.StatementType;
import ca.sqlpower.architect.profile.ProfileFunctionDescriptor;
+import ca.sqlpower.architect.swingui.ArchitectSwingSession;
import ca.sqlpower.diff.DiffChunk;
import ca.sqlpower.object.SPResolverRegistry;
import ca.sqlpower.object.SPVariableHelper;
import ca.sqlpower.object.SPVariableResolver;
+import ca.sqlpower.sql.DataSourceCollection;
+import ca.sqlpower.sql.JDBCDataSource;
+import ca.sqlpower.sql.JDBCDataSourceType;
import ca.sqlpower.sqlobject.SQLCheckConstraint;
import ca.sqlpower.sqlobject.SQLCheckConstraintVariableResolver;
import
ca.sqlpower.sqlobject.SQLCheckConstraintVariableResolver.SQLCheckConstraintVariable;
@@ -153,7 +157,8 @@
*/
protected Map<String, ProfileFunctionDescriptor> profileFunctionMap;
-
+ private ArchitectSwingSession session;
+
public GenericDDLGenerator(boolean allowConnection) throws
SQLException {
this.allowConnection = allowConnection;
ddlStatements = new ArrayList<DDLStatement>();
@@ -170,7 +175,8 @@
this(true);
}
- public String generateDDLScript(Collection<SQLTable> tables) throws
SQLException, SQLObjectException {
+ public String generateDDLScript(ArchitectSwingSession
architectSwingSession, Collection<SQLTable> tables) throws SQLException,
SQLObjectException {
+ session = architectSwingSession;
List<DDLStatement> statements = generateDDLStatements(tables);
ddl = new StringBuffer(4000);
@@ -585,7 +591,7 @@
print("COMMENT ON COLUMN ");
print(toQualifiedName(c.getParent()));
print(".");
- print(c.getPhysicalName());
+ print(getPhysicalName(c));
print(" IS '");
print(c.getRemarks().replaceAll("'", "''"));
print("'");
@@ -886,7 +892,7 @@
sb.append("'" + enumeration.getName() + "'");
}
- return "CHECK (" + c.getPhysicalName() + " IN (" +
+ return "CHECK (" + getPhysicalName(c) + " IN (" +
sb.toString() + "))";
}
@@ -1012,7 +1018,7 @@
}
createPhysicalName(topLevelNames, pk);
print("CONSTRAINT ");
- print(pk.getPhysicalName());
+ print(getPhysicalName(pk));
print(" PRIMARY KEY (");
boolean firstCol = true;
@@ -1021,7 +1027,7 @@
if (col.getColumn() == null) {
throw new IllegalStateException("Index column is not
associated with the real column in the table.");
} else {
- print(col.getColumn().getPhysicalName());
+ print(getPhysicalName(col.getColumn()));
}
firstCol = false;
}
@@ -1151,7 +1157,7 @@
public String toQualifiedName(String tname) {
String catalog = getTargetCatalog();
String schema = getTargetSchema();
-
+ tname = getQuotedPhysicalName(tname);
return DDLUtils.toQualifiedName(catalog, schema, tname);
}
@@ -1287,7 +1293,7 @@
}
logger.debug("The logical name field now is: " + so.getName());
- return so.getPhysicalName();
+ return getPhysicalName(so);
}
/**
@@ -1315,7 +1321,7 @@
public void dropPrimaryKey(SQLTable t) throws SQLObjectException {
SQLIndex pk = t.getPrimaryKeyIndex();
print("\nALTER TABLE " + toQualifiedName(t.getName())
- + " DROP CONSTRAINT " + pk.getPhysicalName());
+ + " DROP CONSTRAINT " + getPhysicalName(pk));
endStatement(StatementType.DROP, t);
}
@@ -1401,7 +1407,7 @@
for (SQLIndex.Column c : index.getChildren(SQLIndex.Column.class))
{
if (!first) print(", ");
if (c.getColumn() != null) {
- print(c.getColumn().getPhysicalName());
+ print(getPhysicalName(c.getColumn()));
} else {
print(c.getName());
}
@@ -1444,5 +1450,34 @@
public boolean supportsEnumeration() {
return false;
}
+
+ /**
+ *
+ * @param name; a physical name of SQLObject
+ * @return name with quotes, if database supports quoting name
+ */
+ public String getQuotedPhysicalName(String name) {
+ if (session.getDDLGenerator()!= null &&
session.getDDLGenerator().getClass().getName().equals(PostgresDDLGenerator.class.getName()))
{
+ DataSourceCollection<JDBCDataSource> dataSourceCollection=
session.getDataSources();
+ for (JDBCDataSourceType dsType :
dataSourceCollection.getDataSourceTypes()) {
+ if
(dsType.getDDLGeneratorClass().equals(PostgresDDLGenerator.class.getName()))
{
+ boolean isQuoting = dsType.getSupportsQuotingName();
+ if (isQuoting && (!((name.startsWith("\"")) &&
name.endsWith("\"")))) {
+ name = "\""+name+"\"";
+ }
+ break;
+ }
+ }
+ }
+ return name;
+ }
+
+
+ @Override
+ public String getPhysicalName(SQLObject c) {
+ String name = c.getPhysicalName();
+ name = getQuotedPhysicalName(name);
+ return name;
+ }
}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/HSQLDBDDLGenerator.java
Fri Jul 9 18:47:49 2010 UTC
+++ /trunk/src/main/java/ca/sqlpower/architect/ddl/HSQLDBDDLGenerator.java
Tue Mar 31 21:03:24 2015 UTC
@@ -175,7 +175,7 @@
@Override
public void addComment(SQLTable t, boolean includeColumns) {
if (t.getRemarks() != null && t.getRemarks().trim().length() > 0) {
- print("\n-- Comment for table [" + t.getPhysicalName()
+ "]: ");
+ print("\n-- Comment for table [" + getPhysicalName(t) + "]: ");
print(t.getRemarks().replaceAll(REGEX_CRLF, "\n-- "));
endStatement(StatementType.COMMENT, t);
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/ddl/LiquibaseDDLGenerator.java
Wed Sep 8 22:54:12 2010 UTC
+++
/trunk/src/main/java/ca/sqlpower/architect/ddl/LiquibaseDDLGenerator.java
Tue Mar 31 21:03:24 2015 UTC
@@ -695,7 +695,7 @@
print("<renameTable ");
print(getTableQualifier(oldTable, "oldTableName", "schemaName"));
print(" newTableName=\"");
- print(newTable.getPhysicalName());
+ print(getPhysicalName(newTable));
println("\"/>");
endOfStatement();
endStatement(StatementType.XMLTAG, newTable);
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/MySqlDDLGenerator.java
Thu Nov 25 21:42:55 2010 UTC
+++ /trunk/src/main/java/ca/sqlpower/architect/ddl/MySqlDDLGenerator.java
Tue Mar 31 21:03:24 2015 UTC
@@ -394,7 +394,7 @@
Map<String, SQLObject> cols = new HashMap<String, SQLObject>();
try {
for (SQLColumn col : oldCol.getParent().getColumns()) {
- cols.put(col.getPhysicalName(), col);
+ cols.put(getPhysicalName(col), col);
}
} catch (SQLObjectException e) {
// can't do anything...
@@ -435,7 +435,7 @@
boolean firstCol = true;
for (SQLIndex.Column col : pk.getChildren(SQLIndex.Column.class)) {
if (!firstCol) print(", ");
- print(col.getPhysicalName());
+ print(getPhysicalName(col));
firstCol = false;
}
print(")");
@@ -583,7 +583,7 @@
if (!first)
print(", ");
if (c.getColumn() != null) {
- print(c.getColumn().getPhysicalName());
+ print(getPhysicalName(c.getColumn()));
} else {
print(c.getName());
}
@@ -663,7 +663,7 @@
print("\nALTER TABLE ");
print(toQualifiedName(c.getParent()));
print(" MODIFY COLUMN ");
- print(c.getPhysicalName());
+ print(getPhysicalName(c));
print(" ");
print(c.getTypeName());
print(" COMMENT '");
@@ -690,7 +690,7 @@
print(" FIRST");
} else if (colPosition > 0) {
SQLObject precedingColumn =
c.getParent().getChild(colPosition - 1);
- print(" AFTER " + precedingColumn.getPhysicalName());
+ print(" AFTER " + getPhysicalName(precedingColumn));
} else {
throw new IllegalStateException(
"Column " + c + " is not a child of its parent!" +
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/OracleDDLGenerator.java
Thu Nov 25 21:42:55 2010 UTC
+++ /trunk/src/main/java/ca/sqlpower/architect/ddl/OracleDDLGenerator.java
Tue Mar 31 21:03:24 2015 UTC
@@ -334,7 +334,7 @@
Map<String, SQLObject> colNameMap = new HashMap<String,
SQLObject>();
SQLTable t = c.getParent();
print("\nALTER TABLE ");
- print(toQualifiedName(t.getPhysicalName()));
+ print(toQualifiedName(getPhysicalName(t)));
print(" MODIFY ");
print(columnDefinition(c,colNameMap, alter));
endStatement(StatementType.MODIFY, c);
@@ -391,7 +391,7 @@
boolean first = true;
for (SQLIndex.Column c : index.getChildren(SQLIndex.Column.class))
{
if (!first) print(", ");
- print(c.getColumn().getPhysicalName());
+ print(getPhysicalName(c.getColumn()));
if (!isBitmapIndex) {
print(c.getAscendingOrDescending() == AscendDescend.ASCENDING ? "
ASC" : "");
print(c.getAscendingOrDescending() == AscendDescend.DESCENDING ? "
DESC" : "");
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/ddl/PostgresDDLGenerator.java
Thu Nov 25 21:42:55 2010 UTC
+++
/trunk/src/main/java/ca/sqlpower/architect/ddl/PostgresDDLGenerator.java
Tue Mar 31 21:03:24 2015 UTC
@@ -356,7 +356,7 @@
for (SQLIndex.Column c : index.getChildren(SQLIndex.Column.class))
{
if (!first) print(", ");
if (c.getColumn() != null) {
- print(c.getColumn().getPhysicalName());
+ print(getPhysicalName(c.getColumn()));
} else {
print(c.getName());
}
@@ -404,7 +404,7 @@
for (SQLColumn c : t.getColumns()) {
if (c.isAutoIncrement()) {
SQLSequence seq = new
SQLSequence(toIdentifier(c.getAutoIncrementSequenceName()));
- print("\nALTER SEQUENCE " + toQualifiedName(seq.getName())
+ " OWNED BY " + toQualifiedName(t) + "." + c.getPhysicalName());
+ print("\nALTER SEQUENCE " + toQualifiedName(seq.getName())
+ " OWNED BY " + toQualifiedName(t) + "." + getPhysicalName(c));
endStatement(StatementType.CREATE, seq);
}
}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/ddl/SQLServerDDLGenerator.java
Tue Jul 20 22:43:01 2010 UTC
+++
/trunk/src/main/java/ca/sqlpower/architect/ddl/SQLServerDDLGenerator.java
Tue Mar 31 21:03:24 2015 UTC
@@ -404,7 +404,7 @@
// So we only write a SQL comment with the table's comment here
if (t.getRemarks() != null && t.getRemarks().trim().length() >
0) {
- print("\n-- Comment for table [" + t.getPhysicalName() + "]:
");
+ print("\n-- Comment for table [" + getPhysicalName(t) + "]:
");
print(t.getRemarks().replaceAll(REGEX_CRLF, "\n-- "));
endStatement(StatementType.COMMENT, t);
@@ -486,7 +486,7 @@
for (SQLIndex.Column c : index.getChildren(SQLIndex.Column.class))
{
if (!first) print(", ");
if (c.getColumn() != null) {
- print(c.getColumn().getPhysicalName());
+ print(getPhysicalName(c.getColumn()));
} else {
print(c.getName());
}
@@ -522,7 +522,7 @@
public void dropPrimaryKey(SQLTable t) {
SQLIndex pk = t.getPrimaryKeyIndex();
print("\nALTER TABLE " + toQualifiedName(t.getName())
- + " DROP " + pk.getPhysicalName());
+ + " DROP " + getPhysicalName(pk));
endStatement(StatementType.DROP, t);
}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectPropertiesDataSourceTypeOptionPanel.java
Sat May 30 18:55:10 2009 UTC
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectPropertiesDataSourceTypeOptionPanel.java
Tue Mar 31 21:03:24 2015 UTC
@@ -23,6 +23,7 @@
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -267,6 +268,7 @@
private final JTextField stringLengthSQLFuncField = new JTextField();
private final JTextField caseWhenNullSQLFuncField = new JTextField();
private final JCheckBox updatableRSField = new JCheckBox("Supports
Updatable Result Sets");
+ private final JCheckBox quotesNameCheckBox = new
JCheckBox(Messages.getString("ArchitectPropertiesDataSourceTypeOptionPanel.quotingNameLabel"));
private final JComboBox ddlGeneratorCombo = new
JComboBox(KnownDDLGenerators.values());
/**
@@ -280,6 +282,8 @@
*/
private DefaultTableModel indexTableModel;
+ private String ddlGeneratorClass;
+
public ArchitectPropertiesDataSourceTypeOptionPanel() {
panel = new JPanel(new BorderLayout());
}
@@ -294,8 +298,23 @@
stringLengthSQLFuncField.setText("");
caseWhenNullSQLFuncField.setText("");
updatableRSField.setSelected(false);
+ quotesNameCheckBox.setVisible(false);
ddlGeneratorCombo.setSelectedItem(KnownDDLGenerators.GENERIC);
-
+ ddlGeneratorClass = dsType.getDDLGeneratorClass();
+ ddlGeneratorCombo.addActionListener( new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ if (ddlGeneratorClass!= null &&
ddlGeneratorClass.equals(PostgresDDLGenerator.class.getName())) {
+ quotesNameCheckBox.setVisible(true);
+ } else {
+ quotesNameCheckBox.setVisible(false);
+ quotesNameCheckBox.setSelected(false);
+ }
+ }
+
+ });
+
currentDSType = dsType;
profileFunctionTableModel = new ProfileFunctionTableModel();
final JTable profileFunctionTable = new
JTable(profileFunctionTableModel);
@@ -333,6 +352,8 @@
}
} else if
(property.equals(JDBCDataSourceType.SUPPORTS_UPDATEABLE_RESULT_SETS)) {
updatableRSField.setSelected(Boolean.parseBoolean(dsType.getProperty(property)));
+ } else if
(property.equals(JDBCDataSourceType.SUPPORTS_QUOTING_NAME)) {
+
quotesNameCheckBox.setSelected(Boolean.parseBoolean(dsType.getProperty(property)));
} else if (property.equals(JDBCDataSourceType.DDL_GENERATOR)) {
ddlGeneratorCombo.setSelectedItem(KnownDDLGenerators.GENERIC);
for (KnownDDLGenerators ddlg :
KnownDDLGenerators.values()) {
@@ -378,9 +399,9 @@
panel.removeAll();
DefaultFormBuilder fb = new DefaultFormBuilder(new
FormLayout("4dlu, pref, 4dlu, pref:grow, 4dlu",
- "pref, 4dlu, pref, 4dlu, pref, 2dlu, pref, 2dlu, pref,
4dlu, fill:min:grow, 2dlu, pref, 4dlu, pref, 2dlu, pref"));
+ "pref, 4dlu, pref, 4dlu, pref, 2dlu, pref, 2dlu, pref,
4dlu, fill:min:grow, 2dlu, pref, 4dlu, pref, 2dlu, pref,2dlu, pref"));
fb.nextColumn();
- fb.append("", updatableRSField);
+ fb.append(updatableRSField, quotesNameCheckBox);
fb.nextLine();
fb.nextLine();
fb.nextColumn();
@@ -425,6 +446,7 @@
currentDSType.putProperty(JDBCDataSourceType.DDL_GENERATOR,
((KnownDDLGenerators)
ddlGeneratorCombo.getSelectedItem()).getDDLClassName());
currentDSType.putProperty(JDBCDataSourceType.SUPPORTS_UPDATEABLE_RESULT_SETS,
String.valueOf(updatableRSField.isSelected()));
+
currentDSType.putProperty(JDBCDataSourceType.SUPPORTS_QUOTING_NAME,
String.valueOf(quotesNameCheckBox.isSelected()));
currentDSType.putProperty(RemoteDatabaseProfileCreator.propName(AverageSQLFunction.class),
averageSQLFunctionField.getText());
currentDSType.putProperty(RemoteDatabaseProfileCreator.propName(StringLengthSQLFunction.class),
stringLengthSQLFuncField.getText());
currentDSType.putProperty(RemoteDatabaseProfileCreator.propName(CaseWhenNullSQLFunction.class),
caseWhenNullSQLFuncField.getText());
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/ExportDDLAction.java
Mon Aug 9 14:51:04 2010 UTC
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/ExportDDLAction.java
Tue Mar 31 21:03:24 2015 UTC
@@ -205,7 +205,7 @@
*/
private void generateAndDisplayDDL(final DDLExportPanel
ddlPanel, DDLGenerator ddlg) throws SQLException,
SQLObjectException {
-
ddlg.generateDDLScript(getSession().getTargetDatabase().getTables());
+ ddlg.generateDDLScript(getSession(),
getSession().getTargetDatabase().getTables());
SQLDatabase ppdb = new SQLDatabase(ddlPanel.getTargetDB());
SQLScriptDialog ssd =
=======================================
---
/trunk/src/main/resources/ca/sqlpower/architect/swingui/messages.properties
Fri Dec 3 22:27:44 2010 UTC
+++
/trunk/src/main/resources/ca/sqlpower/architect/swingui/messages.properties
Tue Mar 31 21:03:24 2015 UTC
@@ -67,6 +67,7 @@
ArchitectSwingSessionImpl.unfinishedTasksRemaining=There are still
unfinished tasks running on this project.\nYou can either wait for them to
finish and try closing again later,\nor force the project to close. Closing
will leave these tasks unfinished.
ArchitectSwingSessionImpl.unsavedChangesDialogTitle=Unsaved Changes
ArchitectSwingSessionImpl.waitOption=Wait
+ArchitectPropertiesDataSourceTypeOptionPanel.quotingNameLabel=Quotes name
ASUtils.couldNotLaunchPowerArchitect=Couldn't launch the SQL Power
Architect.
ASUtils.databaseConnectionDialogTitle=Database Connection: {0}
ASUtils.datasourceOptionsGeneralTab=General
--
---
You received this message because you are subscribed to the Google Groups "Architect Commits" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.