当前位置: 首页>>代码示例>>Java>>正文


Java DatabaseException类代码示例

本文整理汇总了Java中liquibase.exception.DatabaseException的典型用法代码示例。如果您正苦于以下问题:Java DatabaseException类的具体用法?Java DatabaseException怎么用?Java DatabaseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DatabaseException类属于liquibase.exception包,在下文中一共展示了DatabaseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tag

import liquibase.exception.DatabaseException; //导入依赖的package包/类
@Override
    public void tag(final String tagString) throws DatabaseException {
        Database database = getDatabase();
        Executor executor = ExecutorService.getInstance().getExecutor(database);
        try {
            int totalRows = ExecutorService.getInstance().getExecutor(database).queryForInt(new SelectFromDatabaseChangeLogStatement(new ColumnConfig().setName("COUNT(*)", true)));
            if (totalRows == 0) {
                ChangeSet emptyChangeSet = new ChangeSet(String.valueOf(new Date().getTime()), "liquibase", false, false, "liquibase-internal", null, null, getDatabase().getObjectQuotingStrategy(), null);
                this.setExecType(emptyChangeSet, ChangeSet.ExecType.EXECUTED);
            }

//            Timestamp lastExecutedDate = (Timestamp) this.getExecutor().queryForObject(createChangeToTagSQL(), Timestamp.class);
            executor.execute(new TagDatabaseStatement(tagString));
            getDatabase().commit();

            if (this.ranChangeSetList != null) {
                ranChangeSetList.get(ranChangeSetList.size() - 1).setTag(tagString);
            }
        } catch (Exception e) {
            throw new DatabaseException(e);
        }
    }
 
开发者ID:eselyavka,项目名称:liquibase-impala,代码行数:23,代码来源:HiveStandardChangeLogHistoryService.java

示例2: connectToDB

import liquibase.exception.DatabaseException; //导入依赖的package包/类
public static void connectToDB() throws Exception {
    if (connection == null) {
        info = new Properties();
        info.load(new FileInputStream("src/test/resources/liquibase.properties"));

        url = info.getProperty("url");
        driver = (Driver) Class.forName(DatabaseFactory.getInstance().findDefaultDriver(url), true,
                Thread.currentThread().getContextClassLoader()).newInstance();

        connection = driver.connect(url, info);

        if (connection == null) {
            throw new DatabaseException("Connection could not be created to " + url + " with driver "
                    + driver.getClass().getName() + ".  Possibly the wrong driver for the given database URL");
        }

        jdbcConnection = new JdbcConnection(connection);
    }
}
 
开发者ID:CDKGlobal,项目名称:liquibase-snowflake,代码行数:20,代码来源:BaseTestCase.java

示例3: update

import liquibase.exception.DatabaseException; //导入依赖的package包/类
@Override
public int update(SqlStatement sql) throws DatabaseException
{
	if (sql instanceof LockDatabaseChangeLogStatement)
	{
		return 1;
	}
	else if (sql instanceof UnlockDatabaseChangeLogStatement)
	{
		return 1;
	}

	suppressSqlStatement(sql);

	return 0;
}
 
开发者ID:Jurrie,项目名称:liquibase-suppress-output,代码行数:17,代码来源:SuppressOutputExecutor.java

示例4: createDatabase

import liquibase.exception.DatabaseException; //导入依赖的package包/类
protected Database createDatabase(Connection c, ResourceAccessor resourceAccessor) throws DatabaseException {

        DatabaseConnection liquibaseConnection = new JdbcConnection(c);
        DatabaseFactory databaseFactory = DatabaseFactory.getInstance();

        // expand factory with our extensions....
        databaseFactory.register(new DerbyDatabase());

        Database database = databaseFactory.findCorrectDatabaseImplementation(liquibaseConnection);
        // set default schema
        String defaultSchema = cli.optionString(LiquibaseModule.DEFAULT_SCHEMA_OPTION);
        if (defaultSchema != null) {
            database.setDefaultSchemaName(defaultSchema);
        }

        return database;
    }
 
开发者ID:bootique,项目名称:bootique-liquibase,代码行数:18,代码来源:LiquibaseRunner.java

示例5: close

