use of org.compiere.db.CConnection in project adempiere by adempiere.
the class ReplicationLocal method connectRemote.
// doIt
/**
* Connect to Remote Server
* @throws java.lang.Exception
*/
private void connectRemote() throws Exception {
// Replication Info
m_replication = new MReplication(getCtx(), getRecord_ID(), get_TrxName());
//
String AppsHost = m_replication.getHostAddress();
int AppsPort = m_replication.getHostPort();
CConnection connection = new CConnection(AppsHost);
connection.setAppsPort(AppsPort);
log.info(AppsHost + ":" + AppsPort);
try {
Server server = connection.getServer();
// log.fine("- ServerHome: " + serverHome);
if (server == null)
throw new Exception("NoServer");
m_serverRemote = server;
// log.fine("- Server: " + m_serverRemote);
// log.fine("- Remote Status = " + m_serverRemote.getStatus());
} catch (Exception ex) {
log.log(Level.SEVERE, "connectRemote", ex);
throw new Exception(ex);
}
}
use of org.compiere.db.CConnection in project adempiere by adempiere.
the class AdempiereMonitor method createLogMgtPage.
// createSummaryPage
/**
* Add Log Management to page
* @param bb body
*/
private void createLogMgtPage(body bb) {
bb.addElement(new hr());
// Ini Parameters
table table = new table();
table.setBorder(1);
table.setCellSpacing(2);
table.setCellPadding(2);
//
Properties ctx = new Properties();
MSystem system = MSystem.get(ctx);
tr line = new tr();
line.addElement(new th().addElement(system.getDBAddress()));
line.addElement(new td().addElement(Ini.getAdempiereHome()));
table.addElement(line);
// OS + Name
line = new tr();
String info = System.getProperty("os.name") + " " + System.getProperty("os.version");
String s = System.getProperty("sun.os.patch.level");
if (s != null && s.length() > 0)
info += " (" + s + ")";
line.addElement(new th().addElement(info));
info = system.getName();
if (system.getCustomPrefix() != null)
info += " (" + system.getCustomPrefix() + ")";
line.addElement(new td().addElement(info));
table.addElement(line);
// Java + email
line = new tr();
info = System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version");
line.addElement(new th().addElement(info));
line.addElement(new td().addElement(system.getUserName()));
table.addElement(line);
// DB + Instance
line = new tr();
CConnection cc = CConnection.get();
AdempiereDatabase db = cc.getDatabase();
info = db.getDescription();
line.addElement(new th().addElement(info));
line.addElement(new td().addElement(cc.getConnectionURL()));
// line.addElement(new td().addElement(system.getDBInstance()));
table.addElement(line);
// Processors/Support
line = new tr();
line.addElement(new th().addElement("Processor/Support"));
line.addElement(new td().addElement(system.getNoProcessors() + "/" + system.getSupportUnits()));
table.addElement(line);
// Memory
line = new tr();
MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
line.addElement(new th().addElement("VM Memory"));
line.addElement(new td().addElement(new CMemoryUsage(memory.getNonHeapMemoryUsage()).toString()));
table.addElement(line);
line = new tr();
line.addElement(new th().addElement("Heap Memory"));
line.addElement(new td().addElement(new CMemoryUsage(memory.getHeapMemoryUsage()).toString()));
table.addElement(line);
// Runtime
line = new tr();
RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
line.addElement(new th().addElement("Runtime " + rt.getName()));
line.addElement(new td().addElement(TimeUtil.formatElapsed(rt.getUptime())));
table.addElement(line);
// Threads
line = new tr();
ThreadMXBean th = ManagementFactory.getThreadMXBean();
line.addElement(new th().addElement("Threads " + th.getThreadCount()));
line.addElement(new td().addElement("Peak=" + th.getPeakThreadCount() + ", Demons=" + th.getDaemonThreadCount() + ", Total=" + th.getTotalStartedThreadCount()));
table.addElement(line);
//Transactions
Trx[] trxs = Trx.getActiveTransactions();
for (Trx trx : trxs) {
if (trx != null && trx.isActive()) {
line = new tr();
line.addElement(new th().addElement("Active Transaction "));
line.addElement(new td().addElement("Name=" + trx.getTrxName() + ", StartTime=" + trx.getStartTime()));
table.addElement(line);
}
}
// Cache Reset
line = new tr();
line.addElement(new th().addElement(CacheMgt.get().toStringX()));
line.addElement(new td().addElement(new a("adempiereMonitor?CacheReset=Yes", "Reset Cache")));
table.addElement(line);
// Trace Level
line = new tr();
line.addElement(new th().addElement(new label("TraceLevel").addElement("Trace Log Level")));
form myForm = new form("adempiereMonitor", form.METHOD_POST, form.ENC_DEFAULT);
// LogLevel Selection
option[] options = new option[CLogMgt.LEVELS.length];
for (int i = 0; i < options.length; i++) {
options[i] = new option(CLogMgt.LEVELS[i].getName());
options[i].addElement(CLogMgt.LEVELS[i].getName());
if (CLogMgt.LEVELS[i] == CLogMgt.getLevel())
options[i].setSelected(true);
}
select sel = new select("TraceLevel", options);
myForm.addElement(sel);
myForm.addElement(new input(input.TYPE_SUBMIT, "Set", "Set"));
line.addElement(new td().addElement(myForm));
table.addElement(line);
//
line = new tr();
CLogFile fileHandler = CLogFile.get(true, null, false);
line.addElement(new th().addElement("Trace File"));
line.addElement(new td().addElement(new a("adempiereMonitor?Trace=" + fileHandler.getFileName(), "Current")));
table.addElement(line);
//
line = new tr();
line.addElement(new td().addElement(new a("adempiereMonitor?Trace=ROTATE", "Rotate Trace Log")));
line.addElement(new td().addElement(new a("adempiereMonitor?Trace=DELETE", "Delete all Trace Logs")));
table.addElement(line);
//
bb.addElement(table);
// List Log Files
p p = new p();
p.addElement(new b("All Log Files: "));
// All in dir
File logDir = fileHandler.getLogDirectory();
if (logDir != null && logDir.isDirectory()) {
File[] logs = logDir.listFiles();
for (int i = 0; i < logs.length; i++) {
// Skip if is not a file - teo_sarca [ 1726066 ]
if (!logs[i].isFile())
continue;
if (i != 0)
p.addElement(" - ");
String fileName = logs[i].getAbsolutePath();
a link = new a("adempiereMonitor?Trace=" + fileName, fileName);
p.addElement(link);
int size = (int) (logs[i].length() / 1024);
if (size < 1024)
p.addElement(" (" + size + "k)");
else
p.addElement(" (" + size / 1024 + "M)");
}
}
bb.addElement(p);
// Clients and Web Stores
table = new table();
table.setBorder(1);
table.setCellSpacing(2);
table.setCellPadding(2);
//
line = new tr();
MClient[] clients = MClient.getAll(ctx);
line.addElement(new th().addElement("Client #" + clients.length + " - EMail Test:"));
p = new p();
for (int i = 0; i < clients.length; i++) {
MClient client = clients[i];
if (i > 0)
p.addElement(" - ");
p.addElement(new a("adempiereMonitor?EMail=" + client.getAD_Client_ID(), client.getName()));
}
if (clients.length == 0)
p.addElement(" ");
line.addElement(new td().addElement(p));
table.addElement(line);
//
line = new tr();
MStore[] wstores = MStore.getActive();
line.addElement(new th().addElement("Active Web Stores #" + wstores.length));
p = new p();
for (int i = 0; i < wstores.length; i++) {
MStore store = wstores[i];
if (i > 0)
p.addElement(" - ");
a a = new a(store.getWebContext(), store.getName());
a.setTarget("t" + i);
p.addElement(a);
}
if (wstores.length == 0)
p.addElement(" ");
line.addElement(new td().addElement(p));
table.addElement(line);
//
bb.addElement(table);
}
use of org.compiere.db.CConnection in project adempiere by adempiere.
the class ConvertDialog method cmd_start.
// cmd_selectFile
/**************************************************************************
* Start Pressed
*/
private void cmd_start() {
// Open and read File
File file = new File((String) fSelectFile.getSelectedItem());
if (!file.exists() || file.isDirectory()) {
infoPane.append("File does not exist or a directory: " + file + "\n");
return;
}
infoPane.append("Opening file: " + file + "\n");
StringBuffer sb = new StringBuffer(1000);
//
try {
FileReader fr = new FileReader(file);
BufferedReader in = new BufferedReader(fr);
String line = null;
int lines = 0;
while ((line = in.readLine()) != null) {
lines++;
sb.append(line).append('\n');
}
in.close();
fr.close();
infoPane.append("- Read lines: " + lines + ", size: " + sb.length() + "\n");
} catch (FileNotFoundException fnf) {
infoPane.append("Error: " + fnf + "\n");
return;
} catch (IOException ioe) {
infoPane.append("Error: " + ioe + "\n");
return;
}
// Target system
if (fExecute.isSelected()) {
CConnection cc = (CConnection) fConnect.getValue();
Convert convert = cc.getDatabase().getConvert();
convert.setVerbose(fVerbose.isSelected());
//
Connection conn = cc.getConnection(true, Connection.TRANSACTION_READ_COMMITTED);
convert.execute(sb.toString(), conn);
if (convert.hasError()) {
StringBuffer sbb = new StringBuffer("- Error: ");
if (convert.getConversionError() != null)
sbb.append(convert.getConversionError()).append(' ');
if (convert.getException() != null) {
sbb.append(convert.getException());
convert.getException().printStackTrace();
}
sbb.append("\n");
infoPane.append(sbb.toString());
} else
infoPane.append("- OK\n");
} else {
String target = (String) fTarget.getSelectedItem();
if (Database.DB_ORACLE.equals(target)) {
infoPane.append("No conversion needed.\n");
return;
}
Convert convert = null;
try {
convert = Database.getDatabase(target).getConvert();
} catch (Exception e) {
infoPane.append("Error: " + e + "\n");
return;
}
//
String cc = convert.convertAll(sb.toString());
// Output file name
String fileName = file.getAbsolutePath();
int pos = fileName.lastIndexOf('.');
if (pos == -1)
fileName += target;
else
fileName = fileName.substring(0, pos) + target + fileName.substring(pos);
infoPane.append("Writing to: " + fileName + "\n");
// Write to file
try {
FileWriter fw = new FileWriter(fileName, false);
BufferedWriter out = new BufferedWriter(fw);
out.write("-- Adempiere dbPort - Convert Oracle to " + target);
out.newLine();
out.write("-- " + Adempiere.getSummary());
out.newLine();
//
out.write(cc);
//
out.close();
fw.close();
} catch (IOException ioe) {
infoPane.append("Error: " + ioe + "\n");
}
infoPane.append("- Written: " + cc.length() + "\n");
}
}
use of org.compiere.db.CConnection in project adempiere by adempiere.
the class CLogMgt method getServerInfo.
// getMsg
/**
* Get Server Info.
* @return host : port (NotActive) via CMhost : port
*/
private static String getServerInfo() {
StringBuffer sb = new StringBuffer();
CConnection cc = CConnection.get();
// Host
sb.append(cc.getAppsHost()).append(" : ").append(cc.getAppsPort()).append(" (");
// Server
if (cc.isAppsServerOK(false))
sb.append(CConnection.get().getServerVersion());
else
sb.append(getMsg("NotActive"));
//
sb.append(")\n ");
//
return sb.toString();
}
use of org.compiere.db.CConnection in project adempiere by adempiere.
the class ConfigurationData method save.
// testPort
/**************************************************************************
* Save Settings
* @return true if saved
*/
public boolean save() {
// Add
p_properties.setProperty("ADEMPIERE_MAIN_VERSION", Adempiere.MAIN_VERSION);
p_properties.setProperty("ADEMPIERE_DATE_VERSION", Adempiere.DATE_VERSION);
p_properties.setProperty("ADEMPIERE_DB_VERSION", Adempiere.DB_VERSION);
// Create Connection
String ccType = Database.DB_ORACLE;
for (String dbType : DBTYPE) {
if (getDatabaseType().equals(DBTYPE))
ccType = dbType;
}
CConnection cc = null;
try {
cc = CConnection.get(ccType, getDatabaseServer(), getDatabasePort(), getDatabaseName(), getDatabaseUser(), getDatabasePassword());
cc.setAppsHost(getAppsServer());
cc.setAppsPort(getAppsServerJNPPort());
cc.setConnectionProfile(CConnection.PROFILE_LAN);
} catch (Exception e) {
log.log(Level.SEVERE, "connection", e);
return false;
}
p_properties.setProperty(Ini.P_CONNECTION, SecureEngine.encrypt(cc.toStringLong()));
log.finest(p_properties.toString());
// Before we save, load Ini
Ini.setClient(false);
String fileName = m_adempiereHome.getAbsolutePath() + File.separator + Ini.ADEMPIERE_PROPERTY_FILE;
Ini.loadProperties(fileName);
// Save Environment
fileName = m_adempiereHome.getAbsolutePath() + File.separator + ADEMPIERE_ENV_FILE;
try {
FileOutputStream fos = new FileOutputStream(new File(fileName));
p_properties.store(fos, ADEMPIERE_ENV_FILE);
fos.flush();
fos.close();
} catch (Exception e) {
log.severe("Cannot save Properties to " + fileName + " - " + e.toString());
if (p_panel != null)
JOptionPane.showConfirmDialog(p_panel, ConfigurationPanel.res.getString("ErrorSave"), ConfigurationPanel.res.getString("AdempiereServerSetup"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
else
System.err.println(ConfigurationPanel.res.getString("ErrorSave"));
return false;
} catch (Throwable t) {
log.severe("Cannot save Properties to " + fileName + " - " + t.toString());
if (p_panel != null)
JOptionPane.showConfirmDialog(p_panel, ConfigurationPanel.res.getString("ErrorSave"), ConfigurationPanel.res.getString("AdempiereServerSetup"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
else
System.err.println(ConfigurationPanel.res.getString("ErrorSave"));
return false;
}
log.info(fileName);
return saveIni();
}
Aggregations