Android Open Source - jepldroid J E P L Prepared Statement S Q L Droid Impl






From Project

Back to project page jepldroid.

License

The source code is released under:

Apache License

If you think the Android project jepldroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package jepl.impl.nonjta.android;
//from  w  ww. ja  v  a2s .co m
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import jepl.JEPLException;
import jepl.impl.JEPLDALImpl;
import jepl.impl.JEPLPreparedStatementImpl;

public class JEPLPreparedStatementSQLDroidImpl extends JEPLPreparedStatementImpl 
{
  public JEPLPreparedStatementSQLDroidImpl(JEPLNonJTAConnectionSQLDroidImpl jcon,JEPLDALImpl dal,PreparedStatement stmt,String key) throws SQLException
  {
    super(jcon,dal,stmt,key);
  }
  
  public JEPLNonJTAConnectionSQLDroidImpl getJEPLNonJTAConnectionSQLDroid()
  {
    return (JEPLNonJTAConnectionSQLDroidImpl)jcon;
  }
  
  @Override
    protected void setObject(PreparedStatement stmt,int column,Object param) throws SQLException
    {
        // Llamamos al mtodo ms apropiado de acuerdo con el tipo de datos esperado
      // algunos de ellos no estn implementados pero los llamamos por sistema
      // Obviamente no puede ser un primitivo
        
        if (param == null)
        {
          stmt.setNull(column, -1); // El tipo da igual
          return;
        }
        
      Class<?> targetType = param.getClass();
      
        if (Number.class.isAssignableFrom(targetType))
        {
            if (targetType.equals(Byte.class))
                stmt.setByte(column,(Byte)param);
            else if (targetType.equals(Short.class))
              stmt.setShort(column,(Short)param);
            else if (targetType.equals(Integer.class))
              stmt.setInt(column,(Integer)param);
            else if (targetType.equals(Long.class))
              stmt.setLong(column,(Long)param);
            else if (targetType.equals(Float.class))
              stmt.setFloat(column,(Float)param);
            else if (targetType.equals(Double.class))
              stmt.setDouble(column,(Double)param);
            else if (targetType.equals(BigDecimal.class))
                stmt.setBigDecimal(column,(BigDecimal)param);
            else
              throw new JEPLException("Not supported data type:" + targetType); // Puede ser BigInteger
        }
        else if (targetType.equals(Boolean.class))
          stmt.setBoolean(column,(Boolean)param);
        else if (targetType.equals(Character.class))
          stmt.setString(column,new String(param.toString()));
        else if (targetType.equals(String.class))
          stmt.setString(column,(String)param);
        else if (targetType.equals(java.sql.Date.class))
          stmt.setDate(column,(java.sql.Date)param);
        else if (targetType.equals(java.sql.Time.class))
          stmt.setTime(column,(java.sql.Time)param);
        else if (targetType.equals(java.sql.Timestamp.class))
          stmt.setTimestamp(column,(java.sql.Timestamp)param);
        else
          throw new JEPLException("Not supported data type:" + targetType);
   
    }  
    
    @Override
    public ResultSet executeUpdateGetGeneratedKeys(String sqlJDBC) throws Exception
    {   
    // SQLDroid no soporta getGeneratedKeys
        PreparedStatement stmt = getPreparedStatement();
        stmt.executeUpdate();
        // No chequeamos que el resultado de executeUpdate() sea 1 pues SQLDroid siempre devuelve 0
    // nos tenemos que fiar.
    Statement stmtLastId = jcon.getConnection().createStatement();
    ResultSet res = stmtLastId.executeQuery("SELECT LAST_INSERT_ROWID()");
    // La alternativa sera: select max(id) from sometable
    // pero exige conocer el nombre del atributo id y la tabla
    return res;
    }    
    
    @Override
    public void moveResultSetAbsolutePosition(ResultSet result,int position) throws SQLException
    {
      getJEPLNonJTAConnectionSQLDroid().moveResultSetAbsolutePosition(result,position);
    }    
    
    @Override    
    public boolean isExecuteUpdateReturnCorrect()
    {
      // executeUpdate() siempre devuelve 0 en SQLDroid
      return false;
    }    
}




Java Source Code List