import liquibase.exception.DatabaseException; //导入依赖的package包/类
@Override
public void close() throws DatabaseException {

    // copy-paste from AbstractJdbcDatabase plus reflection to deal with private fields...

    ExecutorService.getInstance().clearExecutor(this);
    DatabaseConnection connection = getConnection();
    if (connection != null) {

        Boolean previousAutoCommit = previousAutoCommit();
        if (previousAutoCommit != null) {
            try {
                connection.setAutoCommit(previousAutoCommit);
            } catch (DatabaseException e) {
                LogFactory.getInstance().getLog().warning("Failed to restore the auto commit to " + previousAutoCommit);
                throw e;
            }
        }
        connection.close();
    }
}
 
开发者ID:bootique,项目名称:bootique-liquibase,代码行数:22,代码来源:DerbyDatabase.java

示例6: connectToDB

import liquibase.exception.DatabaseException; //导入依赖的package包/类
public static void connectToDB() throws Exception {
	if ( connection == null ) {
		info = new Properties();
		info.load( new FileInputStream( "src/test/resources/tests.properties" ) );

		url = info.getProperty( "url" );
		driver = (Driver) Class.forName( DatabaseFactory.getInstance().findDefaultDriver( url ), true, Thread.currentThread().getContextClassLoader() ).newInstance();

		connection = driver.connect( url, info );

		if ( connection == null ) {
			throw new DatabaseException( "Connection could not be created to " + url + " with driver " + driver.getClass().getName() + ".  Possibly the wrong driver for the given database URL" );
		}

		jdbcConnection = new JdbcConnection( connection );
	}
}
 
开发者ID:mrswadge,项目名称:liquibase-oracle-preconditions,代码行数:18,代码来源:BaseTestCase.java

示例7: fillForeignKeyInfo

import liquibase.exception.DatabaseException; //导入依赖的package包/类
/**
 * Fill foreign key information from the current register of a getImportedKeys resultset
 * 
 * @param rs The resultset returned by getImportedKeys
 * @return Foreign key information
 */
