public Element getLookupElement() { Element e = new Element("lookup"); if (saveErrors.size() != 0) { saveErrors.clear(); } ObjEntityView view = objEntityViewField.getObjEntityView(); DataView dataView = view.getDataView(); String fieldPath = "<b>" + dataView.getName() + "." + view.getName() + "." + objEntityViewField.getName() + "</b><br>"; if (lookupObjEntityView != null) { e.setAttribute(new Attribute("obj-entity-view-name", lookupObjEntityView.getName())); } else { e.setAttribute(new Attribute("obj-entity-view-name", "")); saveErrors.add(fieldPath + "lookup hasn't attribute \"obj-entity-view-name\"<br><br>"); } if (lookupField != null) { e.setAttribute(new Attribute("field-name", lookupField.getName())); } else { e.setAttribute(new Attribute("field-name", "")); saveErrors.add(fieldPath + "lookup hasn't attribute \"field-name\"<br><br>"); } e.addContent(""); return e; }
protected void commitOrRollback(String cmdName) { if (!error && commit(conn)) { long executionTime = System.currentTimeMillis() - startTime; String execTimeStr = SQLExecutionHelper.millisecondsToSeconds(executionTime); String infoMsg = cmdName + " " + NbBundle.getMessage( SQLStatementExecutor.class, "MSG_execution_success", execTimeStr); dataView.setInfoStatusText(infoMsg); executeOnSucess(); // delegate } else { rollback(conn); reinstateToolbar(); String msg = cmdName + " " + NbBundle.getMessage(SQLStatementExecutor.class, "MSG_failed"); if (ex == null) { errorMsg = msg + " " + errorMsg; } else { errorMsg = msg; } ex = new DBException(errorMsg, ex); dataView.setErrorStatusText(ex); NotifyDescriptor nd = new NotifyDescriptor.Message(ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notify(nd); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dataView = MixView.getDataView(); selectedItemURL = new Vector<String>(); listViewMenu = new Vector<SpannableString>(); DataHandler jLayer = dataView.getDataHandler(); if (dataView.isFrozen() && jLayer.getMarkerCount() > 0) { selectedItemURL.add("search"); } /*add all marker items to a title and a URL Vector*/ for (int i = 0; i < jLayer.getMarkerCount(); i++) { Marker ma = jLayer.getMarker(i); if (ma.isActive()) { if (ma.getURL() != null) { /* Underline the title if website is available*/ underlinedTitle = new SpannableString(ma.getTitle()); underlinedTitle.setSpan(new UnderlineSpan(), 0, underlinedTitle.length(), 0); listViewMenu.add(underlinedTitle); } else { listViewMenu.add(new SpannableString(ma.getTitle())); } /*the website for the corresponding title*/ if (ma.getURL() != null) selectedItemURL.add(ma.getURL()); /*if no website is available for a specific title*/ else selectedItemURL.add(""); } if (dataView.isFrozen()) { TextView searchNotificationTxt = new TextView(this); searchNotificationTxt.setVisibility(View.VISIBLE); searchNotificationTxt.setText( getString(R.string.search_active_1) + " " + DataSourceList.getDataSourcesStringList() + getString(R.string.search_active_2)); searchNotificationTxt.setWidth(MixView.getdWindow().getWidth()); searchNotificationTxt.setPadding(10, 2, 0, 0); searchNotificationTxt.setBackgroundColor(Color.DKGRAY); searchNotificationTxt.setTextColor(Color.WHITE); getListView().addHeaderView(searchNotificationTxt); } setListAdapter( new ArrayAdapter<SpannableString>( this, android.R.layout.simple_list_item_1, listViewMenu)); getListView().setTextFilterEnabled(true); break; } }
/** Binding version of Cursor.putCurrent(). */ OperationStatus putCurrent(Object value) throws DatabaseException { checkWriteAllowed(false); view.useValue(value, valueThang, keyThang); /* * Workaround for a DB core problem: With HASH type a put() with * different data is allowed. */ boolean hashWorkaround = (view.dupsOrdered && !view.ordered); if (hashWorkaround) { if (otherThang == null) { otherThang = new DatabaseEntry(); } cursor.getCurrent(keyThang, primaryKeyThang, otherThang, LockMode.DEFAULT); if (KeyRange.equalBytes(valueThang, otherThang)) { return OperationStatus.SUCCESS; } else { throw new IllegalArgumentException( "Current data differs from put data with sorted duplicates"); } } return cursor.putCurrent(valueThang); }
/** * Repositions to a given raw key/data pair, or just past it if that record has been deleted. * * @return REPOS_EXACT, REPOS_NEXT or REPOS_EOF. */ int repositionRange(byte[] keyBytes, byte[] priKeyBytes, byte[] valueBytes, boolean lockForWrite) throws DatabaseException { LockMode lockMode = getLockMode(lockForWrite); OperationStatus status = null; /* Use the given key/data byte arrays. */ setThangs(keyBytes, priKeyBytes, valueBytes); /* Position on or after the given key/data pair. */ if (view.dupsAllowed) { status = cursor.getSearchBothRange( keyThang, primaryKeyThang, valueThang, lockMode); } if (status != OperationStatus.SUCCESS) { status = cursor.getSearchKeyRange( keyThang, primaryKeyThang, valueThang, lockMode); } /* Return the result of the operation. */ if (status == OperationStatus.SUCCESS) { if (!KeyRange.equalBytes( keyBytes, 0, keyBytes.length, keyThang.getData(), keyThang.getOffset(), keyThang.getSize())) { return REPOS_NEXT; } if (view.dupsAllowed) { DatabaseEntry thang = view.isSecondary() ? primaryKeyThang : valueThang; byte[] bytes = view.isSecondary() ? priKeyBytes : valueBytes; if (!KeyRange.equalBytes( bytes, 0, bytes.length, thang.getData(), thang.getOffset(), thang.getSize())) { return REPOS_NEXT; } } return REPOS_EXACT; } else { return REPOS_EOF; } }
public void run() { assert task != null; try { startTime = System.currentTimeMillis(); ProgressHandle handle = ProgressHandleFactory.createHandle(title, this); handle.setDisplayName(titleMsg); handle.start(); try { handle.switchToIndeterminate(); dataView.setInfoStatusText(""); // NOI18N errorMsg = ""; // NOI18N dataView.disableButtons(); conn = DBConnectionFactory.getInstance().getConnection(dataView.getDatabaseConnection()); String msg = ""; if (conn == null) { Throwable connEx = DBConnectionFactory.getInstance().getLastException(); if (connEx != null) { msg = connEx.getMessage(); } else { msg = NbBundle.getMessage( SQLStatementExecutor.class, "MSG_connection_failure", dataView.getDatabaseConnection()); } NotifyDescriptor nd = new NotifyDescriptor.Message(msg); DialogDisplayer.getDefault().notify(nd); return; } lastCommitState = setAutocommit(conn, false); execute(); // delegate } finally { handle.finish(); } } catch (Exception e) { this.ex = e; } finally { if (ex != null) { errorMsg += ex.getMessage(); error = true; } finished(); // delegate resetAutocommitState(conn, lastCommitState); } }
/** Binding version of Cursor.getSearchKeyRange(), no join cursor allowed. */ OperationStatus getSearchKeyRange(Object key, Object value, boolean lockForWrite) throws DatabaseException { checkNoJoinCursor(); LockMode lockMode = getLockMode(lockForWrite); if (view.dupsView) { if (view.useKey(key, value, primaryKeyThang, view.dupsRange)) { KeyRange.copy(view.dupsKey, keyThang); return cursor.getSearchBothRange(keyThang, primaryKeyThang, valueThang, lockMode); } } else { if (view.useKey(key, value, keyThang, range)) { return cursor.getSearchKeyRange(keyThang, primaryKeyThang, valueThang, lockMode); } } return OperationStatus.NOTFOUND; }
/** Throws an exception if write is not allowed or if a join cursor is in use. */ private void checkWriteAllowed(boolean allowSecondary) { checkNoJoinCursor(); if (!writeAllowed || (!allowSecondary && view.isSecondary())) { throw new UnsupportedOperationException("Writing is not allowed"); } }
/** Do setup for a put() operation. */ private void initForPut(Object key, Object value, Object[] oldValue, boolean useCurrentKey) throws DatabaseException { checkWriteAllowed(false); if (!useCurrentKey && !view.useKey(key, value, keyThang, range)) { throw new IllegalArgumentException("key out of range"); } if (oldValue != null) { oldValue[0] = null; if (!view.dupsAllowed) { OperationStatus status = doGetSearchKey(true); if (status == OperationStatus.SUCCESS) { oldValue[0] = getCurrentValue(); } } } view.useValue(value, valueThang, keyThang); }
private void rollback(Connection conn) { try { if (conn != null && !conn.getAutoCommit()) { conn.rollback(); } } catch (SQLException e) { String msg = NbBundle.getMessage(SQLStatementExecutor.class, "MSG_failure_rollback"); dataView.setErrorStatusText(msg, e); } }
/** * Find the given key and value using getSearchBoth if possible or a sequential scan otherwise, no * join cursor allowed. */ OperationStatus findBoth(Object key, Object value, boolean lockForWrite) throws DatabaseException { checkNoJoinCursor(); LockMode lockMode = getLockMode(lockForWrite); view.useValue(value, valueThang, null); if (view.dupsView) { if (view.useKey(key, value, primaryKeyThang, view.dupsRange)) { KeyRange.copy(view.dupsKey, keyThang); if (otherThang == null) { otherThang = new DatabaseEntry(); } OperationStatus status = cursor.getSearchBoth(keyThang, primaryKeyThang, otherThang, lockMode); if (status == OperationStatus.SUCCESS && KeyRange.equalBytes(otherThang, valueThang)) { return status; } } } else if (view.useKey(key, value, keyThang, range)) { if (view.isSecondary()) { if (otherThang == null) { otherThang = new DatabaseEntry(); } OperationStatus status = cursor.getSearchKey(keyThang, primaryKeyThang, otherThang, lockMode); while (status == OperationStatus.SUCCESS) { if (KeyRange.equalBytes(otherThang, valueThang)) { return status; } status = cursor.getNextDup( keyThang, primaryKeyThang, otherThang, lockMode); } /* if status != SUCCESS set range cursor to invalid? */ } else { return cursor.getSearchBoth(keyThang, null, valueThang, lockMode); } } return OperationStatus.NOTFOUND; }
/** * Find the given value using getSearchBoth if possible or a sequential scan otherwise, no join * cursor allowed. */ OperationStatus findValue(Object value, boolean findFirst) throws DatabaseException { checkNoJoinCursor(); if (view.entityBinding != null && !view.isSecondary() && (findFirst || !view.dupsAllowed)) { return findBoth(null, value, false); } else { if (otherThang == null) { otherThang = new DatabaseEntry(); } view.useValue(value, otherThang, null); OperationStatus status = findFirst ? getFirst(false) : getLast(false); while (status == OperationStatus.SUCCESS) { if (KeyRange.equalBytes(valueThang, otherThang)) { break; } status = findFirst ? getNext(false) : getPrev(false); } return status; } }
private boolean commit(Connection conn) { try { if (conn != null && !conn.getAutoCommit()) { conn.commit(); } } catch (SQLException sqlEx) { String msg = NbBundle.getMessage(SQLStatementExecutor.class, "MSG_failure_to_commit"); dataView.setErrorStatusText(msg, sqlEx); ex = sqlEx; return false; } return true; }
public void clickOnListView(int position) { /*if no website is available for this item*/ String selectedURL = position < selectedItemURL.size() ? selectedItemURL.get(position) : null; if (selectedURL == null || selectedURL.length() <= 0) Toast.makeText(this, getString(R.string.no_website_available), Toast.LENGTH_LONG).show(); else if ("search".equals(selectedURL)) { dataView.setFrozen(false); dataView.getDataHandler().setMarkerList(originalMarkerList); finish(); Intent intent1 = new Intent(this, MixListView.class); startActivityForResult(intent1, 42); } else { try { if (selectedURL.startsWith("webpage")) { String newUrl = MixUtils.parseAction(selectedURL); dataView.getContext().getWebContentManager().loadWebPage(newUrl, this); } } catch (Exception e) { e.printStackTrace(); } } }
@Override public Optional<SimpleData> build(final DataView container) { Optional<Integer> testInt = container.getInt(new DataQuery("myInt")); if (!testInt.isPresent()) { throw new InvalidDataException("Missing important data: {myInt}"); } Optional<Double> testDouble = container.getDouble(new DataQuery("myDouble")); if (!testDouble.isPresent()) { throw new InvalidDataException("Missing important data: {myDouble}"); } Optional<String> testString = container.getString(new DataQuery("myString")); if (!testString.isPresent()) { throw new InvalidDataException("Missing important data: {myString}"); } Optional<List<String>> testList = container.getStringList(new DataQuery("myStringList")); if (!testList.isPresent()) { throw new InvalidDataException("Missing important data: {myStringList}"); } return Optional.of( new SimpleData(testInt.get(), testDouble.get(), testString.get(), testList.get())); }
/** Creates a cursor for a given view and key range. Used by unit tests. */ DataCursor( DataView view, boolean writeAllowed, Object beginKey, boolean beginInclusive, Object endKey, boolean endInclusive) throws DatabaseException { init( view, writeAllowed, null, view.subRange(view.range, beginKey, beginInclusive, endKey, endInclusive)); }
private void doMixSearch(String query) { DataHandler jLayer = dataView.getDataHandler(); if (!dataView.isFrozen()) { originalMarkerList = jLayer.getMarkerList(); MixMap.originalMarkerList = jLayer.getMarkerList(); } originalMarkerList = jLayer.getMarkerList(); searchResultMarkers = new ArrayList<Marker>(); Log.d("SEARCH-------------------0", "" + query); setSearchQuery(query); selectedItemURL = new Vector<String>(); listViewMenu = new Vector<SpannableString>(); for (int i = 0; i < jLayer.getMarkerCount(); i++) { Marker ma = jLayer.getMarker(i); if (ma.getTitle().toLowerCase().indexOf(searchQuery.toLowerCase()) != -1) { searchResultMarkers.add(ma); listViewMenu.add(new SpannableString(ma.getTitle())); /*the website for the corresponding title*/ if (ma.getURL() != null) selectedItemURL.add(ma.getURL()); /*if no website is available for a specific title*/ else selectedItemURL.add(""); } } if (listViewMenu.size() == 0) { Toast.makeText(this, getString(R.string.search_failed_notification), Toast.LENGTH_LONG) .show(); } else { jLayer.setMarkerList(searchResultMarkers); dataView.setFrozen(true); finish(); Intent intent1 = new Intent(this, MixListView.class); startActivityForResult(intent1, 42); } }
/** Creates a join cursor. */ DataCursor( DataView view, DataCursor[] indexCursors, JoinConfig joinConfig, boolean closeIndexCursors) throws DatabaseException { if (view.isSecondary()) { throw new IllegalArgumentException( "The primary collection in a join must not be a secondary " + "database"); } Cursor[] cursors = new Cursor[indexCursors.length]; for (int i = 0; i < cursors.length; i += 1) { cursors[i] = indexCursors[i].cursor.getCursor(); } joinCursor = view.db.join(cursors, joinConfig); init(view, false, null, null); if (closeIndexCursors) { indexCursorsToClose = indexCursors; } }
/** Constructor helper. */ private void initThangs() throws DatabaseException { keyThang = new DatabaseEntry(); primaryKeyThang = view.isSecondary() ? (new DatabaseEntry()) : keyThang; valueThang = new DatabaseEntry(); }
private static Cursor openCursor(DataView view, CursorConfig config, boolean writeAllowed) throws DatabaseException { return view.currentTxn.openCursor( view.db, config, isWriteCursor(config, writeAllowed), view.useTransaction()); }
/** Returns the key object for the last record read. */ Object getCurrentKey() throws DatabaseException { return view.makeKey(keyThang, primaryKeyThang); }
/** Returns the value object for the last record read. */ Object getCurrentValue() throws DatabaseException { return view.makeValue(primaryKeyThang, valueThang); }
/** Binding version of Cursor.putAfter(). */ OperationStatus putAfter(Object value) throws DatabaseException { checkWriteAllowed(false); view.useValue(value, valueThang, null); /* why no key check? */ return cursor.putAfter(keyThang, valueThang); }
/** Binding version of Cursor.putBefore(). */ OperationStatus putBefore(Object value) throws DatabaseException { checkWriteAllowed(false); view.useValue(value, valueThang, keyThang); return cursor.putBefore(keyThang, valueThang); }
/** Creates a cursor for a given view and single key range. Used by unit tests. */ DataCursor(DataView view, boolean writeAllowed, Object singleKey) throws DatabaseException { init(view, writeAllowed, null, view.subRange(view.range, singleKey)); }
protected void reinstateToolbar() { // reinstate the toolbar synchronized (dataView) { dataView.resetToolbar(false); } }