ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject git commit: AMBARI-6202. Change restart_required from BOOLEAN to SMALLINT. (Jonathan Hurley via swagle)
Date Thu, 19 Jun 2014 20:08:55 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 297ccb1b0 -> 09c6d117e


AMBARI-6202. Change restart_required from BOOLEAN to SMALLINT. (Jonathan Hurley via swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/09c6d117
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/09c6d117
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/09c6d117

Branch: refs/heads/trunk
Commit: 09c6d117e4d7eb42aaf8021c08dadeca2b257309
Parents: 297ccb1
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Thu Jun 19 13:09:35 2014 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Thu Jun 19 13:09:35 2014 -0700

----------------------------------------------------------------------
 .../apache/ambari/server/orm/DBAccessor.java    | 34 ++++++++-
 .../ambari/server/orm/DBAccessorImpl.java       | 68 +++++++++++++-----
 .../HostComponentDesiredStateEntity.java        | 21 ++++--
 .../server/orm/entities/ViewInstanceEntity.java | 31 ++++----
 .../server/orm/helpers/dbms/DbmsHelper.java     | 19 ++++-
 .../server/orm/helpers/dbms/DerbyHelper.java    |  9 +++
 .../orm/helpers/dbms/GenericDbmsHelper.java     | 24 +++++--
 .../server/orm/helpers/dbms/MySqlHelper.java    |  9 +++
 .../server/orm/helpers/dbms/OracleHelper.java   |  9 +++
 .../server/orm/helpers/dbms/PostgresHelper.java |  9 +++
 .../server/upgrade/UpgradeCatalog160.java       | 12 ++--
 .../server/upgrade/UpgradeCatalog161.java       | 52 ++++++++++----
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |  2 +-
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  2 +-
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |  2 +-
 .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql     |  2 +-
 .../ambari/server/orm/DBAccessorImplTest.java   | 76 +++++++++++++++-----
 .../server/upgrade/UpgradeCatalog160Test.java   | 47 +-----------
 .../server/upgrade/UpgradeCatalog161Test.java   | 49 ++++++++-----
 19 files changed, 324 insertions(+), 153 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
index 080753e..d60baf6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
@@ -17,14 +17,13 @@
  */
 package org.apache.ambari.server.orm;
 
-import org.eclipse.persistence.sessions.DatabaseSession;
-
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.List;
 
+import org.eclipse.persistence.sessions.DatabaseSession;
+
 /**
  * Interface for schema manipulation
  * Note: IF NOT EXISTS is default for all supported DDL statements
@@ -287,6 +286,35 @@ public interface DBAccessor {
   public DatabaseSession getNewDatabaseSession();
 
   /**
+   * Gets the column's SQL type
+   * 
+   * @param tableName
+   *          the name of the table (not {@code null}).
+   * @param columnName
+   *          the name of the column to retrieve type for (not {@code null}).
+   * @return the integer representation of the column type from {@link Types}.
+   * @throws SQLException
+   * @see {@link Types}
+   */
+  public int getColumnType(String tableName, String columnName)
+      throws SQLException;
+
+  /**
+   * Sets the specified column to either allow or prohibit {@code NULL}.
+   * 
+   * @param tableName
+   *          the name of the table (not {@code null}).
+   * @param columnName
+   *          the name of the column to alter (not {@code null}).
+   * @param nullable
+   *          {@code true} to indicate that the column allows {@code NULL}
+   *          values, {@code false} otherwise.
+   * @throws SQLException
+   */
+  public void setNullable(String tableName, String columnName, boolean nullable)
+      throws SQLException;
+
+  /**
    * Capture column type
    */
   public class DBColumnInfo {

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
index b39008e..b1fc234 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
@@ -17,21 +17,6 @@
  */
 package org.apache.ambari.server.orm;
 
-import com.google.inject.Inject;
-import org.apache.ambari.server.configuration.Configuration;
-import org.apache.ambari.server.orm.helpers.ScriptRunner;
-import org.apache.ambari.server.orm.helpers.dbms.*;
-import org.apache.commons.lang.StringUtils;
-import org.eclipse.persistence.internal.helper.DBPlatformHelper;
-import org.eclipse.persistence.internal.sessions.DatabaseSessionImpl;
-import org.eclipse.persistence.logging.AbstractSessionLog;
-import org.eclipse.persistence.logging.SessionLogEntry;
-import org.eclipse.persistence.platform.database.*;
-import org.eclipse.persistence.sessions.DatabaseLogin;
-import org.eclipse.persistence.sessions.DatabaseSession;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.io.BufferedReader;
 import java.io.FileReader;
 import java.io.IOException;
@@ -39,13 +24,38 @@ import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.orm.helpers.ScriptRunner;
+import org.apache.ambari.server.orm.helpers.dbms.DbmsHelper;
+import org.apache.ambari.server.orm.helpers.dbms.DerbyHelper;
+import org.apache.ambari.server.orm.helpers.dbms.GenericDbmsHelper;
+import org.apache.ambari.server.orm.helpers.dbms.MySqlHelper;
+import org.apache.ambari.server.orm.helpers.dbms.OracleHelper;
+import org.apache.ambari.server.orm.helpers.dbms.PostgresHelper;
+import org.apache.commons.lang.StringUtils;
+import org.eclipse.persistence.internal.helper.DBPlatformHelper;
+import org.eclipse.persistence.internal.sessions.DatabaseSessionImpl;
+import org.eclipse.persistence.logging.AbstractSessionLog;
+import org.eclipse.persistence.logging.SessionLogEntry;
+import org.eclipse.persistence.platform.database.DatabasePlatform;
+import org.eclipse.persistence.platform.database.DerbyPlatform;
+import org.eclipse.persistence.platform.database.MySQLPlatform;
+import org.eclipse.persistence.platform.database.OraclePlatform;
+import org.eclipse.persistence.platform.database.PostgreSQLPlatform;
+import org.eclipse.persistence.sessions.DatabaseLogin;
+import org.eclipse.persistence.sessions.DatabaseSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+
 public class DBAccessorImpl implements DBAccessor {
   private static final Logger LOG = LoggerFactory.getLogger(DBAccessorImpl.class);
   private final DatabasePlatform databasePlatform;
@@ -534,4 +544,30 @@ public class DBAccessorImpl implements DBAccessor {
 
     return new DatabaseSessionImpl(login);
   }
+
+  public int getColumnType(String tableName, String columnName)
+      throws SQLException {
+    String query = "SELECT " + columnName + " FROM " + tableName;
+    Statement statement = null;
+
+    try {
+      statement = getConnection().createStatement();
+      ResultSet rs = statement.executeQuery(query);
+
+      ResultSetMetaData rsmd = rs.getMetaData();
+      return rsmd.getColumnType(1);
+    } finally {
+      if (null != statement)
+        statement.close();
+    }
+  }
+
+  @Override
+  public void setNullable(String tableName, String columnName, boolean nullable)
+      throws SQLException {
+    String statement = dbmsHelper.getSetNullableStatement(tableName,
+        columnName, nullable);
+
+    executeQuery(statement);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
index 6fb5021..610f77f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
@@ -17,14 +17,23 @@
  */
 package org.apache.ambari.server.orm.entities;
 
-import javax.persistence.*;
+import static org.apache.commons.lang.StringUtils.defaultString;
+
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.ManyToOne;
 
 import org.apache.ambari.server.state.HostComponentAdminState;
 import org.apache.ambari.server.state.MaintenanceState;
 import org.apache.ambari.server.state.State;
 
-import static org.apache.commons.lang.StringUtils.defaultString;
-
 @javax.persistence.IdClass(HostComponentDesiredStateEntityPK.class)
 @javax.persistence.Table(name = "hostcomponentdesiredstate")
 @Entity
@@ -76,7 +85,7 @@ public class HostComponentDesiredStateEntity {
 
   @Basic
   @Column(name = "restart_required", insertable = true, updatable = true, nullable = false)
-  private Boolean restartRequired = false;
+  private Integer restartRequired = 0;
 
   public Long getClusterId() {
     return clusterId;
@@ -190,10 +199,10 @@ public class HostComponentDesiredStateEntity {
   }
 
   public boolean isRestartRequired() {
-    return restartRequired;
+    return restartRequired == 0 ? false : true;
   }
 
   public void setRestartRequired(boolean restartRequired) {
-    this.restartRequired = restartRequired;
+    this.restartRequired = (restartRequired == false ? 0 : 1);
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
index 7e3ac08..d7955a3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
@@ -18,15 +18,11 @@
 
 package org.apache.ambari.server.orm.entities;
 
-import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.view.configuration.InstanceConfig;
-import org.apache.ambari.view.ResourceProvider;
-import org.apache.ambari.view.ViewDefinition;
-import org.apache.ambari.view.ViewInstanceDefinition;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContext;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.userdetails.UserDetails;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
@@ -43,11 +39,16 @@ import javax.persistence.Table;
 import javax.persistence.TableGenerator;
 import javax.persistence.Transient;
 import javax.persistence.UniqueConstraint;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.view.configuration.InstanceConfig;
+import org.apache.ambari.view.ResourceProvider;
+import org.apache.ambari.view.ViewDefinition;
+import org.apache.ambari.view.ViewInstanceDefinition;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetails;
 
 /**
  * Represents an instance of a View.
@@ -73,7 +74,7 @@ public class ViewInstanceEntity implements ViewInstanceDefinition {
   public static final String VIEWS_CONTEXT_PATH_PREFIX = "/views/";
 
   @Id
-  @Column(name = "view_instance_id")
+  @Column(name = "view_instance_id", nullable = false)
   @GeneratedValue(strategy = GenerationType.TABLE, generator = "view_instance_id_generator")
   private Long viewInstanceId;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DbmsHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DbmsHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DbmsHelper.java
index 8b56fbe..52eac62 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DbmsHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DbmsHelper.java
@@ -18,10 +18,10 @@
 
 package org.apache.ambari.server.orm.helpers.dbms;
 
-import org.apache.ambari.server.orm.DBAccessor;
-
 import java.util.List;
 
+import org.apache.ambari.server.orm.DBAccessor;
+
 public interface DbmsHelper {
 
   /**
@@ -71,4 +71,19 @@ public interface DbmsHelper {
   String getDropConstraintStatement(String tableName, String constraintName);
 
   String getDropSequenceStatement(String sequenceName);
+
+  /**
+   * Gets the {@code SET NULL} or {@code SET NOT NULL} statement.
+   * 
+   * @param tableName
+   *          the table (not {@code null}).
+   * @param columnName
+   *          the column to alert the nullable state of (not {@code null}).
+   * @param nullable
+   *          {@code true} to indicate that the column allows {@code NULL}
+   *          values, {@code false} otherwise.
+   * @return the statement (never {@code null}).
+   */
+  String getSetNullableStatement(String tableName, String columnName,
+      boolean nullable);
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DerbyHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DerbyHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DerbyHelper.java
index 00d4b86..5f39509 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DerbyHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DerbyHelper.java
@@ -49,4 +49,13 @@ public class DerbyHelper extends GenericDbmsHelper {
 
     return builder;
   }
+
+  @Override
+  public StringBuilder writeSetNullableString(StringBuilder builder,
+      String tableName, String columnName, boolean nullable) {
+    builder.append(" ALTER COLUMN ").append(columnName);
+    String nullStatement = nullable ? " NULL" : " NOT NULL";
+    builder.append(nullStatement);
+    return builder;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
index a5d76ed..a273265 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
@@ -18,6 +18,11 @@
 
 package org.apache.ambari.server.orm.helpers.dbms;
 
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.List;
+
 import org.apache.ambari.server.orm.DBAccessor;
 import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition;
 import org.eclipse.persistence.internal.databaseaccess.Platform;
@@ -27,11 +32,6 @@ import org.eclipse.persistence.tools.schemaframework.FieldDefinition;
 import org.eclipse.persistence.tools.schemaframework.ForeignKeyConstraint;
 import org.eclipse.persistence.tools.schemaframework.TableDefinition;
 
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.List;
-
 public class GenericDbmsHelper implements DbmsHelper {
   protected final DatabasePlatform databasePlatform;
 
@@ -65,7 +65,15 @@ public class GenericDbmsHelper implements DbmsHelper {
     writeAlterTableClause(stringBuilder, tableName);
     writeColumnModifyString(stringBuilder, columnInfo);
 
+    return stringBuilder.toString();
+  }
 
+  @Override
+  public String getSetNullableStatement(String tableName, String columnName,
+      boolean nullable) {
+    StringBuilder stringBuilder = new StringBuilder();
+    writeAlterTableClause(stringBuilder, tableName);
+    writeSetNullableString(stringBuilder, tableName, columnName, nullable);
     return stringBuilder.toString();
   }
 
@@ -106,6 +114,12 @@ public class GenericDbmsHelper implements DbmsHelper {
     return builder;
   }
 
+  public StringBuilder writeSetNullableString(StringBuilder builder,
+      String tableName, String columnName, boolean nullable) {
+    throw new UnsupportedOperationException(
+        "Column nullable modification not supported for generic DB");
+  }
+
   /**
    * get create table statement
    * @param tableName

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
index efed292..841a854 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
@@ -51,4 +51,13 @@ public class MySqlHelper extends GenericDbmsHelper {
     writeColumnType(builder, columnInfo);
     return builder;
   }
+
+  @Override
+  public StringBuilder writeSetNullableString(StringBuilder builder,
+      String tableName, String columnName, boolean nullable) {
+    builder.append(" MODIFY ").append(columnName);
+    String nullStatement = nullable ? " NULL" : " NOT NULL";
+    builder.append(nullStatement);
+    return builder;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/OracleHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/OracleHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/OracleHelper.java
index aebfb62..4da8e8f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/OracleHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/OracleHelper.java
@@ -43,4 +43,13 @@ public class OracleHelper extends GenericDbmsHelper {
     writeColumnType(builder, columnInfo);
     return builder;
   }
+
+  @Override
+  public StringBuilder writeSetNullableString(StringBuilder builder,
+      String tableName, String columnName, boolean nullable) {
+    builder.append(" MODIFY ").append(columnName);
+    String nullStatement = nullable ? " NULL" : " NOT NULL";
+    builder.append(nullStatement);
+    return builder;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/PostgresHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/PostgresHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/PostgresHelper.java
index 38e837e..c3ad9c5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/PostgresHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/PostgresHelper.java
@@ -43,4 +43,13 @@ public class PostgresHelper extends GenericDbmsHelper {
     writeColumnType(builder, columnInfo);
     return builder;
   }
+
+  @Override
+  public StringBuilder writeSetNullableString(StringBuilder builder,
+      String tableName, String columnName, boolean nullable) {
+    builder.append(" ALTER COLUMN ").append(columnName);
+    String nullStatement = nullable ? " SET NULL" : " SET NOT NULL";
+    builder.append(nullStatement);
+    return builder;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog160.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog160.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog160.java
index c3f083a..c359afa 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog160.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog160.java
@@ -80,14 +80,10 @@ public class UpgradeCatalog160 extends AbstractUpgradeCatalog {
     //=========================================================================
     // Add columns
 
-    // restart_required is a boolean, but most DBs use 0/1 in a SMALLINT
+    // treat restart_required as an integer to maintain consistency with other
+    // tables that have booleans
     DBAccessor.DBColumnInfo restartRequiredColumn = new DBAccessor.DBColumnInfo(
-        "restart_required", Boolean.class, 1, 0, false);
-
-    // only postgres supports boolean type, so assign it here
-    if (Configuration.POSTGRES_DB_NAME.equals(getDbType())) {
-      restartRequiredColumn.setDefaultValue(Boolean.FALSE);
-    }
+        "restart_required", Integer.class, 1, 0, false);
 
     dbAccessor.addColumn("hostcomponentdesiredstate", restartRequiredColumn);
 
@@ -95,9 +91,9 @@ public class UpgradeCatalog160 extends AbstractUpgradeCatalog {
     // Add constraints
     dbAccessor.addFKConstraint("hostgroup_configuration", "FK_hg_config_blueprint_name",
       new String[] {"blueprint_name", "hostgroup_name"}, "hostgroup", new String[] {"blueprint_name", "name"}, true);
+
     dbAccessor.addFKConstraint("viewentity", "FK_viewentity_view_name",
         new String[]{"view_name", "view_instance_name"}, "viewinstance", new String[]{"view_name", "name"}, true);
-
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
index a038194..b6898e6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
@@ -20,6 +20,7 @@ package org.apache.ambari.server.upgrade;
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Types;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -67,6 +68,8 @@ public class UpgradeCatalog161 extends AbstractUpgradeCatalog {
 
   @Override
   protected void executeDDLUpdates() throws AmbariException, SQLException {
+    String dbType = getDbType();
+
     List<DBColumnInfo> columns;
 
     // Operation level
@@ -81,6 +84,30 @@ public class UpgradeCatalog161 extends AbstractUpgradeCatalog {
 
     dbAccessor.createTable("requestoperationlevel", columns, "operation_level_id");
 
+    // 1.6.0 initially shipped with restart_required as a BOOELAN so some
+    // upgrades might be BOOLEAN but most are probably SMALLINT
+    if (Configuration.POSTGRES_DB_NAME.equals(dbType)) {
+      int columnType = dbAccessor.getColumnType("hostcomponentdesiredstate",
+          "restart_required");
+
+      if (columnType == Types.BOOLEAN || columnType == Types.BIT) {
+        dbAccessor.executeQuery(
+            "ALTER TABLE hostcomponentdesiredstate ALTER column restart_required TYPE SMALLINT USING CASE WHEN restart_required=true THEN 1 ELSE 0 END",
+            true);
+      }
+    }
+
+    if (Configuration.ORACLE_DB_NAME.equals(dbType)) {
+      dbAccessor.executeQuery(
+          "ALTER TABLE hostcomponentdesiredstate MODIFY (restart_required DEFAULT 0)",
+          true);
+
+    } else {
+      dbAccessor.executeQuery(
+          "ALTER TABLE hostcomponentdesiredstate ALTER column restart_required SET DEFAULT 0",
+          true);
+    }
+
     //=========================================================================
     // Add columns
     dbAccessor.addColumn("viewmain",
@@ -97,12 +124,12 @@ public class UpgradeCatalog161 extends AbstractUpgradeCatalog {
     dbAccessor.dropConstraint("viewentity", "FK_viewentity_view_name");
 
     //modify primary key of viewinstancedata
-    if (Configuration.ORACLE_DB_NAME.equals(getDbType()) ||
-        Configuration.MYSQL_DB_NAME.equals(getDbType()) ||
-        Configuration.DERBY_DB_NAME.equals(getDbType())) {
+    if (Configuration.ORACLE_DB_NAME.equals(dbType)
+        || Configuration.MYSQL_DB_NAME.equals(dbType)
+        || Configuration.DERBY_DB_NAME.equals(dbType)) {
       dbAccessor.executeQuery("ALTER TABLE viewinstance DROP PRIMARY KEY", true);
       dbAccessor.executeQuery("ALTER TABLE viewinstancedata DROP PRIMARY KEY", true);
-    }else if (Configuration.POSTGRES_DB_NAME.equals(getDbType())) {
+    } else if (Configuration.POSTGRES_DB_NAME.equals(dbType)) {
       dbAccessor.executeQuery("ALTER TABLE viewinstance DROP CONSTRAINT viewinstance_pkey CASCADE", true);
       dbAccessor.executeQuery("ALTER TABLE viewinstancedata DROP CONSTRAINT viewinstancedata_pkey CASCADE", true);
     }
@@ -112,7 +139,7 @@ public class UpgradeCatalog161 extends AbstractUpgradeCatalog {
     dbAccessor.addColumn("viewinstancedata",
       new DBAccessor.DBColumnInfo("view_instance_id", Long.class, null, null, true));
 
-    if (Configuration.ORACLE_DB_NAME.equals(getDbType())) {
+    if (Configuration.ORACLE_DB_NAME.equals(dbType)) {
       //sequence looks to be simpler than rownum
       if (dbAccessor.tableHasData("viewinstancedata")) {
         dbAccessor.executeQuery("CREATE SEQUENCE TEMP_SEQ " +
@@ -125,12 +152,12 @@ public class UpgradeCatalog161 extends AbstractUpgradeCatalog {
         dbAccessor.executeQuery("UPDATE viewinstance SET view_instance_id = TEMP_SEQ.NEXTVAL");
         dbAccessor.dropSequence("TEMP_SEQ");
       }
-    }else if (Configuration.MYSQL_DB_NAME.equals(getDbType())) {
+    } else if (Configuration.MYSQL_DB_NAME.equals(dbType)) {
       if (dbAccessor.tableHasData("viewinstance")) {
         dbAccessor.executeQuery("UPDATE viewinstance " +
             "SET view_instance_id = (SELECT @a := @a + 1 FROM (SELECT @a := 1) s)");
       }
-    }else if (Configuration.POSTGRES_DB_NAME.equals(getDbType())) {
+    } else if (Configuration.POSTGRES_DB_NAME.equals(dbType)) {
       if (dbAccessor.tableHasData("viewinstance")) {
         //window functions like row_number were added in 8.4, workaround for earlier versions (redhat/centos 5)
         dbAccessor.executeQuery("CREATE SEQUENCE temp_seq START WITH 1");
@@ -141,7 +168,7 @@ public class UpgradeCatalog161 extends AbstractUpgradeCatalog {
 
     }
 
-    if (Configuration.DERBY_DB_NAME.equals(getDbType())) {
+    if (Configuration.DERBY_DB_NAME.equals(dbType)) {
       dbAccessor.executeQuery("ALTER TABLE viewinstance ALTER COLUMN view_instance_id DEFAULT 0");
       dbAccessor.executeQuery("ALTER TABLE viewinstance ALTER COLUMN view_instance_id NOT NULL");
       dbAccessor.executeQuery("ALTER TABLE viewinstancedata ALTER COLUMN view_instance_id DEFAULT 0");
@@ -159,13 +186,13 @@ public class UpgradeCatalog161 extends AbstractUpgradeCatalog {
     dbAccessor.addFKConstraint("viewentity", "FK_viewentity_view_name",
         new String[]{"view_name", "view_instance_name"}, "viewinstance", new String[]{"view_name", "name"}, true);
 
-    if (Configuration.POSTGRES_DB_NAME.equals(getDbType())) {
+    if (Configuration.POSTGRES_DB_NAME.equals(dbType)) {
       dbAccessor.executeQuery("UPDATE viewinstancedata AS vid SET view_instance_id = vi.view_instance_id " +
         "FROM viewinstance AS vi WHERE vi.name = vid.view_instance_name AND vi.view_name = vid.view_name");
-    } else if (Configuration.ORACLE_DB_NAME.equals(getDbType())) {
+    } else if (Configuration.ORACLE_DB_NAME.equals(dbType)) {
       dbAccessor.executeQuery("UPDATE viewinstancedata vid SET view_instance_id = (" +
         "SELECT view_instance_id FROM viewinstance vi WHERE vi.name = vid.view_instance_name AND vi.view_name = vid.view_name)");
-    }else if (Configuration.MYSQL_DB_NAME.equals(getDbType())) {
+    } else if (Configuration.MYSQL_DB_NAME.equals(dbType)) {
       dbAccessor.executeQuery("UPDATE viewinstancedata AS vid JOIN viewinstance AS vi " +
         "ON vi.name = vid.view_instance_name AND vi.view_name = vid.view_name " +
         "SET vid.view_instance_id = vi.view_instance_id");
@@ -191,7 +218,8 @@ public class UpgradeCatalog161 extends AbstractUpgradeCatalog {
     }
 
     String valueColumnName = "\"value\"";
-    if (Configuration.ORACLE_DB_NAME.equals(getDbType()) || Configuration.MYSQL_DB_NAME.equals(getDbType())) {
+    if (Configuration.ORACLE_DB_NAME.equals(dbType)
+        || Configuration.MYSQL_DB_NAME.equals(dbType)) {
       valueColumnName = "value";
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index de7c3a6..361b589 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -30,7 +30,7 @@ CREATE TABLE clusters (cluster_id BIGINT NOT NULL, cluster_info VARCHAR(255) NOT
 CREATE TABLE clusterconfig (version_tag VARCHAR(255) NOT NULL, type_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, config_data LONGTEXT NOT NULL, create_timestamp BIGINT NOT NULL, PRIMARY KEY (version_tag, type_name, cluster_id));
 CREATE TABLE clusterservices (service_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, service_enabled INTEGER NOT NULL, PRIMARY KEY (service_name, cluster_id));
 CREATE TABLE clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
-CREATE TABLE hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), maintenance_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE', restart_required TINYINT(1) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), maintenance_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE', restart_required TINYINT(1) NOT NULL DEFAULT 0, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE hosts (host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, cpu_info VARCHAR(255) NOT NULL, discovery_status VARCHAR(2000) NOT NULL, host_attributes LONGTEXT NOT NULL, ipv4 VARCHAR(255), ipv6 VARCHAR(255), last_registration_time BIGINT NOT NULL, os_arch VARCHAR(255) NOT NULL, os_info VARCHAR(1000) NOT NULL, os_type VARCHAR(255) NOT NULL, ph_cpu_count INTEGER, public_host_name VARCHAR(255), rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, PRIMARY KEY (host_name));
 CREATE TABLE hoststate (agent_version VARCHAR(255) NOT NULL, available_mem BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), host_name VARCHAR(255) NOT NULL, time_in_state BIGINT NOT NULL, maintenance_state VARCHAR(512), PRIMARY KEY (host_name));

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index 870d066..c170845 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -20,7 +20,7 @@ CREATE TABLE clusters (cluster_id NUMBER(19) NOT NULL, cluster_info VARCHAR2(255
 CREATE TABLE clusterconfig (version_tag VARCHAR2(255) NOT NULL, type_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, config_data CLOB NOT NULL, create_timestamp NUMBER(19) NOT NULL, PRIMARY KEY (version_tag, type_name, cluster_id));
 CREATE TABLE clusterservices (service_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, service_enabled NUMBER(10) NOT NULL, PRIMARY KEY (service_name, cluster_id));
 CREATE TABLE clusterstate (cluster_id NUMBER(19) NOT NULL, current_cluster_state VARCHAR2(255) NULL, current_stack_version VARCHAR2(255) NULL, PRIMARY KEY (cluster_id));
-CREATE TABLE hostcomponentdesiredstate (cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, desired_stack_version VARCHAR2(255) NULL, desired_state VARCHAR2(255) NOT NULL, host_name VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, admin_state VARCHAR2(32) NULL, maintenance_state VARCHAR2(32) NOT NULL, restart_required NUMBER(1) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE hostcomponentdesiredstate (cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, desired_stack_version VARCHAR2(255) NULL, desired_state VARCHAR2(255) NOT NULL, host_name VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, admin_state VARCHAR2(32) NULL, maintenance_state VARCHAR2(32) NOT NULL, restart_required NUMBER(1) DEFAULT 0 NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE hostcomponentstate (cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, current_stack_version VARCHAR2(255) NOT NULL, current_state VARCHAR2(255) NOT NULL, host_name VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE hosts (host_name VARCHAR2(255) NOT NULL, cpu_count INTEGER NOT NULL, cpu_info VARCHAR2(255) NULL, discovery_status VARCHAR2(2000) NULL, host_attributes CLOB NULL, ipv4 VARCHAR2(255) NULL, ipv6 VARCHAR2(255) NULL, last_registration_time INTEGER NOT NULL, os_arch VARCHAR2(255) NULL, os_info VARCHAR2(1000) NULL, os_type VARCHAR2(255) NULL, ph_cpu_count INTEGER NOT NULL, public_host_name VARCHAR2(255) NULL, rack_info VARCHAR2(255) NOT NULL, total_mem INTEGER NOT NULL, PRIMARY KEY (host_name));
 CREATE TABLE hoststate (agent_version VARCHAR2(255) NULL, available_mem NUMBER(19) NOT NULL, current_state VARCHAR2(255) NOT NULL, health_status VARCHAR2(255) NULL, host_name VARCHAR2(255) NOT NULL, time_in_state NUMBER(19) NOT NULL, maintenance_state VARCHAR2(512), PRIMARY KEY (host_name));

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index 0b8f686..e8082f0 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -27,7 +27,7 @@ CREATE TABLE clusterservices (service_name VARCHAR(255) NOT NULL, cluster_id BIG
 
 CREATE TABLE clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
 
-CREATE TABLE hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), maintenance_state VARCHAR(32) NOT NULL, restart_required BOOLEAN NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), maintenance_state VARCHAR(32) NOT NULL, restart_required SMALLINT NOT NULL DEFAULT 0, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 
 CREATE TABLE hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
index 84215e3..e39a5a8 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
@@ -43,7 +43,7 @@ GRANT ALL PRIVILEGES ON TABLE ambari.clusterservices TO :username;
 CREATE TABLE ambari.clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
 GRANT ALL PRIVILEGES ON TABLE ambari.clusterstate TO :username;
 
-CREATE TABLE ambari.hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), maintenance_state VARCHAR(32) NOT NULL, restart_required BOOLEAN NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE ambari.hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), maintenance_state VARCHAR(32) NOT NULL, restart_required SMALLINT NOT NULL DEFAULT 0, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentdesiredstate TO :username;
 
 CREATE TABLE ambari.hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/test/java/org/apache/ambari/server/orm/DBAccessorImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/DBAccessorImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/DBAccessorImplTest.java
index 6f0cd91..8abadea 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/DBAccessorImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/DBAccessorImplTest.java
@@ -18,33 +18,32 @@
 
 package org.apache.ambari.server.orm;
 
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import junit.framework.Assert;
-import org.eclipse.persistence.sessions.DatabaseSession;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.matchers.JUnitMatchers.containsString;
 
-import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.Types;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import static org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-import static org.junit.matchers.JUnitMatchers.containsString;
+import junit.framework.Assert;
+
+import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
+import org.eclipse.persistence.sessions.DatabaseSession;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
 
 public class DBAccessorImplTest {
   private Injector injector;
@@ -306,4 +305,47 @@ public class DBAccessorImplTest {
 
     databaseSession.logout();
   }
+
+  @Test
+  public void testGetColumnType() throws Exception {
+    String tableName = getFreeTableName();
+    createMyTable(tableName);
+    DBAccessorImpl dbAccessor = injector.getInstance(DBAccessorImpl.class);
+    assertEquals(Types.BIGINT, dbAccessor.getColumnType(tableName, "id"));
+    assertEquals(Types.VARCHAR, dbAccessor.getColumnType(tableName, "name"));
+  }
+
+  @Test
+  public void testSetNullable() throws Exception {
+    String tableName = getFreeTableName();
+    createMyTable(tableName);
+    DBAccessorImpl dbAccessor = injector.getInstance(DBAccessorImpl.class);
+
+    dbAccessor.addColumn(tableName, new DBColumnInfo("isNullable",
+        String.class, 1000, "test", false));
+
+    Statement statement = dbAccessor.getConnection().createStatement();
+    ResultSet resultSet = statement.executeQuery("SELECT isNullable FROM "
+        + tableName);
+    ResultSetMetaData rsmd = resultSet.getMetaData();
+    assertEquals(ResultSetMetaData.columnNullable, rsmd.isNullable(1));
+
+    statement.close();
+
+    dbAccessor.setNullable(tableName, "isNullable", false);
+    statement = dbAccessor.getConnection().createStatement();
+    resultSet = statement.executeQuery("SELECT isNullable FROM " + tableName);
+    rsmd = resultSet.getMetaData();
+    assertEquals(ResultSetMetaData.columnNoNulls, rsmd.isNullable(1));
+
+    statement.close();
+
+    dbAccessor.setNullable(tableName, "isNullable", true);
+    statement = dbAccessor.getConnection().createStatement();
+    resultSet = statement.executeQuery("SELECT isNullable FROM " + tableName);
+    rsmd = resultSet.getMetaData();
+    assertEquals(ResultSetMetaData.columnNullable, rsmd.isNullable(1));
+
+    statement.close();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog160Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog160Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog160Test.java
index f597986..59c73f2 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog160Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog160Test.java
@@ -84,35 +84,6 @@ public class UpgradeCatalog160Test {
     assertRestartRequiredColumn(restartRequiredColumnCapture);
   }
 
-  /**
-   * Tests that Postgres-specific code is executed correctly in the DDL layer.
-   * 
-   * @throws Exception
-   */
-  @Test
-  public void testRestartRequiredPostgresDDL() throws Exception {
-    final DBAccessor dbAccessor = createNiceMock(DBAccessor.class);
-    Configuration configuration = createNiceMock(Configuration.class);
-    Capture<DBAccessor.DBColumnInfo> restartRequiredColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
-
-    expect(configuration.getDatabaseUrl()).andReturn(Configuration.POSTGRES_DB_NAME).anyTimes();
-
-    dbAccessor.addColumn(eq("hostcomponentdesiredstate"),
-        capture(restartRequiredColumnCapture));
-    
-    replay(dbAccessor, configuration);
-    AbstractUpgradeCatalog upgradeCatalog = getUpgradeCatalog(dbAccessor);
-    Class<?> c = AbstractUpgradeCatalog.class;
-    Field f = c.getDeclaredField("configuration");
-    f.setAccessible(true);
-    f.set(upgradeCatalog, configuration);
-
-    upgradeCatalog.executeDDLUpdates();
-    verify(dbAccessor, configuration);
-
-    assertRestartRequiredColumnPostgres(restartRequiredColumnCapture);
-  }
-
   @Test
   public void testExecuteDMLUpdates() throws Exception {
     Configuration configuration = createNiceMock(Configuration.class);
@@ -289,24 +260,8 @@ public class UpgradeCatalog160Test {
     DBAccessor.DBColumnInfo column = restartRequiredColumnCapture.getValue();
     assertEquals("restart_required", column.getName());
     assertEquals(1, (int) column.getLength());
-    assertEquals(Boolean.class, column.getType());
+    assertEquals(Integer.class, column.getType());
     assertEquals(0, column.getDefaultValue());
     assertFalse(column.isNullable());
   }
-
-  /**
-   * Checks that the restart_require column was created correct when using a
-   * Postgres DB.
-   * 
-   * @param restartRequiredColumnCapture
-   */
-  private void assertRestartRequiredColumnPostgres(
-      Capture<DBAccessor.DBColumnInfo> restartRequiredColumnCapture) {
-    DBAccessor.DBColumnInfo column = restartRequiredColumnCapture.getValue();
-    assertEquals("restart_required", column.getName());
-    assertEquals(1, (int) column.getLength());
-    assertEquals(Boolean.class, column.getType());
-    assertEquals(false, column.getDefaultValue());
-    assertFalse(column.isNullable());
-  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/09c6d117/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog161Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog161Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog161Test.java
index 284fd99..f70fcd4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog161Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog161Test.java
@@ -18,11 +18,31 @@
 
 package org.apache.ambari.server.upgrade;
 
-import com.google.inject.Binder;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Module;
-import com.google.inject.Provider;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.lang.reflect.Field;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.TypedQuery;
+
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
@@ -31,19 +51,11 @@ import org.easymock.Capture;
 import org.junit.Assert;
 import org.junit.Test;
 
-import javax.persistence.EntityManager;
-import javax.persistence.EntityTransaction;
-import javax.persistence.TypedQuery;
-import java.lang.reflect.Field;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.assertTrue;
-import static org.easymock.EasyMock.*;
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.Provider;
 
 /**
  * UpgradeCatalog161 unit tests.
@@ -150,7 +162,6 @@ public class UpgradeCatalog161Test {
     Assert.assertEquals("1.6.1", upgradeCatalog.getTargetVersion());
   }
 
-
   private AbstractUpgradeCatalog getUpgradeCatalog(final DBAccessor dbAccessor) {
     Module module = new Module() {
       @Override


Mime
View raw message