oracle.jdbc.OracleConnection Java Examples

The following examples show how to use oracle.jdbc.OracleConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OracleClientModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForBaseJdbc
public static ConnectionFactory connectionFactory(BaseJdbcConfig config, CredentialProvider credentialProvider, OracleConfig oracleConfig)
        throws SQLException
{
    Properties connectionProperties = new Properties();
    connectionProperties.setProperty(OracleConnection.CONNECTION_PROPERTY_INCLUDE_SYNONYMS, String.valueOf(oracleConfig.isSynonymsEnabled()));

    return new DriverConnectionFactory(
            new OracleDriver(),
            config.getConnectionUrl(),
            connectionProperties,
            credentialProvider);
}
 
Example #2
Source File: OracleDialect.java    From dalesbred with MIT License 5 votes vote down vote up
@Override
public void bindArgument(@NotNull PreparedStatement ps, int index, @Nullable Object value) throws SQLException {
    if (value instanceof SqlArray) {
        SqlArray array = (SqlArray) value;
        OracleConnection connection = ps.getConnection().unwrap(OracleConnection.class);
        ps.setArray(index, connection.createARRAY(array.getType(), array.getValues().toArray()));

    } else {
        super.bindArgument(ps, index, value);
    }
}
 
Example #3
Source File: OraUtil.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Convience method for ARRAY construction.
 * </p>
 */
public static ARRAY toARRAY(double[] doubles, String dataType,
    OracleConnection connection) throws SQLException
{
  ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(dataType,
      connection);
  return new ARRAY(descriptor, connection, doubles);
}
 
Example #4
Source File: OraUtil.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Convience method for ARRAY construction.
 */
public static ARRAY toARRAY(int[] ints, String dataType,
    OracleConnection connection) throws SQLException
{
  ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(dataType,
      connection);
  return new ARRAY(descriptor, connection, ints);
}
 
Example #5
Source File: OraUtil.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** Convenience method for STRUCT construction. */
public static STRUCT toSTRUCT(Datum[] attributes, String dataType,
    OracleConnection connection) throws SQLException
{
  //TODO: fix this to be more generic
  if (dataType.startsWith("*.")) {
    dataType = "DRA." + dataType.substring(2);
  }
  StructDescriptor descriptor = StructDescriptor.createDescriptor(dataType,
      connection);
  return new STRUCT(descriptor, connection, attributes);
}
 
Example #6
Source File: OraWriter.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Converts a {@link Geometry} into an Oracle MDSYS.SDO_GEOMETRY STRUCT.
 * <p>
 * Although invalid geometries may be encoded, and inserted into an Oracle DB,
 * this is not recommended. It is the responsibility of the user to ensure the
 * geometry is valid prior to calling this method. 
 * <p>
 * The SRID of the created SDO_GEOMETRY is the SRID defined explicitly for the writer, if any; 
 * otherwise it is the SRID contained in the input geometry. 
 * The caller should ensure the the SRID is valid for the intended use, 
 * since an incorrect SRID may cause indexing exceptions during an
 * INSERT or UPDATE.
 * <p>
 * When a null Geometry is passed in, a non-null, empty SDO_GEOMETRY STRUCT is returned.
 * Therefore, inserting the output of the writer into a
 * table will never result in NULL insertions.
 * To pass a NULL Geometry into an Oracle SDO_GEOMETRY-valued parameter using JDBC, use
 * <pre>
 * java.sql.CallableStatement.setNull(index, java.sql.Types.STRUCT, "MDSYS.SDO_GEOMETRY"). 
 * </pre>
 * 
 * @param geom the geometry to encode
 * @return a Oracle MDSYS.SDO_GEOMETRY STRUCT representing the geometry
 * @throws SQLException if an encoding error was encountered
 */
public STRUCT write(Geometry geom, OracleConnection connection) throws SQLException
{
  // this line may be problematic ... for v9i and later need to revisit.

  // was this ... does not work for 9i
  // if( geom == null) return toSTRUCT( null, DATATYPE );

  if (geom == null || geom.isEmpty() || geom.getCoordinate() == null)
    return createEmptySDOGeometry(connection);

  OraGeom oraGeom = createOraGeom(geom);
  
  STRUCT SDO_POINT = null;
  ARRAY SDO_ELEM_INFO = null;
  ARRAY SDO_ORDINATES = null;
  if (oraGeom.point == null) {
    SDO_ELEM_INFO = OraUtil.toARRAY(oraGeom.elemInfo, OraGeom.TYPE_ELEM_INFO_ARRAY,
        connection);
    SDO_ORDINATES = OraUtil.toARRAY(oraGeom.ordinates, OraGeom.TYPE_ORDINATE_ARRAY,
        connection);
  }
  else { // Point Optimization
    Datum data[] = new Datum[] { 
        OraUtil.toNUMBER(oraGeom.point[0]),
        OraUtil.toNUMBER(oraGeom.point[1]), 
        OraUtil.toNUMBER(oraGeom.point[2]), };
    SDO_POINT = OraUtil.toSTRUCT(data, OraGeom.TYPE_POINT_TYPE, connection);
  }
  
  NUMBER SDO_GTYPE = new NUMBER(oraGeom.gType);
  NUMBER SDO_SRID = oraGeom.srid == OraGeom.SRID_NULL ? null : new NUMBER(oraGeom.srid);
  
  Datum sdoGeometryComponents[] = new Datum[] { 
      SDO_GTYPE, 
      SDO_SRID, 
      SDO_POINT,
      SDO_ELEM_INFO, 
      SDO_ORDINATES };
  return OraUtil.toSTRUCT(sdoGeometryComponents, OraGeom.TYPE_GEOMETRY, connection);
}
 
