Java Code Examples for org.mybatis.generator.config.JDBCConnectionConfiguration

The following examples show how to use org.mybatis.generator.config.JDBCConnectionConfiguration. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public Connection getConnection(JDBCConnectionConfiguration config)
        throws SQLException {
    Driver driver = getDriver(config);

    Properties props = new Properties();

    if (stringHasValue(config.getUserId())) {
        props.setProperty("user", config.getUserId()); //$NON-NLS-1$
    }

    if (stringHasValue(config.getPassword())) {
        props.setProperty("password", config.getPassword()); //$NON-NLS-1$
    }

    props.putAll(config.getProperties());

    Connection conn = driver.connect(config.getConnectionURL(), props);

    if (conn == null) {
        throw new SQLException(getString("RuntimeError.7")); //$NON-NLS-1$
    }

    return conn;
}
 
Example 2
Source Project: mybatis-generator-plus   Source File: ConnectionFactory.java    License: Apache License 2.0 6 votes vote down vote up
public Connection getConnection(JDBCConnectionConfiguration config)
        throws SQLException {
    Driver driver = getDriver(config);

    Properties props = new Properties();

    if (stringHasValue(config.getUserId())) {
        props.setProperty("user", config.getUserId()); //$NON-NLS-1$
    }

    if (stringHasValue(config.getPassword())) {
        props.setProperty("password", config.getPassword()); //$NON-NLS-1$
    }

    props.putAll(config.getProperties());

    Connection conn = driver.connect(config.getConnectionURL(), props);

    if (conn == null) {
        throw new SQLException(getString("RuntimeError.7")); //$NON-NLS-1$
    }

    return conn;
}
 
Example 3
Source Project: dolphin   Source File: XmbgMojoUnitTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testChoosePagination(){
    Context context = new Context(null);
    //测试PostgreSQL
    JDBCConnectionConfiguration jdbcConnectionConfiguration = new JDBCConnectionConfiguration();
    jdbcConnectionConfiguration.setConnectionURL("jdbc:postgresql://10.1.8.61:5432/DataManageSystem");
    context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);
    MyBatisGeneratorMojo mbgm = new MyBatisGeneratorMojo();
    mbgm.choosePaginationPlugin(context);
    assertTrue(checkPlugin(PostgreSQLPaginationPlugin.class,context));
    
    //测试MySql
    jdbcConnectionConfiguration.setConnectionURL("jdbc:mysql://localhost/web-monitor?useUnicode=true&characterEncoding=utf-8");
    context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);
    mbgm.choosePaginationPlugin(context);
    assertTrue(checkPlugin(MySqlPaginationPlugin.class,context));
}
 
Example 4
/**
 * This constructor is called when there is a JDBCConnectionConfiguration
 * specified in the configuration.
 * 
 * @param config the configuration
 */
public JDBCConnectionFactory(JDBCConnectionConfiguration config) {
    super();
    userId = config.getUserId();
    password = config.getPassword();
    connectionURL = config.getConnectionURL();
    driverClass = config.getDriverClass();
    otherProperties = config.getProperties();
}
 
Example 5
protected void parseJdbcConnection(Context context, Node node) {
    JDBCConnectionConfiguration jdbcConnectionConfiguration = new JDBCConnectionConfiguration();

    context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);

    Properties attributes = parseAttributes(node);
    String driverClass = attributes.getProperty("driverClass");
    String connectionURL = attributes.getProperty("connectionURL");

    jdbcConnectionConfiguration.setDriverClass(driverClass);
    jdbcConnectionConfiguration.setConnectionURL(connectionURL);

    String userId = attributes.getProperty("userId");
    if (stringHasValue(userId)) {
        jdbcConnectionConfiguration.setUserId(userId);
    }

    String password = attributes.getProperty("password");
    if (stringHasValue(password)) {
        jdbcConnectionConfiguration.setPassword(password);
    }

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) {
            parseProperty(jdbcConnectionConfiguration, childNode);
        }
    }
}
 
