public class GenericJDBC
extends java.lang.Object
The purpose is to provide a command-line driven ability to access and update JDBC databases.
JVM Arguments:
This class requires the JDBC Drivers be in the CLASSPATH already.
For example: For SAS/Share, this generally means that both associated JAR files be in the
System CLASSPATH ( or passed in the command-line):
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
_connection
defaults to "protocol://database-server-hostname:port"
|
protected java.lang.String |
_datapath
defaults to "\'/tst/tools/deploymentdetails/shrdata\'"
|
protected java.lang.String |
_dataset
defaults to null.
|
protected boolean |
_doUpdate
default: true.
|
protected java.lang.String |
_drivers
defaults to "com.sas.net.sharenet.ShareNetDriver"
|
protected java.lang.String |
_field
defaults to null.
|
protected java.lang.String |
_opsource
defaults to null.
|
protected java.util.Properties |
_props
defaults to null.
|
protected java.lang.String |
_shrdataid
defaults to "mydata"
|
protected java.lang.String |
_value
defaults to null.
|
protected java.lang.String |
_where
defaults to null.
|
static java.lang.String |
ARG_CONNECTION |
static java.lang.String |
ARG_DATAID |
static java.lang.String |
ARG_DATAPATH |
static java.lang.String |
ARG_DATASET |
static java.lang.String |
ARG_DRIVERS |
static java.lang.String |
ARG_FIELD |
static java.lang.String |
ARG_NOUPDATE |
static java.lang.String |
ARG_OPSOURCE |
static java.lang.String |
ARG_PROPS |
static java.lang.String |
ARG_VALUE |
static java.lang.String |
ARG_WHERE |
static java.lang.String |
DEFAULT_CONNECTION
Deprecated.
NO default connection will be provided. Please provide when running test.
parameter -connection "protocol://database-server-hostname:port" |
static java.lang.String |
DEFAULT_DEV_DATA
"'/tst/tools/deploymentdetails/dev/shrdata'"
|
static java.lang.String |
DEFAULT_DRIVERS
"com.sas.net.sharenet.ShareNetDriver"
|
static java.lang.String |
DEFAULT_PROD_DATA
"'/tst/tools/deploymentdetails/shrdata'"
|
static java.lang.String |
DEFAULT_SHRDATA_ID
"mydata"
|
static java.lang.String |
PROP_KEY_JDBC_DRIVERS |
static java.lang.String |
PROP_KEY_LIBREFS |
static java.lang.String |
PROP_KEY_SAFS_JDBC_CONNECTION |
static java.lang.String |
PROP_KEY_SAFS_JDBC_DATAID |
static java.lang.String |
PROP_KEY_SAFS_JDBC_DATAPATH |
static java.lang.String |
PROP_KEY_SAFS_JDBC_DATASET |
static java.lang.String |
PROP_KEY_SAFS_JDBC_DRIVERS |
static java.lang.String |
PROP_KEY_SAFS_JDBC_FIELD |
static java.lang.String |
PROP_KEY_SAFS_JDBC_NOUPDATE |
static java.lang.String |
PROP_KEY_SAFS_JDBC_OPSOURCE |
static java.lang.String |
PROP_KEY_SAFS_JDBC_PROPS |
static java.lang.String |
PROP_KEY_SAFS_JDBC_VALUE |
static java.lang.String |
PROP_KEY_SAFS_JDBC_WHERE |
static java.lang.String |
PROP_KEY_UNDOPOLICYNONE |
Constructor and Description |
---|
GenericJDBC() |
Modifier and Type | Method and Description |
---|---|
void |
enableUpdate(boolean enabled) |
java.lang.String |
getConnection() |
java.lang.String |
getDatapath() |
java.lang.String |
getDataset() |
java.lang.String |
getDrivers() |
java.lang.String |
getFieldName() |
java.lang.String |
getFieldValue() |
java.lang.String |
getOpsource() |
java.util.Properties |
getProps() |
java.lang.String |
getShrdataid() |
protected java.lang.String |
getSystemProperty(java.lang.String pname)
Used internally to return a valid System Property value, or null.
|
java.lang.String |
getWhere() |
boolean |
isUpdateEnabled() |
static void |
log(java.lang.String message)
Currently logs to System.out.
|
static void |
main(java.lang.String[] args)
primarily a testing/debug entry point.
|
void |
processArgs(java.lang.String[] args)
String[] args will override any processJVMOptions previously set--
assuming JVM Options are processed BEFORE these args.
|
protected void |
processDriversArg(java.lang.String driversarg)
Create/Append a new JDBC Drivers value to any existing JDBC Drivers value stored in
System Properties.
|
void |
processJVMOptions()
(Re)Set any arguments passed in as JVM -D Options.
|
void |
processPropsArg(java.lang.String propsarg) |
void |
setConnection(java.lang.String _connection) |
void |
setDatapath(java.lang.String _datapath) |
void |
setDataset(java.lang.String _dataset) |
void |
setDrivers(java.lang.String _drivers) |
void |
setFieldName(java.lang.String _field) |
void |
setFieldValue(java.lang.String _value) |
void |
setOpsource(java.lang.String _opsource) |
void |
setProps(java.util.Properties _props) |
void |
setShrdataid(java.lang.String _shrdataid) |
void |
setWhere(java.lang.String _where) |
void |
updateData()
Invokes
updateData(String, Properties, String, String, String, String, String, String, String)
with all internal settings previously set or defaulted. |
void |
updateData(java.lang.String connectURI,
java.util.Properties prop,
java.lang.String dataid,
java.lang.String datapath,
java.lang.String dataset,
java.lang.String field,
java.lang.String value,
java.lang.String where,
java.lang.String opsource)
The primary routine used to update the database.
|
public static final java.lang.String DEFAULT_SHRDATA_ID
public static final java.lang.String DEFAULT_PROD_DATA
public static final java.lang.String DEFAULT_DEV_DATA
public static final java.lang.String DEFAULT_DRIVERS
@Deprecated public static final java.lang.String DEFAULT_CONNECTION
parameter -connection "protocol://database-server-hostname:port"
OR
JVM Option: -Dsafs.jdbc.connection="<connection_uri>"
Ex: -Dsafs.jdbc.connection="protocol://database-server-hostname:port"
protected java.lang.String _connection
protected java.lang.String _drivers
protected java.lang.String _shrdataid
protected java.lang.String _datapath
protected java.lang.String _dataset
updateData()
.protected java.lang.String _field
updateData()
.protected java.lang.String _value
updateData()
.protected java.lang.String _opsource
updateData()
.
A generic value may be used internally if none is provided beforehand.protected java.lang.String _where
updateData()
.protected java.util.Properties _props
updateData()
,
if needed.protected boolean _doUpdate
public static final java.lang.String PROP_KEY_LIBREFS
public static final java.lang.String PROP_KEY_UNDOPOLICYNONE
public static final java.lang.String PROP_KEY_JDBC_DRIVERS
public static final java.lang.String PROP_KEY_SAFS_JDBC_DRIVERS
public static final java.lang.String PROP_KEY_SAFS_JDBC_NOUPDATE
public static final java.lang.String PROP_KEY_SAFS_JDBC_DATAID
public static final java.lang.String PROP_KEY_SAFS_JDBC_DATAPATH
public static final java.lang.String PROP_KEY_SAFS_JDBC_WHERE
public static final java.lang.String PROP_KEY_SAFS_JDBC_DATASET
public static final java.lang.String PROP_KEY_SAFS_JDBC_FIELD
public static final java.lang.String PROP_KEY_SAFS_JDBC_VALUE
public static final java.lang.String PROP_KEY_SAFS_JDBC_CONNECTION
public static final java.lang.String PROP_KEY_SAFS_JDBC_PROPS
public static final java.lang.String PROP_KEY_SAFS_JDBC_OPSOURCE
public static final java.lang.String ARG_NOUPDATE
public static final java.lang.String ARG_DRIVERS
public static final java.lang.String ARG_DATAID
public static final java.lang.String ARG_DATAPATH
public static final java.lang.String ARG_WHERE
public static final java.lang.String ARG_DATASET
public static final java.lang.String ARG_FIELD
public static final java.lang.String ARG_VALUE
public static final java.lang.String ARG_CONNECTION
public static final java.lang.String ARG_PROPS
public static final java.lang.String ARG_OPSOURCE
public static void log(java.lang.String message)
public void enableUpdate(boolean enabled)
enabled
- -- Set true (default) to enable database updates.
False to disable/bypass database updates.public boolean isUpdateEnabled()
public java.lang.String getConnection()
public void setConnection(java.lang.String _connection)
_connection
- -- Set/Change the value of the JDBC connection string.public java.lang.String getDrivers()
public void setDrivers(java.lang.String _drivers)
_drivers
- -- Set/Change the value of the JDBC drivers string.public java.lang.String getShrdataid()
public void setShrdataid(java.lang.String _shrdataid)
_shrdataid
- -- Set/Change the Share data id to be used with JDBC.
This might only apply to SAS Connect JDBC data connections.public java.lang.String getDatapath()
public void setDatapath(java.lang.String _datapath)
_datapath
- -- Set/Change the database path to be used with JDBC.public java.lang.String getDataset()
public void setDataset(java.lang.String _dataset)
_dataset
- -- Set/Change the dataset in the database to be used with JDBC.public java.lang.String getFieldName()
public void setFieldName(java.lang.String _field)
_field
- -- Set/Change the field/column name that will be used in the JDBC dataset.public java.lang.String getFieldValue()
public void setFieldValue(java.lang.String _value)
_value
- -- Set/Change the field value to be used on the field in the JDBC dataset.public java.lang.String getOpsource()
public void setOpsource(java.lang.String _opsource)
_opsource
- -- Set/Change the opSource (comment) that will be sent to the JDBC database.public java.lang.String getWhere()
public void setWhere(java.lang.String _where)
_where
- -- Set/Change the where clause that will be used on the JDBC database.
This setting should NOT include the "where " prefix.public java.util.Properties getProps()
public void setProps(java.util.Properties _props)
_props
- -- Set/Change the Properties used for JDBC database connection, if any.
May be null.public void updateData()
updateData(String, Properties, String, String, String, String, String, String, String)
with all internal settings previously set or defaulted.public void updateData(java.lang.String connectURI, java.util.Properties prop, java.lang.String dataid, java.lang.String datapath, java.lang.String dataset, java.lang.String field, java.lang.String value, java.lang.String where, java.lang.String opsource)
The typical update:
String update = "update "+ dataid +"."+ dataset + " set "+ field +" = '"+ value +"'" / * <-- single quotes critical * / + " where "+ where + " / * "+ opsource +" * /";
Then verification:
String query = "select * from "+ dataid +"."+ dataset +" where "+ where + " / * "+ opsource +" * /";
connectURI
- _connection
prop
- _props
dataid
- _shrdataid
datapath
- _datapath
dataset
- _dataset
field
- _field
value
- _value
where
- _where
opsource
- _opsource
protected java.lang.String getSystemProperty(java.lang.String pname)
public void processPropsArg(java.lang.String propsarg)
propsarg
- -- command-line -props value or JVM Option to be parsed and placed
into _props
.protected void processDriversArg(java.lang.String driversarg)
driversarg
- -- one or more JDBC Driver class names separated by semi-colons as
usually retrieved from the command-line arguments.public void processJVMOptions()
public void processArgs(java.lang.String[] args)
public static void main(java.lang.String[] args)
command-line execution performs:
GenericJDBC process = new GenericJDBC(); process.processJVMOptions(); process.processArgs(args); process.updateData();
args
- Copyright © SAS Institute. All Rights Reserved.