Java Code Examples for java.sql.Types

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project AdminCmd, under directory /src/main/java/be/Balor/Player/sql/.

Source file: SQLPlayer.java

  21 
vote

@Override public void setLastLocation(final Location loc){
  lastLoc=loc;
synchronized (UPDATE_LASTLOC) {
    try {
      UPDATE_LASTLOC.clearParameters();
      if (loc != null) {
        UPDATE_LASTLOC.setString(1,loc.getWorld().getName());
        UPDATE_LASTLOC.setDouble(2,loc.getX());
        UPDATE_LASTLOC.setDouble(3,loc.getY());
        UPDATE_LASTLOC.setDouble(4,loc.getZ());
        UPDATE_LASTLOC.setFloat(5,loc.getYaw());
        UPDATE_LASTLOC.setFloat(6,loc.getPitch());
      }
 else {
        UPDATE_LASTLOC.setNull(1,Types.VARCHAR);
        UPDATE_LASTLOC.setNull(2,Types.DOUBLE);
        UPDATE_LASTLOC.setNull(3,Types.DOUBLE);
        UPDATE_LASTLOC.setNull(4,Types.DOUBLE);
        UPDATE_LASTLOC.setNull(5,Types.FLOAT);
        UPDATE_LASTLOC.setNull(6,Types.FLOAT);
      }
      UPDATE_LASTLOC.setLong(7,id);
synchronized (UPDATE_LASTLOC.getConnection()) {
        UPDATE_LASTLOC.executeUpdate();
      }
    }
 catch (    final SQLException e) {
      ACLogger.severe("Problem with updating lastLoc in the DB",e);
    }
  }
}
 

Example 2

From project accesointeligente, under directory /src/org/accesointeligente/server/.

Source file: EnumUserType.java

  19 
vote

public void nullSafeSet(PreparedStatement preparedStatement,Object value,int index) throws HibernateException, SQLException {
  if (null == value) {
    preparedStatement.setNull(index,Types.VARCHAR);
  }
 else {
    preparedStatement.setString(index,((Enum)value).name());
  }
}
 

Example 3

From project Aion-Extreme, under directory /AE-go_DataPack/loginserver/data/scripts/system/database/mysql5/.

Source file: MySQL5BannedIpDAO.java

  19 
vote

/** 
 * {@inheritDoc}
 */
@Override public boolean insert(final BannedIP bannedIP){
  boolean insert=DB.insertUpdate("INSERT INTO ban_ip(mask, time_end) VALUES (?, ?)",new IUStH(){
    @Override public void handleInsertUpdate(    PreparedStatement preparedStatement) throws SQLException {
      preparedStatement.setString(1,bannedIP.getMask());
      if (bannedIP.getTimeEnd() == null)       preparedStatement.setNull(2,Types.TIMESTAMP);
 else       preparedStatement.setTimestamp(2,bannedIP.getTimeEnd());
      preparedStatement.execute();
    }
  }
);
  if (!insert)   return false;
  final BannedIP result=new BannedIP();
  DB.select("SELECT * FROM ban_ip WHERE mask = ?",new ParamReadStH(){
    @Override public void setParams(    PreparedStatement preparedStatement) throws SQLException {
      preparedStatement.setString(1,bannedIP.getMask());
    }
    @Override public void handleRead(    ResultSet resultSet) throws SQLException {
      resultSet.next();
      result.setId(resultSet.getInt("id"));
      result.setMask(resultSet.getString("mask"));
      result.setTimeEnd(resultSet.getTimestamp("time_end"));
    }
  }
);
  return true;
}
 

Example 4

From project Amoeba-for-Aladdin, under directory /src/java/com/meidusa/amoeba/aladdin/handler/.

Source file: StringTypeHandler.java

  19 
vote

public boolean needHandle(int jdbcType){
switch (jdbcType) {
case Types.LONGVARCHAR:
case Types.VARCHAR:
    return true;
default :
  return false;
}
}
 

Example 5

From project ANNIS, under directory /annis-service/src/main/java/annis/sqlgen/.

Source file: AbstractSolutionKey.java

  19 
vote

public Object getNodeId(ResultSet resultSet,TableAccessStrategy tableAccessStrategy){
  try {
    String idAlias=tableAccessStrategy.columnName(NODE_TABLE,getIdColumnName());
    int idAliasIdx=resultSet.findColumn(idAlias);
    if (resultSet.getMetaData() != null) {
switch (resultSet.getMetaData().getColumnType(idAliasIdx)) {
case Types.VARCHAR:
        return resultSet.getString(idAliasIdx);
case Types.BIGINT:
      return resultSet.getLong(idAliasIdx);
case Types.INTEGER:
    return resultSet.getInt(idAliasIdx);
}
}
return resultSet.getObject(idAliasIdx);
}
 catch (SQLException e) {
log.error("Exception thrown while retrieving node ID",e);
throw new IllegalStateException("Could not retrieve node ID from JDBC results set",e);
}
}
 

