
com.venky.swf.db.MySqlHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swf-db Show documentation
Show all versions of swf-db Show documentation
Succinct Web Framework - Db
The newest version!
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.venky.swf.db;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.List;
import java.util.TimeZone;
import com.venky.core.date.DateUtils;
import com.venky.core.util.Bucket;
import com.venky.swf.db.model.Count;
import com.venky.swf.db.model.Model;
import com.venky.swf.db.table.Table;
import com.venky.swf.exceptions.SWFTimeoutException;
import com.venky.swf.sql.DataManupulationStatement;
import com.venky.swf.sql.Select;
/**
*
* @author venky
*/
public class MySqlHelper extends JdbcTypeHelper{
@Override
public String getAutoIncrementInstruction() {
return (" BIGINT NOT NULL AUTO_INCREMENT ");
}
@Override
public String getCurrentTimeStampKW(){
return "CURRENT_TIMESTAMP";
}
@Override
public String getCurrentDateKW(){
return "CURRENT_DATE" ;
}
public boolean isQueryTimeoutException(SQLException ex){
if (!super.isQueryTimeoutException(ex)){
return ex.getClass().getName().endsWith("TimeoutException");
}
return false;
}
public boolean hasTransactionRolledBack(Throwable ex){
if (super.hasTransactionRolledBack(ex) || ex instanceof SWFTimeoutException){
return true;
}
return false;
}
@Override
public String getDefaultKW(TypeRef> ref,Object value) {
if (Boolean.class.isAssignableFrom(ref.getJavaClass()) || boolean.class.isAssignableFrom(ref.getJavaClass())) {
if ((Boolean)value){
return "b'1'";
}else {
return "b'0'";
}
}
return super.getDefaultKW(ref, value);
}
protected MySqlHelper() {
/**
* Specify size and scale for a data type only if the database accepts
* them during table creation
*/
registerjdbcSQLType(Boolean.class, new TypeRef(
java.sql.Types.BIT, "BIT", 0, 0,false,false,
new BooleanConverter()));
registerjdbcSQLType(boolean.class, new TypeRef(
java.sql.Types.BIT, "BIT", 0, 0,false,false,
new BooleanConverter()));
registerjdbcSQLType(Byte.class, new TypeRef(java.sql.Types.TINYINT,
"TINYINT", 0, 0, false,false,new ByteConverter()));
registerjdbcSQLType(byte.class, new TypeRef(java.sql.Types.TINYINT,
"TINYINT", 0, 0, false,false,new ByteConverter()));
registerjdbcSQLType(Short.class,
new TypeRef(java.sql.Types.SMALLINT, "SMALLINT", 0, 0,false,false,
new ShortConverter()));
registerjdbcSQLType(short.class,
new TypeRef(java.sql.Types.SMALLINT, "SMALLINT", 0, 0,false,false,
new ShortConverter()));
registerjdbcSQLType(Integer.class,
new TypeRef(java.sql.Types.INTEGER, "INTEGER", 0, 0,false,false,
new IntegerConverter()));
registerjdbcSQLType(int.class, new TypeRef(java.sql.Types.INTEGER,
"INTEGER", 0, 0, false,false, new IntegerConverter()));
registerjdbcSQLType(Long.class, new TypeRef(java.sql.Types.BIGINT,
"BIGINT", 0, 0,false,false, new LongConverter()));
registerjdbcSQLType(long.class, new TypeRef(java.sql.Types.BIGINT,
"BIGINT", 0, 0,false,false, new LongConverter()));
registerjdbcSQLType(BigDecimal.class, new TypeRef(
java.sql.Types.DECIMAL, "DECIMAL", 15, 10,false,false,
new BigDecimalConverter()));// also NUMERIC
registerjdbcSQLType(Float.class, new TypeRef(java.sql.Types.REAL,
"FLOAT", 10, 7,false,false, new FloatConverter()));
registerjdbcSQLType(float.class, new TypeRef(java.sql.Types.REAL,
"FLOAT", 10, 7, false,false,new FloatConverter()));
registerjdbcSQLType(Double.class, new TypeRef(
java.sql.Types.DOUBLE, "DOUBLE", 0, 0, false,false,new DoubleConverter())); // ALSO
// FLOAT
registerjdbcSQLType(double.class, new TypeRef(
java.sql.Types.DOUBLE, "DOUBLE", 0, 0, false,false,new DoubleConverter())); // ALSO
registerjdbcSQLType(Bucket.class, new TypeRef(
java.sql.Types.DOUBLE, "DOUBLE", 0, 0, false,false,new BucketConverter())); // ALSO
// FLOAT
registerjdbcSQLType(Date.class, new TypeRef(java.sql.Types.DATE,
"DATE", 0, 0, true, true, new DateConverter(DateUtils.ISO_DATE_FORMAT_STR, TimeZone.getDefault())));
registerjdbcSQLType(Time.class, new TypeRef
© 2015 - 2025 Weber Informatics LLC | Privacy Policy