]> git.mxchange.org Git - jaddressbook-lib.git/blob - Addressbook/src/org/mxchange/addressbook/database/backend/mysql/MySqlDatabaseBackend.java
Added more MySQL-related stuff
[jaddressbook-lib.git] / Addressbook / src / org / mxchange / addressbook / database / backend / mysql / MySqlDatabaseBackend.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.addressbook.database.backend.mysql;
18
19 import java.io.IOException;
20 import java.sql.Connection;
21 import java.sql.DriverManager;
22 import java.sql.SQLException;
23 import java.util.Iterator;
24 import org.mxchange.addressbook.contact.Contact;
25 import org.mxchange.addressbook.database.backend.BaseDatabaseBackend;
26 import org.mxchange.addressbook.database.backend.DatabaseBackend;
27 import org.mxchange.addressbook.database.storage.Storeable;
28 import org.mxchange.addressbook.exceptions.BadTokenException;
29 import org.mxchange.addressbook.exceptions.UnsupportedDatabaseDriverException;
30
31 /**
32  * A backend class for MySQL connections
33  *
34  * @author Roland Haeder
35  */
36 public class MySqlDatabaseBackend extends BaseDatabaseBackend implements DatabaseBackend {
37         /**
38          * An instance of a datbase connection
39          */
40         private Connection connection;
41
42         /**
43          * Constructor with table name
44          * 
45          * @param tableName Table to access
46          * @throws org.mxchange.addressbook.exceptions.UnsupportedDatabaseDriverException
47          */
48         public MySqlDatabaseBackend (final String tableName) throws UnsupportedDatabaseDriverException {
49                 // Validate driver
50                 this.validateDriver("mysql"); //NOI18N
51
52                 // Now that the driver is there ...
53         }
54
55         @Override
56         public void connectToDatabase () throws SQLException {
57                 // Generate connection string
58                 String connect = "jdbc:mysql://" + this.getProperty("org.mxchange.database.mysql.host") + "/" + this.getTableName();
59
60                 // Now get a connection instance back
61                 this.connection = DriverManager.getConnection(connect, this.getProperty("org.mxchange.database.mysql.login"), this.getProperty("org.mxchange.database.mysql.password"));
62         }
63
64         @Override
65         public Iterator<Contact> contactIterator () throws BadTokenException {
66                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
67         }
68
69         @Override
70         public void doShutdown () {
71                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
72         }
73
74         @Override
75         public long length () {
76                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
77         }
78
79         @Override
80         public void rewind () {
81                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
82         }
83
84         @Override
85         public void store (final Storeable object) throws IOException {
86                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
87         }
88 }