Example 6

From project Arecibo, under directory /alert-data-support/src/main/java/com/ning/arecibo/alert/confdata/dao/.

Source file: FixBrokenMySQLEnumSupportArgumentFactory.java

  19 
vote

public void apply(final int position,final PreparedStatement statement,final StatementContext ctx) throws SQLException {
  if (value != null) {
    statement.setString(position,value);
  }
 else {
    statement.setNull(position,Types.VARCHAR);
  }
}
 

Example 7

From project ATHENA, under directory /core/apa/src/main/java/org/fracturedatlas/athena/apa/impl/.

Source file: LongUserType.java

  19 
vote

public void nullSafeSet(PreparedStatement statement,Object value,int index) throws HibernateException, SQLException {
  if (value == null) {
    statement.setNull(index,Types.NULL);
  }
 else {
    Long id=(Long)value;
    statement.setLong(index,id);
  }
}
 

Example 8

From project baseunits, under directory /src/main/java/jp/xet/baseunits/mirage/.

Source file: CalendarDateValueType.java

  19 
vote

@Override public void set(Class<? extends CalendarDate> type,PreparedStatement stmt,CalendarDate value,int index) throws SQLException {
  if (value == null) {
    stmt.setNull(index,Types.DATE);
  }
 else {
    stmt.setString(index,value.toString("yyyy-MM-dd"));
  }
}
 

Example 9

From project Bio-PEPA, under directory /uk.ac.ed.inf.biopepa.ui/lib/opencsv-2.1/examples/.

Source file: MockResultSet.java

  19 
vote

public static MockResultSetMetaData getDefaultMetaData(){
  MockResultSetMetaData meta=new MockResultSetMetaData();
  meta.addColumn(new MockColumn(Types.VARCHAR,"VarcharColumn"));
  meta.addColumn(new MockColumn(Types.BOOLEAN,"BooleanColumn"));
  meta.addColumn(new MockColumn(Types.INTEGER,"IntegerColumn"));
  meta.addColumn(new MockColumn(Types.DOUBLE,"DoubleColumn"));
  meta.addColumn(new MockColumn(Types.TIME,"TimeColumn"));
  meta.addColumn(new MockColumn(Types.DATE,"DateColumn"));
  meta.addColumn(new MockColumn(Types.CHAR,"CharColumn"));
  meta.addColumn(new MockColumn(Types.JAVA_OBJECT,"JavaObjectColumn"));
  meta.addColumn(new MockColumn(Types.TIMESTAMP,"TimeStampColumn"));
  meta.addColumn(new MockColumn(Types.NUMERIC,"NumericColumn"));
  meta.addColumn(new MockColumn(Types.DECIMAL,"DecimalColumn"));
  meta.addColumn(new MockColumn(Types.BIGINT,"BigIntegerColumn"));
  return meta;
}
 

Example 10

From project BookmarksPortlet, under directory /src/main/java/edu/wisc/my/portlets/bookmarks/dao/hibernate/types/.

Source file: EnumUserType.java

  19 
vote

public void nullSafeSet(PreparedStatement preparedStatement,Object value,int index) throws HibernateException, SQLException {
  if (null == value) {
    preparedStatement.setNull(index,Types.VARCHAR);
  }
 else {
    preparedStatement.setString(index,((Enum)value).name());
  }
}
 

Example 11

From project CIShell, under directory /core/org.cishell.utilities/src/org/cishell/utilities/database/.

Source file: Column.java

  19 
vote

private static Map<Integer,String> constructTypeMap(){
  Map<Integer,String> typeMap=new HashMap<Integer,String>(){
{
      put(Types.CHAR,"char");
      put(Types.DATE,"date");
      put(Types.DOUBLE,"double");
      put(Types.FLOAT,"float");
      put(Types.INTEGER,"integer");
      put(Types.SMALLINT,"smallint");
      put(Types.TIME,"time");
      put(Types.VARCHAR,"varchar");
    }
  }
;
  return Collections.unmodifiableMap(typeMap);
}
 

Example 12

From project CloudReports, under directory /src/main/java/cloudreports/database/.

Source file: SQLiteDialect.java

  19 
vote