protected ForeignKeyInfo fillForeignKeyInfo(ResultSet rs) throws DatabaseException, SQLException {
	ForeignKeyInfo fkInfo = new ForeignKeyInfo();
	fkInfo.setFkName(convertFromDatabaseName(rs.getString("FK_NAME")));
	fkInfo.setFkSchema(convertFromDatabaseName(rs.getString("FKTABLE_SCHEM")));
	fkInfo.setFkTableName(convertFromDatabaseName(rs.getString("FKTABLE_NAME")));
	fkInfo.setFkColumn(convertFromDatabaseName(rs.getString("FKCOLUMN_NAME")));
	fkInfo.setPkTableSchema(rs.getString("PKTABLE_SCHEM"));
	fkInfo.setPkTableName(convertFromDatabaseName(rs.getString("PKTABLE_NAME")));
	fkInfo.setPkColumn(convertFromDatabaseName(rs.getString("PKCOLUMN_NAME")));
	fkInfo.setKeySeq(rs.getInt("KEY_SEQ"));
	ForeignKeyConstraintType updateRule = convertToForeignKeyConstraintType(rs.getInt("UPDATE_RULE"));
	if (rs.wasNull()) {
		updateRule = null;
	}
	fkInfo.setUpdateRule(updateRule);
	ForeignKeyConstraintType deleteRule = convertToForeignKeyConstraintType(rs.getInt("DELETE_RULE"));
	if (rs.wasNull()) {
		deleteRule = null;
	}
	fkInfo.setDeleteRule(deleteRule);
	fkInfo.setDeferrablility(rs.getShort("DEFERRABILITY"));
	return fkInfo;
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:30,代码来源:JdbcDatabaseSnapshotGenerator.java

示例8: testGenerateSql

import liquibase.exception.DatabaseException; //导入依赖的package包/类
@Test(dataProvider = "generateSqlTestData")
public void testGenerateSql(final DropColumnStatement statement, final Database database,
      final Sql[] expected) throws DatabaseException {
   final DropGeometryColumnGeneratorGeoDB generator = new DropGeometryColumnGeneratorGeoDB();
   final SqlGeneratorChain sqlGeneratorChain = mock(SqlGeneratorChain.class);
   when(sqlGeneratorChain.generateSql(statement, database)).thenReturn(new Sql[0]);
   final Sql[] result = generator.generateSql(statement, database, sqlGeneratorChain);
   assertEquals(result.length, expected.length);
   if (result.length > 0) {
      for (int ii = 0; ii < result.length; ii++) {
         final Sql resultSql = result[ii];
         final Sql expectedSql = expected[ii];
         assertEquals(resultSql.toSql(), expectedSql.toSql());
      }
   }
}
 
开发者ID:lonnyj,项目名称:liquibase-spatial,代码行数:17,代码来源:DropGeometryColumnGeneratorGeoDBTest.java

示例9: generateSql

import liquibase.exception.DatabaseException; //导入依赖的package包/类
public Sql[] generateSql(FindForeignKeyConstraintsStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    StringBuilder sb = new StringBuilder();

    sb.append("SELECT ");
    sb.append("RC.TABLE_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_NAME).append(", ");
    sb.append("KCU.COLUMN_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_COLUMN_NAME).append(", ");
    sb.append("RC.REFERENCED_TABLE_NAME ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_TABLE_NAME).append(", ");
    sb.append("KCU.REFERENCED_COLUMN_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_COLUMN_NAME).append(", ");
    sb.append("RC.CONSTRAINT_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_CONSTRAINT_NAME).append(" ");
    sb.append("FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC,");
    sb.append("     INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU ");
    sb.append("WHERE RC.TABLE_NAME = KCU.TABLE_NAME ");
    sb.append("AND RC.CONSTRAINT_SCHEMA = KCU.CONSTRAINT_SCHEMA ");
    sb.append("AND RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME ");
    sb.append("AND RC.TABLE_NAME = '").append(statement.getBaseTableName()).append("' ");
    try {
        sb.append("AND RC.CONSTRAINT_SCHEMA = '").append(database.convertRequestedSchemaToSchema(null)).append("'");
    } catch (DatabaseException e) {
        throw new UnexpectedLiquibaseException(e);
    }
    return new Sql[]{
            new UnparsedSql(sb.toString())
    };
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:25,代码来源:FindForeignKeyConstraintsGeneratorMySQL.java

示例10: getColumn

import liquibase.exception.DatabaseException; //导入依赖的package包/类
public Column getColumn(String schemaName, String tableName, String columnName, Database database)
		throws DatabaseException {
	ResultSet rs = null;
	try {
		rs = getMetaData(database).getColumns(database.convertRequestedSchemaToCatalog(schemaName),
				database.convertRequestedSchemaToSchema(schemaName),
				convertTableNameToDatabaseTableName(tableName), convertColumnNameToDatabaseTableName(columnName));

		if (!rs.next()) {
			return null;
		}

		return readColumn(rs, database);
	} catch (Exception e) {
		throw new DatabaseException(e);
	} finally {
		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException ignore) {
			}
		}
	}
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:25,代码来源:JdbcDatabaseSnapshotGenerator.java

示例11: getForeignKeys

import liquibase.exception.DatabaseException; //导入依赖的package包/类
public List<ForeignKey> getForeignKeys(String schemaName, String foreignKeyTableName, Database database)
		throws DatabaseException {
	List<ForeignKey> fkList = new ArrayList<ForeignKey>();
	try {
		String dbCatalog = database.convertRequestedSchemaToCatalog(schemaName);
		String dbSchema = database.convertRequestedSchemaToSchema(schemaName);
		ResultSet rs = getMetaData(database).getImportedKeys(dbCatalog, dbSchema,
				convertTableNameToDatabaseTableName(foreignKeyTableName));

		try {
			while (rs.next()) {
				ForeignKeyInfo fkInfo = fillForeignKeyInfo(rs);

				fkList.add(generateForeignKey(fkInfo, database, fkList));
			}
		} finally {
			rs.close();
		}

		return fkList;

	} catch (Exception e) {
		throw new DatabaseException(e);
	}
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:26,代码来源:JdbcDatabaseSnapshotGenerator.java

示例12: generateSql

import liquibase.exception.DatabaseException; //导入依赖的package包/类
public Sql[] generateSql(SelectSequencesStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    try {
        String schema = statement.getSchemaName();
        
        return new Sql[] {
                new UnparsedSql("SELECT relname AS SEQUENCE_NAME FROM pg_class, pg_namespace " +
            "WHERE relkind='S' " +
            "AND pg_class.relnamespace = pg_namespace.oid " +
            "AND nspname = '" + database.convertRequestedSchemaToSchema(schema) + "' " +
            "AND 'nextval(''" + (schema == null ? "" : schema + ".") + "'||relname||'''::regclass)' not in (select adsrc from pg_attrdef where adsrc is not null) " +
            "AND 'nextval(''" + (schema == null ? "" : schema + ".") + "\"'||relname||'\"''::regclass)' not in (select adsrc from pg_attrdef where adsrc is not null) " +
            "AND 'nextval('''||relname||'''::regclass)' not in (select adsrc from pg_attrdef where adsrc is not null)")
        };
    } catch (DatabaseException e) {
        throw new UnexpectedLiquibaseException(e);
    }
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:18,代码来源:SelectSequencesGeneratorPostgres.java

示例13: call

import liquibase.exception.DatabaseException; //导入依赖的package包/类
public Map call(CallableSqlStatement csc, final List declaredParameters, List<SqlVisitor> sqlVisitors) throws DatabaseException {
        return (Map) execute(csc, new CallableStatementCallback() {
            public Object doInCallableStatement(CallableStatement cs) throws SQLException {
                //not currently doing anything with returned results
//                boolean retVal = cs.execute();
//                int updateCount = cs.getUpdateCount();
//                Map returnedResults = new HashMap();
//                if (retVal || updateCount != -1) {
//                    returnedResults.putAll(extractReturnedResultSets(cs, declaredParameters, updateCount));
//                }
//                returnedResults.putAll(extractOutputParameters(cs, declaredParameters));
                cs.execute();
                return new HashMap();
            }
        }, sqlVisitors);
    }
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:17,代码来源:JdbcExecutor.java

示例14: execute

import liquibase.exception.DatabaseException; //导入依赖的package包/类
public Object execute(StatementCallback action, List<SqlVisitor> sqlVisitors) throws DatabaseException {
    DatabaseConnection con = database.getConnection();
    Statement stmt = null;
    try {
        stmt = ((JdbcConnection) con).getUnderlyingConnection().createStatement();
        Statement stmtToUse = stmt;

        return action.doInStatement(stmtToUse);
    }
    catch (SQLException ex) {
        // Release Connection early, to avoid potential connection pool deadlock
        // in the case when the exception translator hasn't been initialized yet.
        JdbcUtils.closeStatement(stmt);
        stmt = null;
        throw new DatabaseException("Error executing SQL " + StringUtils.join(applyVisitors(action.getStatement(), sqlVisitors), "; on "+ con.getURL())+": "+ex.getMessage(), ex);
    }
    finally {
        JdbcUtils.closeStatement(stmt);
    }
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:21,代码来源:JdbcExecutor.java

示例15: getColumnTypeAndDefValue

import liquibase.exception.DatabaseException; //导入依赖的package包/类
/**
 * Oracle specific implementation
 */
@Override
protected void getColumnTypeAndDefValue(Column columnInfo, ResultSet rs, Database database) throws SQLException, DatabaseException {
    super.getColumnTypeAndDefValue(columnInfo, rs, database);

    // Exclusive setting for oracle INTEGER type
    // Details:
    // INTEGER means NUMBER type with 'data_precision IS NULL and scale = 0'
    if (columnInfo.getDataType() == Types.INTEGER) {
        columnInfo.setTypeName("INTEGER");
    }

    String columnTypeName = rs.getString("TYPE_NAME");
    if ("VARCHAR2".equals(columnTypeName)) {
        int charOctetLength = rs.getInt("CHAR_OCTET_LENGTH");
        int columnSize = rs.getInt("COLUMN_SIZE");
        if (columnSize == charOctetLength) {
            columnInfo.setLengthSemantics(Column.LengthSemantics.BYTE);
        } else {
            columnInfo.setLengthSemantics(Column.LengthSemantics.CHAR);
        }
    }
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:26,代码来源:OracleDatabaseSnapshotGenerator.java


注:本文中的liquibase.exception.DatabaseException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。