Example 6
private void parseJdbcConnection(Context context, Node node) {
    JDBCConnectionConfiguration jdbcConnectionConfiguration = new JDBCConnectionConfiguration();

    context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);

    Properties attributes = parseAttributes(node);
    String driverClass = attributes.getProperty("driverClass"); //$NON-NLS-1$
    String connectionURL = attributes.getProperty("connectionURL"); //$NON-NLS-1$
    String userId = attributes.getProperty("userId"); //$NON-NLS-1$
    String password = attributes.getProperty("password"); //$NON-NLS-1$

    jdbcConnectionConfiguration.setDriverClass(driverClass);
    jdbcConnectionConfiguration.setConnectionURL(connectionURL);

    if (stringHasValue(userId)) {
        jdbcConnectionConfiguration.setUserId(userId);
    }

    if (stringHasValue(password)) {
        jdbcConnectionConfiguration.setPassword(password);
    }

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperty(jdbcConnectionConfiguration, childNode);
        }
    }
}
 
Example 7
private void parseJdbcConnection(Context context, Node node) {
    JDBCConnectionConfiguration jdbcConnectionConfiguration = new JDBCConnectionConfiguration();

    context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);

    Properties attributes = parseAttributes(node);
    String driverClass = attributes.getProperty("driverClass"); //$NON-NLS-1$
    String connectionURL = attributes.getProperty("connectionURL"); //$NON-NLS-1$
    String userId = attributes.getProperty("userId"); //$NON-NLS-1$
    String password = attributes.getProperty("password"); //$NON-NLS-1$

    jdbcConnectionConfiguration.setDriverClass(driverClass);
    jdbcConnectionConfiguration.setConnectionURL(connectionURL);

    if (stringHasValue(userId)) {
        jdbcConnectionConfiguration.setUserId(userId);
    }

    if (stringHasValue(password)) {
        jdbcConnectionConfiguration.setPassword(password);
    }

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperty(jdbcConnectionConfiguration, childNode);
        }
    }
}
 
Example 8
private void parseJdbcConnection(Context context, Node node) {
    JDBCConnectionConfiguration jdbcConnectionConfiguration = new JDBCConnectionConfiguration();

    context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);

    Properties attributes = parseAttributes(node);
    String driverClass = attributes.getProperty("driverClass"); //$NON-NLS-1$
    String connectionURL = attributes.getProperty("connectionURL"); //$NON-NLS-1$
    String userId = attributes.getProperty("userId"); //$NON-NLS-1$
    String password = attributes.getProperty("password"); //$NON-NLS-1$

    jdbcConnectionConfiguration.setDriverClass(driverClass);
    jdbcConnectionConfiguration.setConnectionURL(connectionURL);

    if (stringHasValue(userId)) {
        jdbcConnectionConfiguration.setUserId(userId);
    }

    if (stringHasValue(password)) {
        jdbcConnectionConfiguration.setPassword(password);
    }

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperty(jdbcConnectionConfiguration, childNode);
        }
    }
}
 
Example 9
private void parseJdbcConnection(Context context, Node node) {
    JDBCConnectionConfiguration jdbcConnectionConfiguration = new JDBCConnectionConfiguration();

    context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);

    Properties attributes = parseAttributes(node);
    String driverClass = attributes.getProperty("driverClass"); //$NON-NLS-1$
    String connectionURL = attributes.getProperty("connectionURL"); //$NON-NLS-1$
    String userId = attributes.getProperty("userId"); //$NON-NLS-1$
    String password = attributes.getProperty("password"); //$NON-NLS-1$

    jdbcConnectionConfiguration.setDriverClass(driverClass);
    jdbcConnectionConfiguration.setConnectionURL(connectionURL);

    if (stringHasValue(userId)) {
        jdbcConnectionConfiguration.setUserId(userId);
    }

    if (stringHasValue(password)) {
        jdbcConnectionConfiguration.setPassword(password);
    }

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperty(jdbcConnectionConfiguration, childNode);
        }
    }
}