public SQLiteDialect(){
  super();
  registerColumnType(Types.BIT,"integer");
  registerColumnType(Types.TINYINT,"tinyint");
  registerColumnType(Types.SMALLINT,"smallint");
  registerColumnType(Types.INTEGER,"integer");
  registerColumnType(Types.BIGINT,"bigint");
  registerColumnType(Types.FLOAT,"float");
  registerColumnType(Types.REAL,"real");
  registerColumnType(Types.DOUBLE,"double");
  registerColumnType(Types.NUMERIC,"numeric");
  registerColumnType(Types.DECIMAL,"decimal");
  registerColumnType(Types.CHAR,"char");
  registerColumnType(Types.VARCHAR,"varchar");
  registerColumnType(Types.LONGVARCHAR,"longvarchar");
  registerColumnType(Types.DATE,"date");
  registerColumnType(Types.TIME,"time");
  registerColumnType(Types.TIMESTAMP,"timestamp");
  registerColumnType(Types.BINARY,"blob");
  registerColumnType(Types.VARBINARY,"blob");
  registerColumnType(Types.LONGVARBINARY,"blob");
  registerColumnType(Types.BLOB,"blob");
  registerColumnType(Types.CLOB,"clob");
  registerColumnType(Types.BOOLEAN,"integer");
  registerFunction("concat",new VarArgsSQLFunction(Hibernate.STRING,"","||",""));
  registerFunction("mod",new SQLFunctionTemplate(Hibernate.INTEGER,"?1 % ?2"));
  registerFunction("substr",new StandardSQLFunction("substr",Hibernate.STRING));
  registerFunction("substring",new StandardSQLFunction("substr",Hibernate.STRING));
}
 

Example 13

From project codjo-broadcast, under directory /codjo-broadcast-common/src/main/java/net/codjo/broadcast/common/columns/.

Source file: FileColumnFactory.java

  19 
vote

public FileColumnGenerator newFileColumnGenerator(final ResultSet rs,final FieldInfo fieldInfo,final int sqlType,final FunctionHolder funcs) throws SQLException {
  String columnName=rs.getString(COLUMN_FIELD_NAME);
  boolean isBreakField=rs.getBoolean(BREAK_FIELD_NAME);
  GeneratorExpression expression=newExpression(rs,sqlType,funcs);
  Padder padder=newPadder(rs);
switch (sqlType) {
case Types.VARCHAR:
case Types.CHAR:
    return new StringColumnGenerator(fieldInfo,columnName,padder,expression,isBreakField);
case Types.DATE:
case Types.TIMESTAMP:
  String dateFormat=rs.getString(DATE_FORMAT_FIELD_NAME);
return new DateColumnGenerator(fieldInfo,columnName,dateFormat,padder,expression,isBreakField);
case Types.DOUBLE:
case Types.INTEGER:
case Types.DECIMAL:
case Types.NUMERIC:
String decimalSeparator=rs.getString(DECIMAL_SEPARATOR_FIELD_NAME);
String numberFormat=rs.getString(NUMBER_FORMAT_FIELD_NAME);
return new NumberColumnGenerator(fieldInfo,columnName,decimalSeparator,numberFormat,padder,expression,isBreakField);
case Types.BIT:
return new BooleanColumnGenerator(fieldInfo,columnName,padder,expression,isBreakField);
default :
throw new IllegalArgumentException("Type SQL inconnu : " + sqlType);
}
}
 

Example 14

From project codjo-control, under directory /codjo-control-common/src/main/java/net/codjo/control/common/util/.

Source file: SQLUtil.java

  19 
vote

/** 
 * Construit la table des correspondances type JAVA vers type SQL. <p> http://java.sun.com/docs/books/tutorial/jdbc/basics/_retrievingTable.html#table2 </p>
 * @return map
 */
private static void buildSqlToClass(){
  classToSql.put(byte.class,Types.TINYINT);
  classToSql.put(short.class,Types.SMALLINT);
  classToSql.put(int.class,Types.INTEGER);
  classToSql.put(Integer.class,Types.INTEGER);
  classToSql.put(long.class,Types.BIGINT);
  classToSql.put(float.class,Types.REAL);
  classToSql.put(double.class,Types.FLOAT);
  classToSql.put(double.class,Types.DOUBLE);
  classToSql.put(java.math.BigDecimal.class,Types.NUMERIC);
  classToSql.put(boolean.class,Types.BIT);
  classToSql.put(Boolean.class,Types.BIT);
  classToSql.put(String.class,Types.CHAR);
  classToSql.put(String.class,Types.VARCHAR);
  classToSql.put(java.sql.Date.class,Types.DATE);
  classToSql.put(java.sql.Time.class,Types.TIME);
  classToSql.put(java.sql.Timestamp.class,Types.TIMESTAMP);
}
 

Example 15

From project codjo-data-process, under directory /codjo-data-process-gui/src/main/java/net/codjo/dataprocess/gui/repository/.

Source file: ArgumentsTable.java

  19 
vote

public void initSqlFormatStuff(){
  Map<Integer,String> traductTable=new HashMap<Integer,String>();
  traductTable.put(Types.VARCHAR,"Varchar");
  traductTable.put(Types.NUMERIC,"Numeric");
  traductTable.put(Types.DATE,"Date");
  traductTable.put(Types.TIMESTAMP,"TimeStamp");
  GenericRenderer renderer=new GenericRenderer(traductTable);
  JComboBox typeComboBox=new JComboBox(traductTable.keySet().toArray());
  typeComboBox.setRenderer(renderer);
  setCellRenderer(NOM.columnPosition,new MyTableCellRenderer());
  setCellRenderer(VALEUR.columnPosition,new MyTableCellRenderer());
  setCellRenderer(POSITION.columnPosition,new MyTableCellRenderer());
  setCellRenderer(TYPE.columnPosition,renderer);
  setCellEditor(TYPE.columnPosition,new DefaultCellEditor(typeComboBox));
}
 

