Index: topia/src/java/org/codelutin/topia/persistence/jdbc/JDBCPersistenceHelper.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/jdbc/JDBCPersistenceHelper.java:1.1 --- /dev/null Wed Sep 15 15:25:57 2004 +++ topia/src/java/org/codelutin/topia/persistence/jdbc/JDBCPersistenceHelper.java Wed Sep 15 15:25:51 2004 @@ -0,0 +1,226 @@ +/* *##% + * Copyright (C) 2002, 2003, 2004 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * JDBCPersistenceHelper.java + * + * Created: Sep 15, 2004 + * + * @author Cédric Pineau + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2004/09/15 15:25:51 $ + * by : $Author: pineau $ + */ + +package org.codelutin.topia.persistence.jdbc; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.List; +import java.util.Properties; + +import org.codelutin.topia.AsynchronousLoader; +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaEntity; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.TopiaQuery; +import org.codelutin.topia.persistence.AbstractPersistenceHelper; + +/** + * + */ +public class JDBCPersistenceHelper extends AbstractPersistenceHelper { + + protected Connection connection; + + public JDBCPersistenceHelper(TopiaContext context, Properties properties) { + super(context, properties); + + // Override jar settings with systems properties if they are set + String connectionDriverName = System + .getProperty("java.sql.ConnectionDriverName"); + if (connectionDriverName != null) { + getProperties().setProperty("java.sql.ConnectionDriverName", + connectionDriverName); + } + String connectionURL = System.getProperty("java.sql.ConnectionURL"); + if (connectionURL != null) { + getProperties() + .setProperty("java.sql.ConnectionURL", connectionURL); + } + String connectionUserName = System + .getProperty("java.sql.ConnectionUserName"); + if (connectionUserName != null) { + getProperties().setProperty("java.sql.ConnectionUserName", + connectionUserName); + } + String connectionPassword = System + .getProperty("java.sql.ConnectionPassword"); + if (connectionPassword != null) { + getProperties().setProperty("java.sql.ConnectionPassword", + connectionPassword); + } + + initDb(); + } + + protected void initDb() { + try { + String connectionDriverName = getProperties().getProperty( + "java.sql.ConnectionDriverName"); + String connectionURL = getProperties().getProperty( + "java.sql.ConnectionURL"); + String connectionUserName = getProperties().getProperty( + "java.sql.ConnectionUserName"); + String connectionPassword = getProperties().getProperty( + "java.sql.ConnectionPassword"); + + // Load the database driver + Class.forName(connectionDriverName); + + // Get a connection to the database + connection = DriverManager.getConnection(connectionURL, + connectionUserName, connectionPassword); + + } catch (SQLException se) { + se.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.persistence.PersistenceHelper#makePersistent(org.codelutin.topia.TopiaEntity) + */ + + public TopiaEntity makePersistent(TopiaEntity entity) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.persistence.PersistenceHelper#update(org.codelutin.topia.TopiaEntity) + */ + public TopiaEntity update(TopiaEntity entity) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.persistence.PersistenceHelper#delete(org.codelutin.topia.TopiaEntity) + */ + public void delete(TopiaEntity entity) throws TopiaException { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.persistence.PersistenceHelper#find(org.codelutin.topia.TopiaQuery) + */ + public List find(TopiaQuery query) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.persistence.PersistenceHelper#findAsynchronously(org.codelutin.topia.TopiaQuery) + */ + public AsynchronousLoader findAsynchronously(TopiaQuery query) + throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.persistence.PersistenceHelper#findInRange(org.codelutin.topia.TopiaQuery, + * int, int) + */ + public List findInRange(TopiaQuery query, int startIndex, int endIndex) + throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.persistence.PersistenceHelper#findInRangeAsynchronously(org.codelutin.topia.TopiaQuery, + * int, int) + */ + public AsynchronousLoader findInRangeAsynchronously(TopiaQuery query, + int startIndex, int endIndex) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.persistence.PersistenceHelper#size(org.codelutin.topia.TopiaQuery) + */ + public int size(TopiaQuery query) throws TopiaException { + // TODO Auto-generated method stub + return 0; + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.persistence.PersistenceHelper#importXML(java.lang.String) + */ + public void importXML(String xml) throws TopiaException { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.persistence.PersistenceHelper#exportXML() + */ + public String exportXML() throws TopiaException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.persistence.PersistenceHelper#findByTopiaId(java.lang.String) + */ + public TopiaEntity findByTopiaId(String id) throws TopiaException { + // TODO Auto-generated method stub + return null; + } + +} \ No newline at end of file