package com.webaction.proc;
import com.webaction.source.lib.type.*;
import org.apache.log4j.*;
import com.webaction.security.*;
import com.webaction.uuid.*;
import com.webaction.uuid.UUID;
import com.webaction.proc.events.*;
import java.util.*;
import java.util.Date;
import org.joda.time.*;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import com.webaction.runtime.compiler.*;
import com.webaction.source.cdc.common.*;
public class DatabaseReaderNew implements DatabaseReader
{
private Connection connection;
private PreparedStatement statement;
private ResultSet results;
private List<String> tables;
private List<String> excludedTables;
private int currentTableIndex;
private String currentTableName;
private int colCount;
private String tablesValue;
private int fetchSize;
private String url;
private dtenum asDT;
private static Logger logger;
public DatabaseReaderNew() {
this.connection = null;
this.statement = null;
this.results = null;
this.tables = null;
this.excludedTables = new ArrayList<String>();
this.currentTableIndex = 0;
this.currentTableName = null;
this.colCount = 0;
this.tablesValue = null;
this.fetchSize = 100;
this.url = null;
}
@Override
public synchronized void initDR(final Map<String, Object> properties) throws Exception {
String username = null;
String password = null;
String asDTstr = null;
try {
if (!properties.containsKey("ConnectionURL") || properties.get("ConnectionURL") == null || properties.get("ConnectionURL").toString().length() <= 0) {
DatabaseReaderNew.logger.error((Object)"ConnectionURL is not specified");
throw new Exception("ConnectionURL is not specified");
}
this.url = properties.get("ConnectionURL").toString();
}
catch (ClassCastException e3) {
DatabaseReaderNew.logger.error((Object)"Invalid ConnectionURL format.Value specified cannot be cast to java.lang.String");
throw new Exception("Invalid ConnectionURL format.Value specified cannot be cast to java.lang.String");
}
if (DatabaseReaderNew.logger.isTraceEnabled()) {
DatabaseReaderNew.logger.trace((Object)("Initialized DatabaseReaderNew with url: " + this.url));
}
try {
if (!properties.containsKey("Username") || properties.get("Username") == null || properties.get("Username").toString().length() <= 0) {
DatabaseReaderNew.logger.error((Object)"Username is not specified");
throw new Exception("Username is not specified");
}
username = properties.get("Username").toString();
}
catch (ClassCastException e3) {
DatabaseReaderNew.logger.error((Object)"Invalid Username format.Value specified cannot be cast to java.lang.String");
throw new Exception("Invalid Username format.Value specified cannot be cast to java.lang.String");
}
if (DatabaseReaderNew.logger.isTraceEnabled()) {
DatabaseReaderNew.logger.trace((Object)("Initialized DatabaseReaderNew with username: " + username));
}
try {
if (!properties.containsKey("Password") || properties.get("Password") == null || ((Password)properties.get("Password")).getPlain().length() <= 0) {
DatabaseReaderNew.logger.error((Object)"Password is not specified");
throw new Exception("Password is not specified");
}
password = ((Password)properties.get("Password")).getPlain();
}
catch (ClassCastException e3) {
DatabaseReaderNew.logger.error((Object)"Invalid Password format.Value specified cannot be cast to java.lang.String");
throw new Exception("Invalid Password format.Value specified cannot be cast to java.lang.String");
}
if (DatabaseReaderNew.logger.isTraceEnabled()) {
DatabaseReaderNew.logger.trace((Object)("Initialized DatabaseReaderNew with password: " + password));
}
try {
if (properties.containsKey("Tables") && properties.get("Tables") != null && properties.get("Tables").toString().length() > 0) {
this.tablesValue = properties.get("Tables").toString();
}
else {
if (!properties.containsKey("Table") || properties.get("Table") == null || properties.get("Table").toString().length() <= 0) {
throw new IllegalArgumentException("Expected required parameter 'Tables' not found");
}
this.tablesValue = properties.get("Table").toString();
}
}
catch (ClassCastException e3) {
DatabaseReaderNew.logger.error((Object)"Invalid Table format.Value specified cannot be cast to java.lang.String");
throw new Exception("Invalid Table format.Value specified cannot be cast to java.lang.String");
}
if (DatabaseReaderNew.logger.isTraceEnabled()) {
DatabaseReaderNew.logger.trace((Object)("Initialized DatabaseReaderNew with tableList:" + this.tablesValue));
}
try {
if (properties.containsKey("ExcludedTables") && properties.get("ExcludedTables") != null && properties.get("ExcludedTables").toString().length() > 0) {
final String excludedTableStr = properties.get("ExcludedTables").toString();
final String[] split;
final String[] tabs = split = excludedTableStr.split(";");
for (final String tab : split) {
String temp = tab.substring(tab.lastIndexOf(46) + 1);
if (temp.charAt(0) == '\"' && temp.charAt(temp.length() - 1) == '\"') {
temp = temp.substring(1, temp.length() - 2);
}
this.excludedTables.add(temp);
}
}
}
catch (Exception e) {
final String errMsg = "Invalid value in excludedTables property: " + e.getMessage();
DatabaseReaderNew.logger.error((Object)errMsg);
throw new IllegalArgumentException(errMsg);
}
if (DatabaseReaderNew.logger.isTraceEnabled()) {
DatabaseReaderNew.logger.trace((Object)("Initialized DatabaseReaderNew with excludedTables:" + Arrays.toString(this.excludedTables.toArray())));
}
try {
int fetchS = 100;
if (properties.containsKey("FetchSize")) {
if (properties.get("FetchSize") == null) {
final Exception exception = new Exception("FetchSize is specified Null");
DatabaseReaderNew.logger.error((Object)exception.getMessage());
throw exception;
}
final Object val = properties.get("FetchSize");
if (val instanceof Number) {
fetchS = ((Number)val).intValue();
}
else if (val instanceof String) {
fetchS = Integer.parseInt((String)val);
}
if (fetchS < 0 || fetchS > 1000000000) {
final Exception exception2 = new Exception("FetchSize specified is out of Range");
DatabaseReaderNew.logger.error((Object)exception2.getMessage());
throw exception2;
}
}
else {
fetchS = 100;
}
this.fetchSize = fetchS;
}
catch (ClassCastException e3) {
final Exception exception = new Exception("Invalid FetchSize format. Value specified cannot be cast to java.lang.Integer");
DatabaseReaderNew.logger.error((Object)exception.getMessage());
throw exception;
}