Example 16

From project codjo-imports, under directory /codjo-imports-common/src/main/java/net/codjo/imports/common/.

Source file: FieldFactory.java

  19 
vote

/** 
 * Converti un type de champ importable en type Sql (java.sql.Types).
 * @param fieldType un type de champ
 * @return un type sql
 * @throws IllegalArgumentException Si le type n'est pas connu
 */
public static int convertFieldTypeToSqlType(char fieldType){
switch (fieldType) {
case CLASS_FIELD:
case STRING_FIELD:
    return Types.VARCHAR;
case DATE_FIELD:
  return Types.DATE;
case NUMERIC_FIELD:
return Types.NUMERIC;
case BOOLEAN_FIELD:
return Types.BIT;
default :
throw new IllegalArgumentException("Type de champ non importable : " + fieldType);
}
}
 

Example 17

From project codjo-segmentation, under directory /codjo-segmentation-server/src/main/java/net/codjo/segmentation/server/plugin/.

Source file: ExpressionCompilerCommand.java

  19 
vote

private void executeImpl(CommandQuery query) throws CompilationException, SQLException, CyclicVariableException, UnknownVariableException, InvalidExpressionException {
  String expressionToCompile=query.getArgumentString("expression");
  String familyId=query.getArgumentString("familyId");
  expressionToCompile=CompilationUtil.replaceVariables(expressionToCompile,getContext().getConnection());
  XmlFamilyPreference familyPreference=contextManager.getFamilyPreference(familyId);
  if (familyPreference.getTableMetaData() == null) {
    TableMetaData tableMetaData=TableMetaData.create(familyPreference.getDestinationTable(),getContext().getConnection());
    familyPreference.setTableMetaData(tableMetaData);
  }
  ExpressionManager expressionManager=new ExpressionManager(familyPreference.createFunctionManager());
  expressionManager.setExpressionManagerName(expressionToCompile);
  Map<String,Integer> varColumn=new HashMap<String,Integer>();
  expressionManager.setVarColumn(varColumn);
  findVariablesColumnType(expressionToCompile,familyPreference,varColumn);
  Map<String,Integer> sourceColumn=new HashMap<String,Integer>();
  expressionManager.setSourceColumn(sourceColumn);
  Map<String,Integer> destColumn=new HashMap<String,Integer>();
  expressionManager.setDestColumn(destColumn);
  FindUses findUses=new FindUses();
  findUses.add(expressionToCompile);
  Collection usedSourceColumns=findUses.buildReport().getUsedSourceColumns();
  if (!usedSourceColumns.isEmpty()) {
    findSourceColumnType(familyPreference,sourceColumn,new ArrayList<String>(usedSourceColumns));
  }
  destColumn.put("DEST_FIELD",Types.BIT);
  expressionManager.add("DEST_FIELD",expressionToCompile);
  expressionManager.compileExpressions();
}
 

Example 18

From project codjo-shipment, under directory /src/test/java/net/codjo/shipment/.

Source file: MonoFormattedDataFieldTest.java

  19 
vote

/** 
 * A unit test for JUnit
 * @exception Exception Description of the Exception
 */
public void test_convertField_FieldNotFound() throws Exception {
  Translator translator=DataShipmentHome.getNewTranslator(Types.DATE,null,"dd/MM/yy");
  MonoFormattedDataField dataField=new MonoFormattedDataField("COL_B","COL_B",translator);
  Object[][] matrix={{"COL_A","COL_C"},{"b",123}};
  ResultSet rs=new FakeResultSet(matrix).getStub();
  rs.next();
  try {
    dataField.convertField(rs);
    fail("Le test doit echouer ! la colonne COL_B n'existe pas");
  }
 catch (  SQLException ex) {
    ;
  }
}
 

Example 19

From project codjo-standalone-common, under directory /src/main/java/net/codjo/operation/imports/.

Source file: FieldImportHome.java

  19 
vote

/** 
 * Creation d'un nouveau FieldImport.
 * @param destFieldName Description of the Parameter
 * @param destFieldType Description of the Parameter
 * @param decimalSeparator DECIMAL_SEPARATOR
 * @param inputDateFormat INPUT_DATE_FORMAT
 * @return un nouveau FieldImport
 * @throws Error TODO
 */
