You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by "Pickelbauer, Martin" <pi...@siemens-enterprise.com> on 2010/03/18 10:49:24 UTC

Searching for an example how to use Ibatis 3 without XML files

Hello,

I'm searching for an full example on how to use Ibatis 3 without any XML files, so only with configuration settings in Java. Anyone a hint, where to find such an example?

regards,

martin

Re: Searching for an example how to use Ibatis 3 without XML files

Posted by shamim <sr...@yandex.ru>.
public class TestConfig {
    public static void main(String[] args) {
        SqlSession session = null;
        try {
            // derby datasource setting
            EmbeddedDataSource ds = new EmbeddedDataSource();
            ds.setDatabaseName("d:/DerbyDB");
            ds.setUser("");
            ds.setPassword("");
            /*DataSource ds = null;
            try {
                ds = getOracleDataSource();
            } catch (SQLException e) {
                System.out.println("No data Conenction");
                e.printStackTrace();
                System.exit(1);

            } */
            TransactionFactory tfactory = new JdbcTransactionFactory();
            

            Environment env = new Environment("Development", tfactory, ds);
            Configuration config  = new Configuration(env).;
            SqlSessionFactory sessionFactory = new
SqlSessionFactoryBuilder().build(config);
            session = sessionFactory.openSession();
            System.out.println("Session open");
            // query
            FooMapper fooMapper =  session.getMapper(FooMapper.class);
            // do something
        } finally {
            session.close();
            System.out.println("Session closed");
        }

    }
    private static DataSource getOracleDataSource() throws SQLException {

        OracleDataSource ods = new OracleDataSource();
        ods.setURL("jdbc:oracle:thin:@localhost:1521:ORCL");
        ods.setUser("scott");
        ods.setPassword("tiger");

        // caching parms
        //ods.setConnectionCachingEnabled(true);
        //ods.setConnectionCacheName("MY_Cache");
        //Properties cacheProps = new Properties();
        //cacheProps.setProperty("MinLimit", "1");
        //cacheProps.setProperty("MaxLimit", "4");
        //cacheProps.setProperty("InitialLimit", "1");
        //cacheProps.setProperty("ConnectionWaitTimeout", "5");
        //cacheProps.setProperty("ValidateConnection", "true");

        //ods.setConnectionCacheProperties(cacheProps);

        
        
        return ods;
    }

Pickelbauer, Martin wrote:
> 
> Hello,
> 
> I'm searching for an full example on how to use Ibatis 3 without any XML
> files, so only with configuration settings in Java. Anyone a hint, where
> to find such an example?
> 
> regards,
> 
> martin
> 
> 

-- 
View this message in context: http://old.nabble.com/Searching-for-an-example-how-to-use-Ibatis-3-without-XML-files-tp27943459p27950438.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org