List of usage examples for weka.core.converters DatabaseSaver DatabaseSaver
public DatabaseSaver() throws Exception
From source file:adams.flow.sink.WekaDatabaseWriter.java
License:Open Source License
/** * Executes the flow item./*from w w w . j a v a 2s. co m*/ * * @return null if everything is fine, otherwise error message */ @Override protected String doExecute() { String result; Instances data; Instance inst; result = null; if (m_InputToken.getPayload() instanceof Instance) { inst = (Instance) m_InputToken.getPayload(); data = inst.dataset(); } else { data = (Instances) m_InputToken.getPayload(); inst = null; } try { if (m_Saver == null) { m_Saver = new DatabaseSaver(); m_Saver.setUrl(m_URL); m_Saver.setUser(m_User); m_Saver.setPassword(m_Password.getValue()); m_Saver.setTableName(m_TableName); m_Saver.setRelationForTableName(m_UseRelationNameAsTable); m_Saver.setAutoKeyGeneration(m_AutoKeyGeneration); if (!m_CustomPropsFile.isDirectory()) m_Saver.setCustomPropsFile(m_CustomPropsFile.getAbsoluteFile()); } if (inst == null) { m_Saver.setInstances(data); m_Saver.writeBatch(); } else { m_Saver.writeIncremental(inst); } } catch (Exception e) { result = handleException("Failed to write to database: " + m_URL, e); } return result; }
From source file:core.DatabaseSaverEx.java
License:Open Source License
/** * Main method.//from w w w .j a v a2 s .c o m * * @param options should contain the options of a Saver. */ public static void main(String[] options) { StringBuffer text = new StringBuffer(); text.append("\n\nDatabaseSaver options:\n"); try { DatabaseSaver asv = new DatabaseSaver(); try { Enumeration enumi = asv.listOptions(); while (enumi.hasMoreElements()) { Option option = (Option) enumi.nextElement(); text.append(option.synopsis() + '\n'); text.append(option.description() + '\n'); } asv.setOptions(options); asv.setDestination(); } catch (Exception ex) { ex.printStackTrace(); } //incremental /*asv.setRetrieval(INCREMENTAL); Instances instances = asv.getInstances(); asv.setStructure(instances); for(int i = 0; i < instances.numInstances(); i++){ //last instance is null and finishes incremental saving asv.writeIncremental(instances.instance(i)); } asv.writeIncremental(null);*/ //batch asv.writeBatch(); } catch (Exception ex) { ex.printStackTrace(); System.out.println(text); } }