public static FieldImport newFieldImport(String destFieldName,int destFieldType,String decimalSeparator,String inputDateFormat){
  FieldImport fieldImport;
switch (destFieldType) {
case Types.CHAR:
case Types.VARCHAR:
    fieldImport=new StringFieldImport(destFieldName);
  break;
case Types.BIT:
fieldImport=new BooleanFieldImport(destFieldName);
break;
case Types.INTEGER:
fieldImport=new NumberFieldImport(destFieldName);
break;
case Types.NUMERIC:
if (decimalSeparator == null) {
fieldImport=new NumberFieldImport(destFieldName);
}
 else {
fieldImport=new NumberFieldImport(destFieldName,decimalSeparator.charAt(0));
}
break;
case Types.DATE:
if (dateFormats == null) {
initDateFormats();
}
fieldImport=new DateFieldImport(destFieldName,getInputDateFormat(inputDateFormat));
break;
default :
throw new Error("Type de champ inconnu : '" + destFieldType + "'");
}
return fieldImport;
}
 

Example 20

From project components-ness-jdbi, under directory /src/main/java/com/nesscomputing/jdbi/argument/.

Source file: DateTimeArgument.java

  19 
vote

@Override public void apply(final int position,final PreparedStatement statement,final StatementContext ctx) throws SQLException {
  if (dateTime == null) {
    statement.setNull(position,Types.TIMESTAMP);
  }
 else {
    final long millis=dateTime.getMillis();
    statement.setTimestamp(position,new Timestamp(millis));
  }
}
 

Example 21

From project core_1, under directory /src/com/iCo6/util/org/apache/commons/dbutils/.

Source file: QueryRunner.java

  19 
vote

/** 
 * Fill the <code>PreparedStatement</code> replacement parameters with  the given objects.
 * @param stmt PreparedStatement to fill
 * @param params Query replacement parameters; <code>null</code> is a validvalue to pass in.
 * @throws SQLException if a database access error occurs
 */
public void fillStatement(PreparedStatement stmt,Object... params) throws SQLException {
  if (params == null) {
    return;
  }
  ParameterMetaData pmd=null;
  if (!pmdKnownBroken) {
    pmd=stmt.getParameterMetaData();
    if (pmd.getParameterCount() < params.length) {
      throw new SQLException("Too many parameters: expected " + pmd.getParameterCount() + ", was given "+ params.length);
    }
  }
  for (int i=0; i < params.length; i++) {
    if (params[i] != null) {
      stmt.setObject(i + 1,params[i]);
    }
 else {
      int sqlType=Types.VARCHAR;
      if (!pmdKnownBroken) {
        try {
          sqlType=pmd.getParameterType(i + 1);
        }
 catch (        SQLException e) {
          pmdKnownBroken=true;
        }
      }
      stmt.setNull(i + 1,sqlType);
    }
  }
}
 

Example 22

From project core_5, under directory /exo.core.component.database/src/main/java/org/exoplatform/services/database/.

Source file: ReflectionMapper.java

  19 
vote

private Object getValue(int type,ResultSet resultSet,String name) throws Exception {
switch (type) {
case Types.CLOB:
    return loadClob(resultSet,name);
case Types.BLOB:
  return loadBlob(resultSet,name);
case Types.BINARY:
return loadBinary(resultSet,name);
default :
return resultSet.getObject(name.toUpperCase());
}
}
 

Example 23

From project elasticsearch-river-jdbc, under directory /src/main/java/org/elasticsearch/river/jdbc/.

Source file: SQLService.java

  19 
vote

private void bind(PreparedStatement pstmt,int i,Object value) throws SQLException {
  if (value == null) {
    pstmt.setNull(i,Types.VARCHAR);
  }
 else   if (value instanceof String) {
    String s=(String)value;
    if ("$now".equals(s)) {
      pstmt.setDate(i,new Date(new java.util.Date().getTime()));
    }
 else {
      pstmt.setString(i,(String)value);
    }
  }
 else   if (value instanceof Integer) {
    pstmt.setInt(i,((Integer)value).intValue());
  }
 else   if (value instanceof Long) {
    pstmt.setLong(i,((Long)value).longValue());
  }
 else   if (value instanceof BigDecimal) {
    pstmt.setBigDecimal(i,(BigDecimal)value);
  }
 else   if (value instanceof Date) {
    pstmt.setDate(i,(Date)value);
  }
 else   if (value instanceof Timestamp) {
    pstmt.setTimestamp(i,(Timestamp)value);
  }
 else   if (value instanceof Float) {
    pstmt.setFloat(i,((Float)value).floatValue());
  }
 else   if (value instanceof Double) {
    pstmt.setDouble(i,((Double)value).doubleValue());
  }
 else {
    pstmt.setObject(i,value);
  }
}
 

Example 24

From project empire-db, under directory /empire-db-codegen/src/main/java/org/apache/empire/db/codegen/.

Source file: CodeGenParser.java

  19 
vote

/** 
 * Adds DBColumn object to the given DBTable. The DBColumn is created from the given ResultSet
 */
