You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by ol...@apache.org on 2012/02/16 14:29:08 UTC
svn commit: r1244973 - in
/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba:
JdbcAdapter.java ingres/IngresAdapter.java
Author: oltka
Date: Thu Feb 16 13:29:08 2012
New Revision: 1244973
URL: http://svn.apache.org/viewvc?rev=1244973&view=rev
Log:
CAY-1666 remove duplicated code from ingres adapter
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java?rev=1244973&r1=1244972&r2=1244973&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java Thu Feb 16 13:29:08 2012
@@ -283,13 +283,7 @@ public class JdbcAdapter implements DbAd
* <code>ent</code> parameter.
*/
public String createTable(DbEntity entity) {
- boolean status;
- if (entity.getDataMap() != null && entity.getDataMap().isQuotingSQLIdentifiers()) {
- status = true;
- }
- else {
- status = false;
- }
+ boolean status = (entity.getDataMap() != null && entity.getDataMap().isQuotingSQLIdentifiers());
QuotingStrategy context = getQuotingStrategy(status);
StringBuffer sqlBuffer = new StringBuffer();
sqlBuffer.append("CREATE TABLE ");
@@ -333,13 +327,7 @@ public class JdbcAdapter implements DbAd
* @since 1.2
*/
protected void createTableAppendPKClause(StringBuffer sqlBuffer, DbEntity entity) {
- boolean status;
- if (entity.getDataMap() != null && entity.getDataMap().isQuotingSQLIdentifiers()) {
- status = true;
- }
- else {
- status = false;
- }
+ boolean status = (entity.getDataMap() != null && entity.getDataMap().isQuotingSQLIdentifiers());
QuotingStrategy context = getQuotingStrategy(status);
Iterator<DbAttribute> pkit = entity.getPrimaryKeys().iterator();
if (pkit.hasNext()) {
@@ -365,14 +353,8 @@ public class JdbcAdapter implements DbAd
* @since 1.2
*/
public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) {
- boolean status;
- if ((column.getEntity().getDataMap() != null)
- && column.getEntity().getDataMap().isQuotingSQLIdentifiers()) {
- status = true;
- }
- else {
- status = false;
- }
+ boolean status = ((column.getEntity().getDataMap() != null)
+ && column.getEntity().getDataMap().isQuotingSQLIdentifiers());
QuotingStrategy context = getQuotingStrategy(status);
String[] types = externalTypesForJdbcType(column.getType());
if (types == null || types.length == 0) {
@@ -423,13 +405,7 @@ public class JdbcAdapter implements DbAd
* @since 1.1
*/
public String createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns) {
- boolean status;
- if (source.getDataMap() != null && source.getDataMap().isQuotingSQLIdentifiers()) {
- status = true;
- }
- else {
- status = false;
- }
+ boolean status = (source.getDataMap() != null && source.getDataMap().isQuotingSQLIdentifiers());
QuotingStrategy context = getQuotingStrategy(status);
if (columns == null || columns.isEmpty()) {
@@ -465,13 +441,7 @@ public class JdbcAdapter implements DbAd
public String createFkConstraint(DbRelationship rel) {
DbEntity source = (DbEntity) rel.getSourceEntity();
- boolean status;
- if (source.getDataMap() != null && source.getDataMap().isQuotingSQLIdentifiers()) {
- status = true;
- }
- else {
- status = false;
- }
+ boolean status = (source.getDataMap() != null && source.getDataMap().isQuotingSQLIdentifiers());
QuotingStrategy context = getQuotingStrategy(status);
StringBuilder buf = new StringBuilder();
StringBuilder refBuf = new StringBuilder();
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java?rev=1244973&r1=1244972&r2=1244973&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java Thu Feb 16 13:29:08 2012
@@ -22,7 +22,6 @@ package org.apache.cayenne.dba.ingres;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
-import java.util.Iterator;
import java.util.List;
import org.apache.cayenne.CayenneRuntimeException;
@@ -38,7 +37,6 @@ import org.apache.cayenne.dba.JdbcAdapte
import org.apache.cayenne.dba.PkGenerator;
import org.apache.cayenne.dba.QuotingStrategy;
import org.apache.cayenne.dba.TypesMapping;
-import org.apache.cayenne.dba.sybase.SybaseMergerFactory;
import org.apache.cayenne.di.Inject;
import org.apache.cayenne.map.DbAttribute;
import org.apache.cayenne.map.DbEntity;
@@ -83,103 +81,6 @@ public class IngresAdapter extends JdbcA
.createSQLAction(new IngresActionBuilder(this, node.getEntityResolver()));
}
- /**
- * Returns a SQL string that can be used to create database table corresponding to
- * <code>ent</code> parameter.
- */
- @Override
- public String createTable(DbEntity ent) {
- QuotingStrategy context = getQuotingStrategy(ent.getDataMap().isQuotingSQLIdentifiers());
- StringBuilder buf = new StringBuilder();
- buf.append("CREATE TABLE ");
- buf.append(context.quoteFullyQualifiedName(ent));
- buf.append(" (");
-
- // columns
- Iterator<DbAttribute> it = ent.getAttributes().iterator();
- boolean first = true;
- while (it.hasNext()) {
- if (first)
- first = false;
- else
- buf.append(", ");
-
- DbAttribute at = it.next();
-
- // attribute may not be fully valid, do a simple check
- if (at.getType() == TypesMapping.NOT_DEFINED) {
- throw new CayenneRuntimeException("Undefined type for attribute '"
- + ent.getFullyQualifiedName()
- + "."
- + at.getName()
- + "'.");
- }
-
- String[] types = externalTypesForJdbcType(at.getType());
- if (types == null || types.length == 0) {
- throw new CayenneRuntimeException("Undefined type for attribute '"
- + ent.getFullyQualifiedName()
- + "."
- + at.getName()
- + "': "
- + at.getType());
- }
-
- String type = types[0];
- buf.append(context.quoteString(at.getName())).append(' ').append(type);
-
- // append size and precision (if applicable)
- if (TypesMapping.supportsLength(at.getType())) {
- int len = at.getMaxLength();
- int scale = TypesMapping.isDecimal(at.getType()) ? at.getScale() : -1;
-
- // sanity check
- if (scale > len) {
- scale = -1;
- }
-
- if (len > 0) {
- buf.append('(').append(len);
-
- if (scale >= 0) {
- buf.append(", ").append(scale);
- }
-
- buf.append(')');
- }
- }
-
- // Ingres does not like "null" for non mandatory fields
- if (at.isMandatory()) {
- buf.append(" NOT NULL");
- }
- }
-
- // primary key clause
- Iterator<DbAttribute> pkit = ent.getPrimaryKeys().iterator();
- if (pkit.hasNext()) {
- if (first)
- first = false;
- else
- buf.append(", ");
-
- buf.append("PRIMARY KEY (");
- boolean firstPk = true;
- while (pkit.hasNext()) {
- if (firstPk)
- firstPk = false;
- else
- buf.append(", ");
-
- DbAttribute at = pkit.next();
- buf.append(context.quoteString(at.getName()));
- }
- buf.append(')');
- }
- buf.append(')');
- return buf.toString();
- }
-
@Override
protected void configureExtendedTypes(ExtendedTypeMap map) {
super.configureExtendedTypes(map);
@@ -217,8 +118,51 @@ public class IngresAdapter extends JdbcA
return new IngresMergerFactory();
}
-// @Override
-// public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) {
-// super.createTableAppendColumn(sqlBuffer, column);
-// }
+ @Override
+ public void createTableAppendColumn(StringBuffer buf, DbAttribute at) {
+ boolean status = (at.getEntity().getDataMap() != null) && at.getEntity().getDataMap().isQuotingSQLIdentifiers();
+ QuotingStrategy context = getQuotingStrategy(status);
+ String[] types = externalTypesForJdbcType(at.getType());
+ if (types == null || types.length == 0) {
+ throw new CayenneRuntimeException("Undefined type for attribute '"
+ + ((DbEntity) at.getEntity()).getFullyQualifiedName()
+ + "."
+ + at.getName()
+ + "': "
+ + at.getType());
+ }
+
+ String type = types[0];
+ buf.append(context.quoteString(at.getName())).append(' ').append(type);
+
+ // append size and precision (if applicable)
+ if (TypesMapping.supportsLength(at.getType())) {
+ int len = at.getMaxLength();
+ int scale = TypesMapping.isDecimal(at.getType()) ? at.getScale() : -1;
+
+ // sanity check
+ if (scale > len) {
+ scale = -1;
+ }
+
+ if (len > 0) {
+ buf.append('(').append(len);
+
+ if (scale >= 0) {
+ buf.append(", ").append(scale);
+ }
+
+ buf.append(')');
+ }
+ }
+
+ // Ingres does not like "null" for non mandatory fields
+ if (at.isMandatory()) {
+ buf.append(" NOT NULL");
+ }
+
+// if (at.isGenerated()) {
+// buf.append(" GENERATED ALWAYS AS IDENTITY");
+// }
+ }
}