1 /* 2 * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.properties.impl.config.ds.mysql; 17 18 import java.sql.PreparedStatement; 19 import java.sql.SQLException; 20 21 import de.smartics.properties.spi.config.ds.DataSourceProxy; 22 23 /** 24 * Data source proxy to create MySQL data sources. 25 */ 26 public abstract class AbstractMySqlDataSourceProxy implements DataSourceProxy 27 { 28 // ********************************* Fields ********************************* 29 30 // --- constants ------------------------------------------------------------ 31 32 /** 33 * The class version identifier. 34 */ 35 private static final long serialVersionUID = 1L; 36 37 // --- members -------------------------------------------------------------- 38 39 // ****************************** Initializer ******************************* 40 41 // ****************************** Constructors ****************************** 42 43 /** 44 * Default constructor. 45 */ 46 protected AbstractMySqlDataSourceProxy() 47 { 48 } 49 50 // ****************************** Inner Classes ***************************** 51 52 // ********************************* Methods ******************************** 53 54 // --- init ----------------------------------------------------------------- 55 56 // --- factory -------------------------------------------------------------- 57 58 // --- get&set -------------------------------------------------------------- 59 60 // --- business ------------------------------------------------------------- 61 62 @Override 63 public final String getCreateTableSqlTemplate() 64 { 65 return "CREATE TABLE IF NOT EXISTS ${table}" 66 + " (${configColumn} VARCHAR(128) NOT NULL," 67 + " ${nameColumn} VARCHAR(64) NOT NULL," 68 + " ${valueColumn} VARCHAR(255)," 69 + " CONSTRAINT prime UNIQUE (${configColumn}, ${nameColumn}))"; 70 } 71 72 @Override 73 public final String getInsertOrUpdateSqlTemplate() 74 { 75 return "INSERT INTO ${table} VALUES (?,?,?)" 76 + " ON DUPLICATE KEY UPDATE ${valueColumn} = ?"; 77 } 78 79 @Override 80 public final void setInsertOrUpdate(final PreparedStatement statement, 81 final String config, final String name, final String value) 82 throws SQLException 83 { 84 statement.setString(1, config); 85 statement.setString(2, name); 86 statement.setString(3, value); 87 statement.setString(4, value); 88 } 89 90 // --- object basics -------------------------------------------------------- 91 92 }