private DBTableColumn addColumn(DBTable t,ResultSet rs) throws SQLException {
  String name=rs.getString("COLUMN_NAME");
  DataType empireType=getEmpireDataType(rs.getInt("DATA_TYPE"));
  double colSize=Double.parseDouble("" + rs.getInt("COLUMN_SIZE") + '.'+ rs.getInt("DECIMAL_DIGITS"));
  boolean required=false;
  String defaultValue=rs.getString("COLUMN_DEF");
  if (rs.getString("IS_NULLABLE").equalsIgnoreCase("NO"))   required=true;
  if (rs.getInt("DATA_TYPE") == Types.TIMESTAMP && defaultValue != null && defaultValue.equals("CURRENT_TIMESTAMP")) {
    required=false;
    defaultValue=null;
  }
  DataType originalType=empireType;
  ResultSetMetaData metaData=rs.getMetaData();
  int colCount=metaData.getColumnCount();
  String colName;
  for (int i=1; i <= colCount; i++) {
    colName=metaData.getColumnName(i);
    if ((colName.equalsIgnoreCase("IS_AUTOINCREMENT") && rs.getString(i).equalsIgnoreCase("YES")) || (colName.equals("TYPE_NAME") && rs.getString(i).matches(".*(?i:identity).*"))) {
      empireType=DataType.AUTOINC;
    }
  }
  log.info("\tCOLUMN:\t" + name + " ("+ empireType+ ")");
  DBTableColumn col=t.addColumn(name,empireType,colSize,required,defaultValue);
  if (empireType.equals(DataType.AUTOINC))   col.setAttribute("AutoIncDataType",originalType);
  return col;
}
 

Example 25

From project entando-core-engine, under directory /src/main/java/com/agiletec/aps/system/services/page/.

Source file: PageDAO.java

  19 
vote

private void valueAddShowletStatement(String pageCode,int pos,Showlet showlet,PreparedStatement stat) throws Throwable {
  stat.setString(1,pageCode);
  stat.setInt(2,pos);
  stat.setString(3,showlet.getType().getCode());
  if (!showlet.getType().isLogic()) {
    String config=null;
    if (null != showlet.getConfig()) {
      config=showlet.getConfig().toXml();
    }
    stat.setString(4,config);
  }
 else {
    stat.setNull(4,Types.VARCHAR);
  }
  stat.setString(5,showlet.getPublishedContent());
}
 

Example 26

From project fairy, under directory /fairy-core/src/main/java/com/mewmew/fairy/v1/book/.

Source file: Sql.java

  19 
vote

private static Object getObject(ResultSet rs,int i,Integer sqlType) throws SQLException {
switch (sqlType) {
case Types.CLOB:
    return rs.getString(i);
case Types.BLOB:
  return rs.getBytes(i);
case Types.TIMESTAMP:
return rs.getTimestamp(i);
case Types.VARBINARY:
case Types.BINARY:
byte[] b=rs.getBytes(i);
if (b != null) {
return new String(Hex.encodeHex(b));
}
return null;
default :
return rs.getObject(i);
}
}
 

Example 27

From project galaxy, under directory /src/co/paralleluniverse/galaxy/jdbc/.

Source file: SQLDB.java

  19 
vote

private void initDbTypes() throws SQLException {
  if (bigintType == null || smallintType == null || varbinaryType == null) {
    final Map<Integer,String> types=new HashMap<Integer,String>();
    final DatabaseMetaData dmd=conn.getMetaData();
    final ResultSet rs=dmd.getTypeInfo();
    while (rs.next()) {
      final int jdbcType=rs.getInt("DATA_TYPE");
      final String typeName=rs.getString("TYPE_NAME");
      types.put(jdbcType,typeName);
    }
    rs.close();
    if (bigintType == null)     bigintType=types.get(Types.BIGINT);
    if (smallintType == null)     smallintType=types.get(Types.SMALLINT);
    if (varbinaryType == null)     varbinaryType=types.get(Types.VARBINARY);
    LOG.debug("BIGINT type is: {}",bigintType);
    LOG.debug("SMALLINT type is: {}",smallintType);
    LOG.debug("VARBINARY type is: {}",varbinaryType);
  }
}
 

Example 28

From project ha-jdbc, under directory /src/main/java/net/sf/hajdbc/state/sql/.

Source file: SQLStateManager.java

  19 
vote

/** 
 * {@inheritDoc}
 * @see net.sf.hajdbc.Lifecycle#start()
 */
