• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java UnitilsException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: readFileContent

import org.unitils.core.UnitilsException; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
public <T> T readFileContent(String fileName, Class<T> targetType, String encoding, Class<?> testClass) {
    ConversionStrategy<?> conversionStrategy = determineConversionStrategy(targetType);
    if (isBlank(encoding)) {
        encoding = defaultEncoding;
    }
    InputStream inputStream = null;
    try {
        if (isBlank(fileName)) {
            inputStream = readingStrategy.getDefaultInputStream(conversionStrategy.getDefaultFileExtension(), testClass);
        } else {
            inputStream = readingStrategy.getInputStream(fileName, testClass);
        }
        return (T) conversionStrategy.convertContent(inputStream, encoding);

    } catch (Exception e) {
        throw new UnitilsException("Unable to read file content for file " + fileName + " and target type " + targetType.getSimpleName(), e);
    } finally {
        closeQuietly(inputStream);
    }
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:22,代码来源:DefaultFileContentReader.java


示例2: getItemAsString

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Returns the value extracted from the result of the given query. If no value is found, a {@link UnitilsException}
 * is thrown.
 *
 * @param sql        The sql string for retrieving the items
 * @param dataSource The data source, not null
 * @return The string item value
 */
public static String getItemAsString(String sql, DataSource dataSource) {
    logger.debug(sql);

    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    try {
        connection = dataSource.getConnection();
        statement = connection.createStatement();
        resultSet = statement.executeQuery(sql);
        if (resultSet.next()) {
            return resultSet.getString(1);
        }
    } catch (Exception e) {
        throw new UnitilsException("Error while executing statement: " + sql, e);
    } finally {
        closeQuietly(connection, statement, resultSet);
    }

    // in case no value was found, throw an exception
    throw new UnitilsException("No item value found: " + sql);
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:31,代码来源:SQLUnitils.java


示例3: readDataSetXml

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Parses the datasets from the given files.
 * Each schema is given its own dataset and each row is given its own table.
 *
 * @param dataSetFiles The dataset files, not null
 * @return The read data set, not null
 */
public MultiSchemaDataSet readDataSetXml(File... dataSetFiles) {
    try {
        DataSetContentHandler dataSetContentHandler = new DataSetContentHandler(defaultSchemaName);
        XMLReader xmlReader = createXMLReader();
        xmlReader.setContentHandler(dataSetContentHandler);
        xmlReader.setErrorHandler(dataSetContentHandler);

        for (File dataSetFile : dataSetFiles) {
            InputStream dataSetInputStream = null;
            try {
                dataSetInputStream = new FileInputStream(dataSetFile);
                xmlReader.parse(new InputSource(dataSetInputStream));
            } finally {
                closeQuietly(dataSetInputStream);
            }
        }
        return dataSetContentHandler.getMultiSchemaDataSet();

    } catch (Exception e) {
        throw new UnitilsException("Unable to parse data set xml.", e);
    }

}
 
开发者ID:linux-china,项目名称:unitils,代码行数:31,代码来源:MultiSchemaXmlDataSetReader.java


示例4: readClass

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Uses ASM to read the byte code of the given class. This will access the class file and create some sort
 * of DOM tree for the structure of the bytecode.
 *
 * @param clazz The class to read, not null
 * @return The structure of the class, not null
 */
protected static ClassNode readClass(Class<?> clazz) {
    InputStream inputStream = null;
    try {
        inputStream = clazz.getClassLoader().getResourceAsStream(clazz.getName().replace('.', '/') + ".class");

        ClassReader classReader = new ClassReader(inputStream);
        ClassNode classNode = new ClassNode();
        classReader.accept(classNode, 0);
        return classNode;

    } catch (Exception e) {
        throw new UnitilsException("Unable to read class file for " + clazz, e);
    } finally {
        closeQuietly(inputStream);
    }
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:24,代码来源:ArgumentMatcherPositionFinder.java


示例5: findById

import org.unitils.core.UnitilsException; //导入依赖的package包/类
public Person findById(Long id) {
	Connection conn = null;
	PreparedStatement st = null;
	ResultSet rs = null;
	try {
		conn = dataSource.getConnection();
		st = conn.prepareStatement("select id, name from person where id = ?");
		st.setLong(1, id);
		rs = st.executeQuery();
		if (rs.next()) {
			return new Person(rs.getLong("id"), rs.getString("name"));
		} else {
			return null;
		}
	} catch (SQLException e) {
		throw new UnitilsException(e);
	} finally {
		DbUtils.closeQuietly(conn, st, rs);
	}
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:21,代码来源:JdbcPersonDao.java


示例6: getProxiedMethodStackTrace

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * First finds a trace element in which a cglib proxy method was invoked. Then it returns the rest of the stack trace following that
 * element. The stack trace starts with the element rh  r is the method call that was proxied by the proxy method.
 *
 * @return The proxied method trace, not null
 */
public static StackTraceElement[] getProxiedMethodStackTrace() {
    List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>();

    boolean foundProxyMethod = false;
    StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
    for (StackTraceElement stackTraceElement : stackTraceElements) {
        if (foundProxyMethod) {
            stackTrace.add(stackTraceElement);

        } else if (isProxyClassName(stackTraceElement.getClassName())) {
            // found the proxy method element, the next element is the proxied method element
            foundProxyMethod = true;
        }
    }
    if (stackTrace.isEmpty()) {
        throw new UnitilsException("No invocation of a cglib proxy method found in stacktrace: " + Arrays.toString(stackTraceElements));
    }
    return stackTrace.toArray(new StackTraceElement[stackTrace.size()]);
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:26,代码来源:ProxyUtils.java


示例7: testClearSchemas_synonymsToPreserveDoNotExist

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Test for synonyms to preserve that do not exist.
 */
@Test
public void testClearSchemas_synonymsToPreserveDoNotExist() throws Exception {
    if (!getDefaultDbSupport(configuration, sqlHandler, dialect, schemas.get(0)).supportsSynonyms()) {
        logger.warn("Current dialect does not support synonyms. Skipping test.");
        return;
    }
    try {
        configuration.setProperty(PROPKEY_PRESERVE_SYNONYMS, "unexisting_synonym1, unexisting_synonym2");
        defaultDbClearer.init(configuration, sqlHandler, dialect, schemas);
        fail("UnitilsException expected.");
    } catch (UnitilsException e) {
        // expected
    }

}
 
开发者ID:linux-china,项目名称:unitils,代码行数:19,代码来源:DefaultDBClearerPreserveDoesNotExistTest.java


示例8: copyClassPathResource

import org.unitils.core.UnitilsException; //导入依赖的package包/类
public static void copyClassPathResource(String classPathResourceName, String fileSystemDirectoryName) {
    InputStream resourceInputStream = null;
    OutputStream fileOutputStream = null;
    try {
        resourceInputStream = FileUtils.class.getResourceAsStream(classPathResourceName);
        String fileName = StringUtils.substringAfterLast(classPathResourceName, "/");
        File fileSystemDirectory = new File(fileSystemDirectoryName);
        fileSystemDirectory.mkdirs();
        fileOutputStream = new FileOutputStream(fileSystemDirectoryName + "/" + fileName);
        IOUtils.copy(resourceInputStream, fileOutputStream);
    } catch (IOException e) {
        throw new UnitilsException(e);
    } finally {
        closeQuietly(resourceInputStream);
        closeQuietly(fileOutputStream);
    }
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:18,代码来源:FileUtils.java


示例9: assertAccessablePropertiesNotNull

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * All fields that have a getter with the same name will be checked by an assertNotNull.
 * Other fields will be ignored
 * 
 * @param message
 * @param object
 */
public static void assertAccessablePropertiesNotNull(String message, Object object) {

    Set<Field> fields = ReflectionUtils.getAllFields(object.getClass());
    for (Field field : fields) {
        Method getter = ReflectionUtils.getGetter(object.getClass(), field.getName(), false);
        if (getter != null) {
            Object result = null;

            try {
                result = getter.invoke(object, ArrayUtils.EMPTY_OBJECT_ARRAY);
            } catch (Exception e) {
                throw new UnitilsException(e);
            }
            String formattedMessage = formatMessage(message, "Property '" + field.getName() + "' in object '" + object.toString() + "' is null ");
            assertNotNull(formattedMessage, result);
        }

    }
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:27,代码来源:ReflectionAssert.java


示例10: getTriggersToPreserve

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Gets the list of all triggers to preserve per schema. The case is corrected if necesary. Quoting a trigger name
 * makes it case sensitive. If no schema is specified, the trigger will be added to the default schema name set.
 * <p/>
 * If a trigger to preserve does not exist, a UnitilsException is thrown.
 *
 * @return The trigger to preserve per schema, not null
 */
protected Map<String, Set<String>> getTriggersToPreserve() {
    Map<String, Set<String>> triggersToPreserve = getItemsToPreserve(PROPKEY_PRESERVE_TRIGGERS);
    for (Map.Entry<String, Set<String>> entry : triggersToPreserve.entrySet()) {
        String schemaName = entry.getKey();

        DbSupport dbSupport = getDbSupport(schemaName);
        Set<String> triggerNames;
        if (!dbSupport.supportsTriggers()) {
            triggerNames = new HashSet<String>();
        } else {
            triggerNames = dbSupport.getTriggerNames();
        }
        for (String triggerToPreserve : entry.getValue()) {
            if (!itemToPreserveExists(triggerToPreserve, triggerNames)) {
                throw new UnitilsException("Trigger to preserve does not exist: " + triggerToPreserve + " in schema: " + schemaName + ".\nUnitils cannot determine which triggers need to be preserved. To assure nothing is dropped by mistake, no triggers will be dropped.\nPlease fix the configuration of the " + PROPKEY_PRESERVE_TRIGGERS + " property.");
            }
        }
    }
    return triggersToPreserve;
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:29,代码来源:DefaultDBClearer.java


示例11: disableCheckAndUniqueConstraints

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Disables all check and unique constraints on all tables in the schema
 */
protected void disableCheckAndUniqueConstraints() {
    Connection connection = null;
    Statement queryStatement = null;
    Statement alterStatement = null;
    ResultSet resultSet = null;
    try {
        connection = getSQLHandler().getDataSource().getConnection();
        queryStatement = connection.createStatement();
        alterStatement = connection.createStatement();

        resultSet = queryStatement.executeQuery("select TABLE_NAME, CONSTRAINT_NAME from INFORMATION_SCHEMA.SYSTEM_TABLE_CONSTRAINTS where CONSTRAINT_TYPE IN ('CHECK', 'UNIQUE') AND CONSTRAINT_SCHEMA = '" + getSchemaName() + "'");
        while (resultSet.next()) {
            String tableName = resultSet.getString("TABLE_NAME");
            String constraintName = resultSet.getString("CONSTRAINT_NAME");
            alterStatement.executeUpdate("alter table " + qualified(tableName) + " drop constraint " + quoted(constraintName));
        }
    } catch (Exception e) {
        throw new UnitilsException("Error while disabling check and unique constraints on schema " + getSchemaName(), e);
    } finally {
        closeQuietly(queryStatement);
        closeQuietly(connection, alterStatement, resultSet);
    }
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:27,代码来源:HsqldbDbSupport.java


示例12: getStringList

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Gets the list of comma separated string values for the property with the given name. If no such property is found or
 * the value is empty, an empty list is returned if not required, else an exception is raised. Empty elements (",,")
 * will not be added.
 *
 * @param propertyName The name, not null
 * @param required     If true an exception will be raised when the property is not found or empty
 * @return The trimmed string list, empty or exception if none found
 */
public List<String> getStringList(String propertyName, boolean required) {
    String values = properties.getProperty(propertyName);
    if (values == null || "".equals(values.trim())) {
        if (required) {
            throw new UnitilsException("No value found for property " + propertyName);
        }
        return new ArrayList<String>(0);
    }
    String[] splitValues = values.split(",");
    List<String> result = new ArrayList<String>(splitValues.length);
    for (String value : splitValues) {
        if (value == null || "".equals(value.trim())) {
            continue;
        }
        result.add(value.trim());
    }

    if (required && result.isEmpty()) {
        throw new UnitilsException("No value found for property " + propertyName);
    }
    return result;
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:32,代码来源:UnitilsConfiguration.java


示例13: getValueStatic

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Retrieves the value of the static property from the given class
 *
 * @param targetClass    The class from which the static property value is retrieved
 * @param staticProperty The name of the property (simple name, not a composite expression)
 * @return The value of the static property from the given class
 */
private static Object getValueStatic(Class<?> targetClass, String staticProperty) {
    Method staticGetter = getGetter(targetClass, staticProperty, true);
    if (staticGetter != null) {
        try {
            return invokeMethod(targetClass, staticGetter);

        } catch (InvocationTargetException e) {
            throw new UnitilsException("Exception thrown by target", e);
        }
    } else {
        Field staticField = getFieldWithName(targetClass, staticProperty, true);
        if (staticField != null) {
            return getFieldValue(targetClass, staticField);
        } else {
            throw new UnitilsException("Static property named " + staticProperty + " not found on class " + targetClass.getSimpleName());
        }
    }
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:26,代码来源:InjectionUtils.java


示例14: testGetAnnotationEnumDefaults_defaultWrongKey

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Test the loading of the default values. TestAnnotation2 has a default value configured but for different enum.
 * Default for test enum in annotation 1 should still be loaded correctly.
 */
@SuppressWarnings("unchecked")
public void testGetAnnotationEnumDefaults_defaultWrongKey() {
    configuration.remove("ModuleUtilsTest.TestModule.ModuleUtilsTest.TestAnnotation2.testEnum.default");
    configuration.setProperty("ModuleUtilsTest.TestModule.ModuleUtilsTest.TestAnnotation2.otherTestEnum.default", "VALUE2");

    Map<Class<? extends Annotation>, Map<String, String>> result = getAnnotationPropertyDefaults(TestModule.class,
            configuration, TestAnnotation1.class, TestAnnotation2.class);

    TestEnum enumValue1 = getEnumValueReplaceDefault(TestAnnotation1.class, "testEnum", TestEnum.DEFAULT, result);
    assertSame(TestEnum.VALUE1, enumValue1);
    try {
        getEnumValueReplaceDefault(TestAnnotation2.class, "testEnum", TestEnum.DEFAULT, result);
        fail("Expected UnitilsException");

    } catch (UnitilsException e) {
        // expected
    }
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:23,代码来源:ModuleUtilsTest.java


示例15: loadPropertiesFileFromUserHome

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
    * Loads the properties file with the given name, which is available in the user home folder. If no
    * file with the given name is found, null is returned.
    * 
    * @param propertiesFileName The name of the properties file
    * @return The Properties object, null if the properties file wasn't found.
    */
public Properties loadPropertiesFileFromUserHome(
		String propertiesFileName) {
       InputStream inputStream = null;
       try {
       	if("".equals(propertiesFileName)){
       		throw new IllegalArgumentException("Properties Filename must be given.");
       	}
           Properties properties = new Properties();
           String userHomeDir = System.getProperty("user.home");
           File localPropertiesFile = new File(userHomeDir, propertiesFileName);
           if (!localPropertiesFile.exists()) {
               return null;
           }
           inputStream = new FileInputStream(localPropertiesFile);
           properties.load(inputStream);
           logger.info("Loaded configuration file " + propertiesFileName + " from user home");
           return properties;

       } catch (Exception e) {
           throw new UnitilsException("Unable to load configuration file: " + propertiesFileName + " from user home", e);
       } finally {
           closeQuietly(inputStream);
       }
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:32,代码来源:PropertiesReader.java


示例16: testUpdateDatabase_ErrorInScript

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Tests the behavior in case there is an error in a script supplied by the ScriptSource. In this case, the
 * database version must not org incremented and a StatementHandlerException must be thrown.
 */
@Test
public void testUpdateDatabase_ErrorInScript() throws Exception {
    // Set database version and available script expectations
    expectNewScriptsAdded();
    expectNoPostProcessingCodeScripts();
    mockScriptRunner.raises(UnitilsException.class).execute(scripts.get(0).getScriptContentHandle());

    try {
        dbMaintainer.updateDatabase(schema, true);
        fail("A UnitilsException should have been thrown");
    } catch (UnitilsException e) {
        // expected
    }
    mockExecutedScriptInfoSource.assertInvoked().registerExecutedScript(new ExecutedScript(scripts.get(0), null, false));
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:20,代码来源:DBMaintainerTest.java


示例17: incrementSequenceToValue

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Sets the next value of the sequence with the given sequence name to the given sequence value.
 *
 * @param sequenceName     The sequence, not null
 * @param newSequenceValue The value to set
 */
@Override
public void incrementSequenceToValue(String sequenceName, long newSequenceValue) {
    Connection connection = null;
    ResultSet resultSet = null;
    Statement statement = null;
    try {
        connection = getSQLHandler().getDataSource().getConnection();
        statement = connection.createStatement();
        resultSet = statement.executeQuery("select LAST_NUMBER, INCREMENT_BY from ALL_SEQUENCES where SEQUENCE_NAME = '" + sequenceName + "' and SEQUENCE_OWNER = '" + getSchemaName() + "'");
        while (resultSet.next()) {
            long lastNumber = resultSet.getLong("LAST_NUMBER");
            long incrementBy = resultSet.getLong("INCREMENT_BY");
            // change the increment
            getSQLHandler().executeUpdate("alter sequence " + qualified(sequenceName) + " increment by " + (newSequenceValue - lastNumber));
            // select the increment
            getSQLHandler().executeQuery("select " + qualified(sequenceName) + ".NEXTVAL from DUAL");
            // set back old increment
            getSQLHandler().executeUpdate("alter sequence " + qualified(sequenceName) + " increment by " + incrementBy);
        }
    } catch (SQLException e) {
        throw new UnitilsException("Error while incrementing sequence to value", e);
    } finally {
        closeQuietly(connection, statement, resultSet);
    }
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:32,代码来源:OracleDbSupport.java


示例18: getItemsAsStringSet

import org.unitils.core.UnitilsException; //导入依赖的package包/类
/**
 * Returns the items extracted from the result of the given query.
 *
 * @param sql        The sql string for retrieving the items
 * @param dataSource The data source, not null
 * @return The items, not null
 */
public static Set<String> getItemsAsStringSet(String sql, DataSource dataSource) {
    logger.debug(sql);

    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    try {
        connection = dataSource.getConnection();
        statement = connection.createStatement();
        resultSet = statement.executeQuery(sql);
        Set<String> result = new HashSet<String>();
        while (resultSet.next()) {
            result.add(resultSet.getString(1));
        }
        return result;

    } catch (Exception e) {
        throw new UnitilsException("Error while executing statement: " + sql, e);
    } finally {
        closeQuietly(connection, statement, resultSet);
    }
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:30,代码来源:SQLUnitils.java


示例19: executeUpdateAndCommit

import org.unitils.core.UnitilsException; //导入依赖的package包/类
public int executeUpdateAndCommit(String sql) {
    logger.debug(sql);

    if (!doExecuteUpdates) {
        // skip update
        return 0;
    }
    Connection connection = null;
    Statement statement = null;
    try {
        connection = dataSource.getConnection();
        statement = connection.createStatement();
        int nbChanges = statement.executeUpdate(sql);
        if (!connection.getAutoCommit()) {
            connection.commit();
        }
        return nbChanges;

    } catch (Exception e) {
        throw new UnitilsException("Error while performing database update: " + sql, e);
    } finally {
        closeQuietly(connection, statement, null);
    }
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:25,代码来源:DefaultSQLHandler.java


示例20: getItemAsLong

import org.unitils.core.UnitilsException; //导入依赖的package包/类
public long getItemAsLong(String sql) {
    logger.debug(sql);

    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    try {
        connection = dataSource.getConnection();
        statement = connection.createStatement();
        resultSet = statement.executeQuery(sql);
        if (resultSet.next()) {
            return resultSet.getLong(1);
        }
    } catch (Exception e) {
        throw new UnitilsException("Error while executing statement: " + sql, e);
    } finally {
        closeQuietly(connection, statement, resultSet);
    }

    // in case no value was found, throw an exception
    throw new UnitilsException("No item value found: " + sql);
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:23,代码来源:DefaultSQLHandler.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HighPerformanceTiledSpriteVertexBufferObject类代码示例发布时间:2022-05-23
下一篇:
Java DocumentHighlight类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap