
com.venky.swf.db.PostgresqlHelper 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.core.util.ExceptionUtil;
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.sql.Select;
/**
*
* @author venky
*/
public class PostgresqlHelper extends JdbcTypeHelper{
@Override
public boolean isColumnNameAutoLowerCasedInDB(){
return true;
}
@Override
public boolean isQueryTimeoutSupported(){
return false;
}
public boolean isNoWaitSupported() {
return true;
}
@Override
public String getNoWaitLiteral(){
return " NOWAIT ";
}
@Override
public boolean isQueryTimeoutException(SQLException ex){
if (!hasTransactionRolledBack(ex)){
return ex.getSQLState().equals("55P03");
}
return super.isQueryTimeoutException(ex);
}
@Override
public boolean hasTransactionRolledBack(Throwable ex){
if (super.hasTransactionRolledBack(ex)){
return true;
}
SQLException sqlex = (SQLException) ExceptionUtil.getEmbeddedException(ex,SQLException.class);
if (sqlex != null && (sqlex.getSQLState().startsWith("08") || sqlex.getSQLState().startsWith("57"))){
return true;
}
return false;
}
@Override
public String getAutoIncrementInstruction() {
return (" BIGSERIAL ");
}
@Override
public String getCurrentTimeStampKW(){
return "now()";
}
public String getCurrentDateKW(){
return "('now'::text)::date";
}
@Override
public String getDefaultKW(TypeRef> ref,Object value){
if (String.class.isAssignableFrom(ref.getJavaClass())){
return "'" + value + "'::character varying";
}
return super.getDefaultKW(ref,value);
}
protected PostgresqlHelper() {
/**
* 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, "BOOLEAN", 0, 0,false,false,
new BooleanConverter()));
registerjdbcSQLType(boolean.class, new TypeRef(
java.sql.Types.BIT, "BOOLEAN", 0, 0,false,false,
new BooleanConverter()));
registerjdbcSQLType(Byte.class, new TypeRef(java.sql.Types.SMALLINT,
"SMALLINT", 0, 0, false,false,new ByteConverter()));
registerjdbcSQLType(byte.class, new TypeRef(java.sql.Types.SMALLINT,
"SMALLINT", 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", 14, 8,false,false,
new BigDecimalConverter()));// also NUMERIC
registerjdbcSQLType(BigDecimal.class, new TypeRef(
java.sql.Types.NUMERIC, "DECIMAL", 14, 8,false,false,
new BigDecimalConverter()));// also NUMERIC
registerjdbcSQLType(Float.class, new TypeRef(java.sql.Types.REAL,
"REAL", 0, 0, false,false,new FloatConverter()));
registerjdbcSQLType(float.class, new TypeRef(java.sql.Types.REAL,
"REAL", 0, 0, false,false,new FloatConverter()));
registerjdbcSQLType(Double.class, new TypeRef(
java.sql.Types.DOUBLE, "DOUBLE PRECISION", 0, 0, false,false,new DoubleConverter())); // ALSO
// FLOAT
registerjdbcSQLType(double.class, new TypeRef(
java.sql.Types.DOUBLE, "DOUBLE PRECISION", 0, 0, false,false,new DoubleConverter())); // ALSO
registerjdbcSQLType(Bucket.class, new TypeRef(
java.sql.Types.DOUBLE, "DOUBLE PRECISION", 0, 0, false,false,new BucketConverter())); // ALSO // FLOAT
registerjdbcSQLType(Date.class, new TypeRef(java.sql.Types.DATE,
"DATE", 0, 0, true ,false, new DateConverter(DateUtils.ISO_DATE_FORMAT_STR,TimeZone.getDefault())));
registerjdbcSQLType(Time.class, new TypeRef
© 2015 - 2025 Weber Informatics LLC | Privacy Policy