@Override public void start() throws Exception {
  this.driver=this.database.createConnectionSource();
  this.password=this.database.decodePassword(this.cluster.getDecoder());
  this.pool=this.poolFactory.createPool(new ConnectionPoolProvider(this));
  Connection connection=this.pool.take();
  boolean autoCommit=connection.getAutoCommit();
  connection.setAutoCommit(true);
  DatabaseMetaData metaData=connection.getMetaData();
  DialectFactory factory=ServiceLoaders.findService(new IdentifiableMatcher<DialectFactory>(this.database.getLocation()),DialectFactory.class);
  if (factory == null) {
    factory=ServiceLoaders.findService(DialectFactory.class);
  }
  Dialect dialect=factory.createDialect();
  DatabaseProperties properties=new LazyDatabaseProperties(new SimpleDatabaseMetaDataProvider(metaData),new DatabaseMetaDataSupportImpl(metaData,dialect),dialect);
  try {
    String enumType=properties.findType(0,Types.TINYINT,Types.SMALLINT,Types.INTEGER);
    String stringType=properties.findType(Database.ID_MAX_SIZE,Types.VARCHAR);
    String binaryType=properties.findType(this.cluster.getTransactionIdentifierFactory().size(),Types.BINARY);
    String varBinaryType=properties.findType(0,Types.VARBINARY);
    Statement statement=connection.createStatement();
    try {
      boolean batch=false;
      batch|=this.addBatch(statement,properties,STATE_TABLE,CREATE_STATE_SQL,stringType);
      batch|=this.addBatch(statement,properties,INVOCATION_TABLE,CREATE_INVOCATION_SQL,binaryType,enumType,enumType);
      batch|=this.addBatch(statement,properties,INVOKER_TABLE,CREATE_INVOKER_SQL,binaryType,enumType,stringType,varBinaryType);
      if (batch) {
        statement.executeBatch();
      }
    }
  finally {
      close(statement);
    }
    connection.setAutoCommit(autoCommit);
  }
  finally {
    this.pool.release(connection);
  }
}
 

Example 29

From project hibernate-ogm, under directory /hibernate-ogm-core/src/main/java/org/hibernate/ogm/type/.

Source file: EnumType.java

  19 
vote

private boolean isOrdinal(int paramType){
switch (paramType) {
case Types.INTEGER:
case Types.NUMERIC:
case Types.SMALLINT:
case Types.TINYINT:
case Types.BIGINT:
case Types.DECIMAL:
case Types.DOUBLE:
case Types.FLOAT:
    return true;
case Types.CHAR:
case Types.LONGVARCHAR:
case Types.VARCHAR:
  return false;
default :
throw new HibernateException("Unable to persist an Enum in a column of SQL Type: " + paramType);
}
}
 

Example 30

From project hibernate-tools, under directory /src/java/org/hibernate/cfg/reveng/.

Source file: JDBCToHibernateTypeHelper.java

  19 
vote

public static String getPreferredHibernateType(int sqlType,int size,int precision,int scale,boolean nullable,boolean generatedIdentifier){
  boolean returnNullable=nullable || generatedIdentifier;
  if ((sqlType == Types.DECIMAL || sqlType == Types.NUMERIC) && scale <= 0) {
    if (precision == 1) {
      return returnNullable ? Boolean.class.getName() : "boolean";
    }
 else     if (precision < 3) {
      return returnNullable ? Byte.class.getName() : "byte";
    }
 else     if (precision < 5) {
      return returnNullable ? Short.class.getName() : "short";
    }
 else     if (precision < 10) {
      return returnNullable ? Integer.class.getName() : "int";
    }
 else     if (precision < 19) {
      return returnNullable ? Long.class.getName() : "long";
    }
 else {
      return "big_decimal";
    }
  }
  if (sqlType == Types.CHAR && size > 1) {
    return "string";
  }
  String[] result=(String[])PREFERRED_HIBERNATETYPE_FOR_SQLTYPE.get(new Integer(sqlType));
  if (result == null) {
    return null;
  }
 else   if (returnNullable) {
    return result[1];
  }
 else {
    return result[0];
  }
}
 

Example 31

From project hiho, under directory /src/co/nubetech/apache/hadoop/.

Source file: DataDrivenDBInputFormat.java

  19 
vote

/** 
 * @return the DBSplitter implementation to use to divide the table/queryinto InputSplits.
 */
protected DBSplitter getSplitter(int sqlDataType){
switch (sqlDataType) {
case Types.NUMERIC:
case Types.DECIMAL:
    return new BigDecimalSplitter();
case Types.BIT:
case Types.BOOLEAN:
  return new BooleanSplitter();
case Types.INTEGER:
case Types.TINYINT:
case Types.SMALLINT:
case Types.BIGINT:
return new IntegerSplitter();
case Types.REAL:
case Types.FLOAT:
case Types.DOUBLE:
return new FloatSplitter();
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
return new TextSplitter();
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
return new DateSplitter();
default :
return null;
}
}
 

Example 32

From project ipdburt, under directory /iddb-cli/src/main/java/iddb/cli/command/.

Source file: BuildAliasIndex.java

  19 
vote