com.innowhere.jepldroidtest.JEPLDroidTestActivity.java
jepl.JEPLBootNonJTA.java
jepl.JEPLBootRoot.java
jepl.JEPLBoot.java
jepl.JEPLCachedResultSet.java
jepl.JEPLConnectionListener.java
jepl.JEPLConnection.java
jepl.JEPLDALQuery.java
jepl.JEPLDAL.java
jepl.JEPLDAOQuery.java
jepl.JEPLDAO.java
jepl.JEPLDataSource.java
jepl.JEPLException.java
jepl.JEPLListener.java
jepl.JEPLNonJTADataSource.java
jepl.JEPLParameter.java
jepl.JEPLPreparedStatementListener.java
jepl.JEPLPreparedStatement.java
jepl.JEPLResultSetDALListener.java
jepl.JEPLResultSetDAOListenerDefault.java
jepl.JEPLResultSetDAOListener.java
jepl.JEPLResultSetDAO.java
jepl.JEPLResultSet.java
jepl.JEPLRowBeanMapper.java
jepl.JEPLStatement.java
jepl.JEPLTask.java
jepl.JEPLTransactionPropagation.java
jepl.JEPLTransaction.java
jepl.JEPLTransactionalJTA.java
jepl.JEPLTransactionalNonJTA.java
jepl.JEPLUserData.java
jepl.impl.JEPLBootImpl.java
jepl.impl.JEPLBootRootImpl.java
jepl.impl.JEPLConnectionImpl.java
jepl.impl.JEPLCurrentTransactionImpl.java
jepl.impl.JEPLDALDefaultImpl.java
jepl.impl.JEPLDALImpl.java
jepl.impl.JEPLDAOImpl.java
jepl.impl.JEPLDataSourceImpl.java
jepl.impl.JEPLListenerListImpl.java
jepl.impl.JEPLPreparedStatementDefaultImpl.java
jepl.impl.JEPLPreparedStatementImpl.java
jepl.impl.JEPLStatementImpl.java
jepl.impl.JEPLTaskExecContextImpl.java
jepl.impl.JEPLTaskExecContextInConnectionImpl.java
jepl.impl.JEPLTaskOneExecWithConnectionImpl.java
jepl.impl.JEPLTaskOneExecWithConnectionWrapperImpl.java
jepl.impl.JEPLTaskOneExecutionImpl.java
jepl.impl.JEPLTaskOneExecutionWrapperImpl.java
jepl.impl.JEPLUserDataMonoThreadImpl.java
jepl.impl.JEPLUserDataMultiThreadImpl.java
jepl.impl.JEPLUtilImpl.java
jepl.impl.lex.Cursor.java
jepl.impl.lex.Identifier.java
jepl.impl.lex.JDBCParamStandardToken.java
jepl.impl.lex.JDBCParamToken.java
jepl.impl.lex.JDBCParamWithNameToken.java
jepl.impl.lex.JDBCParamWithNumberToken.java
jepl.impl.lex.OtherCharToken.java
jepl.impl.lex.SourceCode.java
jepl.impl.lex.Space.java
jepl.impl.lex.StringDoubleQuote.java
jepl.impl.lex.StringLiteral.java
jepl.impl.lex.StringSimpleQuote.java
jepl.impl.lex.TestSourceCode.java
jepl.impl.lex.TokenFilter.java
jepl.impl.lex.Token.java
jepl.impl.nonjta.JEPLBootNonJTAImpl.java
jepl.impl.nonjta.JEPLCurrentTransactionNonJTAImpl.java
jepl.impl.nonjta.JEPLNonJTAConnectionDefaultImpl.java
jepl.impl.nonjta.JEPLNonJTAConnectionImpl.java
jepl.impl.nonjta.JEPLNonJTADataSourceDefaultImpl.java
jepl.impl.nonjta.JEPLNonJTADataSourceImpl.java
jepl.impl.nonjta.JEPLTaskExecContextInConnectionNonJTAImpl.java
jepl.impl.nonjta.android.JEPLNonJTAConnectionSQLDroidImpl.java
jepl.impl.nonjta.android.JEPLNonJTADataSourceAndroidImpl.java
jepl.impl.nonjta.android.JEPLPreparedStatementSQLDroidImpl.java
jepl.impl.query.JEPLCachedResultSetImpl.java
jepl.impl.query.JEPLDALQueryImpl.java
jepl.impl.query.JEPLDAOQueryImpl.java
jepl.impl.query.JEPLParameterDecImpl.java
jepl.impl.query.JEPLParameterDecWithNameImpl.java
jepl.impl.query.JEPLParameterDecWithNumberImpl.java
jepl.impl.query.JEPLParameterImpl.java
jepl.impl.query.JEPLParameterValueImpl.java
jepl.impl.query.JEPLParameterValueNamedImpl.java
jepl.impl.query.JEPLParameterWithNameImpl.java
jepl.impl.query.JEPLParameterWithNumberImpl.java
jepl.impl.query.JEPLPropertyDescriptorImpl.java
jepl.impl.query.JEPLPropertyDescriptorJavaBeansImpl.java
jepl.impl.query.JEPLQueryParsedCacheImpl.java
jepl.impl.query.JEPLQueryParsedImpl.java
jepl.impl.query.JEPLResultSetBeanInfo.java
jepl.impl.query.JEPLResultSetDAOImpl.java
jepl.impl.query.JEPLResultSetDAOIteratorImpl.java
jepl.impl.query.JEPLResultSetDAOListenerDefaultImpl.java
jepl.impl.query.JEPLResultSetDefaultImpl.java
jepl.impl.query.JEPLResultSetImpl.java