Example #7
Source File: OraWriter.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
private STRUCT createEmptySDOGeometry(OracleConnection connection) throws SQLException {
	return OraUtil.toSTRUCT(new Datum[5], OraGeom.TYPE_GEOMETRY, connection);
}
 
Example #8
Source File: ConnectedTestCase.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static OracleConnection getOracleConnection(String server, String port, String sid, String userid, String pwd) throws SQLException {
    String url = "jdbc:oracle:thin:@"+server+":"+port+":"+sid;
    return (OracleConnection) openConnection( "oracle.jdbc.driver.OracleDriver", url, userid, pwd );
}
 
Example #9
Source File: OracleConnectImpl.java    From mcg-helper with Apache License 2.0 3 votes vote down vote up
@Override
   public List<DataRecord> getTableInfo(String tableName)  throws Exception {
       List<DataRecord> result = new ArrayList<DataRecord>();
       
       try {
        OracleConnection conn = (OracleConnection)dbConnect.getConnection();
        conn.setRemarksReporting(true);
        DatabaseMetaData dbmd = conn.getMetaData();
        ResultSet resultSet = dbmd.getTables(null, "%", tableName, new String[] { "TABLE" });
        
        ResultSet primaryKeyResultSet = dbmd.getPrimaryKeys(conn.getCatalog() ,null,tableName);  
        Map<String, String> primaryMap = new HashMap<String, String>();
        while(primaryKeyResultSet.next()){  
            String primaryKeyColumnName = primaryKeyResultSet.getString("COLUMN_NAME"); 
            primaryMap.put(primaryKeyColumnName, primaryKeyColumnName);
        }          
        
        while (resultSet.next()) {
            String existTableName = resultSet.getString("TABLE_NAME");
            if(existTableName.equals(tableName)){
                ResultSet rs = conn.getMetaData().getColumns(null, getSchema(conn), existTableName, "%");
                while(rs.next()){
                    DataRecord dataRecord = new DataRecord();
                    dataRecord.setTableField(rs.getString("COLUMN_NAME")); //字段名
                    dataRecord.setClassField(Tools.convertFieldName(dataRecord.getTableField()));//变量名
                    dataRecord.setComment(rs.getString("REMARKS")); //字段注释
                    dataRecord.setTableFieldType(rs.getString("TYPE_NAME")); //表字段数据类型
                    dataRecord.setMandatory(!rs.getBoolean("NULLABLE"));//非空
                    dataRecord.setLength(rs.getInt("COLUMN_SIZE"));//列大小
                    dataRecord.setPrecision(rs.getInt("DECIMAL_DIGITS"));//精度
                    dataRecord.setInclude(JDBCTypesUtils.jdbcTypeToJavaType(rs.getInt("DATA_TYPE")).getName()); ////java import类型
                    dataRecord.setDataType(Tools.splitLast(dataRecord.getInclude()));
                    
                    dataRecord.setPrimary(rs.getString("COLUMN_NAME").equalsIgnoreCase(primaryMap.get(rs.getString("COLUMN_NAME")))); //是否为主键
//                  rs.getString("COLUMN_DEF"); //默认值
//                  rs.getString("ORDINAL_POSITION")//序号
                    
                    if("NUMBER".equalsIgnoreCase(dataRecord.getTableFieldType()) && dataRecord.getPrecision() <= 0 ) {
                    	if(dataRecord.getLength() <= 4) {
                    		dataRecord.setDataType("Short");
                    		dataRecord.setInclude("java.lang.Short");
                    	} else if(dataRecord.getLength() <= 9){
                    		dataRecord.setDataType("Integer");
                    		dataRecord.setInclude("java.lang.Integer");
                    	} else if(dataRecord.getLength() <= 18){
                    		dataRecord.setDataType("Long");
                    		dataRecord.setInclude("java.lang.Long");
                    	}
                    }
                    result.add(dataRecord);
                }
                
            }
        }
        
       } catch (Exception e) {
       	logger.error("获取oracle表结构信息出错,异常信息:", e);
	} finally {
       	dbConnect.freeConnection();
       }
       return result;
   }
 
Example #10
Source File: OraWriter.java    From jts with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Creates a writer using a valid Oracle connection. 
 * <p>
 * To simplify connection resource handling, the connection should be
 * provided in the {@link #write(Geometry, OracleConnection)} method.
 * Accordingly, this constructor has been deprecated.
 * <p>
 * The connection should have sufficient privileges to view the description of the MDSYS.SDO_GEOMETRY type.
 * <p>
 * The output dimension will be whatever the dimension of the input is.
 * 
 * @param con a valid Oracle connection
 * @deprecated use {@link #OraWriter()} instead
 */
public OraWriter(OracleConnection con)
{
  this.connection = con;
}
 
Example #11
Source File: OraWriter.java    From jts with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Creates a writer using a valid Oracle connection,
 * and specifying the maximum output dimension. 
  * <p>
  * To simplify connection resource handling, the connection should be
  * provided in the {@link #write(Geometry, OracleConnection)} method.
  * Accordingly, this constructor has been deprecated.
  * <p>
  * The connection should have sufficient privileges to view the description of the MDSYS.SDO_GEOMETRY type.
 * 
 * @param con a valid Oracle connection
 * @param outputDimension the coordinate dimension to use for the output
 * @deprecated use {@link #OraWriter(int)} instead
 */
public OraWriter(OracleConnection con, int outputDimension)
{
	this.connection = con;
	this.outputDimension = outputDimension;
}
 
Example #12
Source File: ConnectedTestCase.java    From jts with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Sub-classes should not assume that either the connection will always exist, or 
 * the connection has the required permissions.
 * 
 * @return OracleConnection
 */
protected OracleConnection getConnection()
{
	return connection;
}