@Override protected void execute(OptionSet options) throws Exception {
  Connection conn=null;
  try {
    conn=ConnectionFactory.getConnection();
    System.out.println("Processing ...");
    Statement statement=conn.createStatement();
    ResultSet rs=statement.executeQuery("select id, nickname from alias");
    String sql="update alias set normalized = ?, textindex = ? where id = ? limit 1";
    conn.setAutoCommit(false);
    PreparedStatement pst=conn.prepareStatement(sql);
    while (rs.next()) {
      count++;
      String nickname=rs.getString("nickname");
      pst.setString(1,Functions.normalize(nickname));
      if (nickname.length() > Parameters.INDEX_MIN_LENGTH) {
        pst.setString(2,Functions.createNameIndex(nickname));
      }
 else {
        pst.setNull(2,Types.VARCHAR);
      }
      pst.setLong(3,rs.getLong("id"));
      pst.addBatch();
      if (count % 100 == 0) {
        System.out.println("Processed " + count + " id "+ rs.getLong("id"));
      }
      if (count % 500 == 0) {
        pst.executeBatch();
      }
    }
    pst.executeBatch();
    conn.commit();
    System.out.println("Processed: " + count);
    rs.close();
    statement.close();
  }
  finally {
    if (conn != null)     conn.close();
  }
}
 

Example 33

From project jAPS2, under directory /src/com/agiletec/aps/system/services/page/.

Source file: PageDAO.java

  19 
vote

private void valueAddShowletStatement(String pageCode,int pos,Showlet showlet,PreparedStatement stat) throws Throwable {
  stat.setString(1,pageCode);
  stat.setInt(2,pos);
  stat.setString(3,showlet.getType().getCode());
  if (!showlet.getType().isLogic()) {
    String config=null;
    if (null != showlet.getConfig()) {
      config=showlet.getConfig().toXml();
    }
    stat.setString(4,config);
  }
 else {
    stat.setNull(4,Types.VARCHAR);
  }
  stat.setString(5,showlet.getPublishedContent());
}
 

Example 34

From project java-maven-tests, under directory /src/pg-lock-test/src/main/java/com/alexshabanov/service/impl/dao/impl/oracle/.

Source file: UserAccountDaoOracleImpl.java

  19 
vote

private AddUserAccountProcedure(DataSource dataSource){
  procedure=new StoredProcedure(dataSource,"usr_api.p_add_user"){
  }
;
  procedure.setParameters(new SqlParameter[]{new SqlParameter("pr_user_name",Types.VARCHAR),new SqlParameter("pr_balance",Types.DECIMAL),new SqlOutParameter("pro_user_id",Types.INTEGER)});
  procedure.compile();
}
 

Example 35

From project jdbi, under directory /src/main/java/org/skife/jdbi/v2/.

Source file: BigDecimalArgument.java

  19 
vote

public void apply(int position,PreparedStatement statement,StatementContext ctx) throws SQLException {
  if (value != null) {
    statement.setBigDecimal(position,value);
  }
 else {
    statement.setNull(position,Types.NUMERIC);
  }
}
 

Example 36

From project jDcHub, under directory /jdchub-core/src/main/java/ru/sincore/db/.

Source file: SQLiteDialect.java

  19 
vote

public SQLiteDialect(){
  super();
  registerColumnType(Types.BIT,"integer");
  registerColumnType(Types.TINYINT,"tinyint");
  registerColumnType(Types.SMALLINT,"smallint");
  registerColumnType(Types.INTEGER,"integer");
  registerColumnType(Types.BIGINT,"bigint");
  registerColumnType(Types.FLOAT,"float");
  registerColumnType(Types.REAL,"real");
  registerColumnType(Types.DOUBLE,"double");
  registerColumnType(Types.NUMERIC,"numeric");
  registerColumnType(Types.DECIMAL,"decimal");
  registerColumnType(Types.CHAR,"char");
  registerColumnType(Types.VARCHAR,"varchar");
  registerColumnType(Types.LONGVARCHAR,"longvarchar");
  registerColumnType(Types.DATE,"date");
  registerColumnType(Types.TIME,"time");
  registerColumnType(Types.TIMESTAMP,"timestamp");
  registerColumnType(Types.BINARY,"blob");
  registerColumnType(Types.VARBINARY,"blob");
  registerColumnType(Types.LONGVARBINARY,"blob");
  registerColumnType(Types.BLOB,"blob");
  registerColumnType(Types.CLOB,"clob");
  registerColumnType(Types.BOOLEAN,"integer");
  registerFunction("concat",new VarArgsSQLFunction(Hibernate.STRING,"","||",""));
  registerFunction("mod",new SQLFunctionTemplate(Hibernate.INTEGER,"?1 % ?2"));
  registerFunction("substr",new StandardSQLFunction("substr",Hibernate.STRING));
  registerFunction("substring",new StandardSQLFunction("substr",Hibernate.STRING));
}
 

Example 37

From project jeppetto, under directory /jeppetto-test-support/src/main/java/org/iternine/jeppetto/testsupport/db/.

Source file: HsqlDatabase.java

  19 
vote

public DataType createDataType(int sqlType,String sqlTypeName) throws DataTypeException {
  if (sqlType == Types.BOOLEAN) {
    return DataType.BOOLEAN;
  }
  return super.createDataType(sqlType,sqlTypeName);
}