com.jk.data.vendors.h2.H2DataAccess Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jk-framework-data Show documentation
Show all versions of jk-framework-data Show documentation
This contains a set of API's that ease the database programming with Java, in both: JDBC and JPA Persisitnce).
/*
* Copyright 2002-2022 Dr. Jalal Kiswani.
* Email: [email protected]
* Check out https://smart-api.com for more details
*
* All the opensource projects of Dr. Jalal Kiswani are free for personal and academic use only,
* for commercial usage and support, please contact the author.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jk.data.vendors.h2;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import org.h2.tools.RunScript;
import com.jk.core.util.JK;
import com.jk.data.dataaccess.core.JKDataAccessImpl;
import com.jk.data.dataaccess.core.JKFinderAdapter;
import com.jk.data.datasource.JKDataSource;
// TODO: Auto-generated Javadoc
/**
* The Class H2DataAccess.
*/
public class H2DataAccess extends JKDataAccessImpl {
/**
* Instantiates a new h 2 data access.
*
* @param dataSource the data source
*/
public H2DataAccess(JKDataSource dataSource) {
super(dataSource);
}
/**
* Run script.
*
* @param fileName the file name
*/
/*
* (non-Javadoc)
*
* @see
* com.jk.db.test.dataaccess.core.JKAbstractPlainDataAccess#runScript(java.lang.
* String)
*/
@Override
public void runScript(String fileName) {
logger.debug("runScript({})", fileName);
try {
RunScript.execute(getConnection(), JK.getReader(fileName));
} catch (SQLException e) {
JK.throww(e);
}
}
/**
* Gets the system date.
*
* @return the system date
*/
/*
* (non-Javadoc)
*
* @see com.jk.db.test.dataaccess.core.JKAbstractPlainDataAccess#getSystemDate()
*/
@Override
public Date getSystemDate() {
logger.debug("getSystemDate()");
JK.fixMe("Use h2 CURRENT_DATE() function");
return new Date();
}
/**
* Describe table.
*
* @param name the name
* @return the map
*/
/*
* (non-Javadoc)
*
* @see
* com.jk.db.test.dataaccess.core.JKDefaultDataAccess#describeTable(java.lang.
* String)
*/
@Override
public Map describeTable(String name) {
logger.debug("describeTable({})", name);
final Map map = new LinkedHashMap();
JKFinderAdapter finder = new JKFinderAdapter() {
@Override
public String getQuery() {
return JK.concat("show columns from \"", name, "\"");
}
@Override
public String populate(ResultSet rs) throws SQLException {
String fieldName = rs.getString("field");
String type = rs.getString("type");
map.put(fieldName, type);
return fieldName;
}
};
getList(finder);
// the map will be already filled inside the populate
return map;
}
}