public static void main(String[] args) { DataLoader dataLoader = new DataLoader(); boolean success = dataLoader.performUpdate(); if (success) System.out.println("Update successful"); else System.out.println("Update was not successful"); }
protected void processRequest(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final Boolean[] isRunning = new Boolean[] {true}; final DataLoader dataLoader = DataLoader.getInstance(); resp.setContentType("video/mpeg"); final IDataLoaderCallback callback = new IDataLoaderCallback() { @Override public void dataReceived(byte[] bytes) { try { resp.getOutputStream().write(bytes); } catch (Throwable e) { isRunning[0] = false; } finally { dataLoader.removeCallback(this); } } }; dataLoader.addCallback(callback); synchronized (dataLoader) { String ipParam = req.getParameter(KEY_IP); if (ipParam == null || ipParam.trim().equals("")) { ipParam = "192.168.8.156"; } final String ip = ipParam; String user = req.getParameter(KEY_USER); String pw = req.getParameter(KEY_PASSWORD); if (user == null || user.trim().equals("")) { user = "******"; } if (pw == null || pw.trim().equals("")) { pw = "password"; } dataLoader.init(ip, user, pw); } while (isRunning[0]) { try { Thread.sleep(1000L); } catch (Exception e) { isRunning[0] = false; dataLoader.removeCallback(callback); break; } } }
public Test2DVisualizer() throws Exception { JPanel p = Visualizer2D.getChartPanel(DataLoader.loadPrototypes(file)); this.setContentPane(p); this.setVisible(true); Toolkit toolkit = Toolkit.getDefaultToolkit(); this.setSize(toolkit.getScreenSize()); }
/** Changes directly the filesystem attribute. */ protected void doSetPreferredLoader(FileObject fo, DataLoader loader) throws IOException { if (loader == null) { fo.setAttribute("NetBeansAttrAssignedLoader", null); } else { Class c = loader.getClass(); fo.setAttribute("NetBeansAttrAssignedLoader", c.getName()); } }
private void SetModify(int itemIndex) { Item current = DataLoader.getItemById(itemIndex); if (current != null) { CurrentModifyWindowId = itemIndex; ModifyItem.SetParent(MainFrame); Driver.GetGuiMain().GetTextBoxes(); ((TextLabel) ModifyItem.GetChild("Id")).SetText("ID #" + itemIndex); ((TextBox) ModifyItem.GetChild("TitleInput")).SetText(current.getName()); ((TextBox) ModifyItem.GetChild("ArtistInput")).SetText(current.getCreator()); ((TextBox) ModifyItem.GetChild("YearInput")).SetText("" + current.getYearOfRelease()); ((TextBox) ModifyItem.GetChild("GenreInput")).SetText(current.getGenre()); ((TextBox) ModifyItem.GetChild("CostInput")).SetText("" + current.getPrice()); ((TextBox) ModifyItem.GetChild("DurationInputH")).SetText("" + current.getHour()); ((TextBox) ModifyItem.GetChild("DurationInputM")).SetText("" + current.getMinute()); ((TextBox) ModifyItem.GetChild("DurationInputS")).SetText("" + current.getSecond()); ((TextBox) ModifyItem.GetChild("PreviewInput")).SetText("" + current.getPreview()); ((CheckBox) ModifyItem.GetChild("HiddenInput")).SetSelected(current.isVisible()); ((CheckBox) ModifyItem.GetChild("HiddenInput")) .SetText( ((CheckBox) ModifyItem.GetChild("HiddenInput")).GetSelected() ? "true" : "false"); } }
/* package */ static boolean handleLocalFile(String url, LoadListener loadListener, WebSettings settings) { if (URLUtil.isAssetUrl(url)) { FileLoader.requestUrl( url, loadListener, loadListener.getContext(), true, settings.getAllowFileAccess()); return true; } else if (URLUtil.isFileUrl(url)) { FileLoader.requestUrl( url, loadListener, loadListener.getContext(), false, settings.getAllowFileAccess()); return true; } else if (URLUtil.isContentUrl(url)) { // Send the raw url to the ContentLoader because it will do a // permission check and the url has to match.. ContentLoader.requestUrl(loadListener.url(), loadListener, loadListener.getContext()); return true; } else if (URLUtil.isDataUrl(url)) { DataLoader.requestUrl(url, loadListener); return true; } else if (URLUtil.isAboutUrl(url)) { loadListener.data(mAboutBlank.getBytes(), mAboutBlank.length()); loadListener.endData(); return true; } return false; }
@Test public void shouldLoadGeeks() { new DataLoader().doJob(); assertThat(DataLoader.geeks()).isNotEmpty(); assertThat(DataLoader.geeks().get(0).getNom()).isEqualTo("Antoine"); }
// @Transactional public void loadData() { DataLoader dataLoader = new DataLoader(); try { Map<BigInteger, Supplier> suppliers = dataLoader.loadSuppliers("suppliers.xml"); System.out.println(suppliers.keySet()); logger.info("loadData : Persisting " + suppliers.size() + " suppliers"); for (Supplier s : suppliers.values()) { supplierDAO.create(s); } Map<String, Customer> customers = dataLoader.loadCustomers("customers.xml"); logger.info("loadData : Persisting " + customers.size() + " customers"); for (Customer c : customers.values()) { customerDAO.create(c); } Map<BigInteger, Category> categories = dataLoader.loadCategories("categories.xml"); logger.info("loadData : Persisting " + categories.size() + " categories"); for (Category c : categories.values()) { categoryDAO.create(c); } Map<BigInteger, Shipper> shippers = dataLoader.loadShippers("shippers.xml"); logger.info("loadData : Persisting " + shippers.size() + " shippers"); for (Shipper s : shippers.values()) { shipperDAO.create(s); } Map<BigInteger, Product> products = dataLoader.loadProducts("products.xml", suppliers, categories); logger.info("loadData : Persisting " + products.size() + " products"); for (Product p : products.values()) productDAO.create(p); Map<BigInteger, Employee> employees = dataLoader.loadEmployees("employees.xml"); logger.info("loadData : Persisting " + employees.size() + " employees"); for (Employee e : employees.values()) { try { employeeDAO.create(e); } catch (Exception es) { logger.warn(es.getMessage()); } } logger.info("Loading orders with details"); Map<BigInteger, Order> orders = dataLoader.loadOrders("orders_rand_10000.xml", customers, employees, shippers); orders.putAll(dataLoader.loadOrders("orders_rand_20000.xml", customers, employees, shippers)); Map<Integer, OrderDetails> orderDetails = dataLoader.loadOrderDetails("orderdetails_rand_10000.xml", orders, products); orderDetails.putAll( dataLoader.loadOrderDetails("orderdetails_rand_20000.xml", orders, products)); Map<Order, List<OrderDetails>> orderToOrderDetails = buildOrderToOrderDetailsMap(orderDetails); for (OrderDetails od : orderDetails.values()) { od.getOrderID().addOrderDetails(od); } List<Order> orderList = new ArrayList<Order>(orders.values()); logger.info("Orders persisting:"); int size = orderList.size(); int i = 0; long start, stop = 0; StringBuilder builder = new StringBuilder(); for (int j = 1000; j < size; j += 1000) { start = System.currentTimeMillis(); entityManager.getTransaction().begin(); while (i < j) { // entityManager.persist(orderList.get(i)); orderDAO.create(orderList.get(i)); i++; } entityManager.getTransaction().commit(); stop = System.currentTimeMillis(); builder.append((j / 1000) + " : " + (stop - start) + "\n"); logger.info("Orders round: " + j / 1000 + " : " + (stop - start)); } System.out.println(builder.toString()); } catch (Exception e) { e.printStackTrace(); } }
public static void main(String[] args) { // the name of the database String databaseName = "apriori"; // the name and password of the administrator of the database String administratorName = SampleProperties.administratorName; String administratorPassword = SampleProperties.administratorPassword; // create a session XhiveDriverIf driver = XhiveDriverFactory.getDriver(); driver.init(1024); XhiveSessionIf session = driver.createSession(); try { // open a connection to the database session.connect(administratorName, administratorPassword, databaseName); // create a Reporter for some nice output Reporter rep = new Reporter(); // begin the transaction session.begin(); // get a handle to the database XhiveDatabaseIf united_nations_db = session.getDatabase(); // get a handle to the root library XhiveLibraryIf rootLibrary = united_nations_db.getRoot(); // get/create the "UN Charter" library XhiveLibraryIf charterLib = DataLoader.createLibrary(united_nations_db, rootLibrary, "UN Charter", session); // load the sample documents DataLoader.storeDocuments(united_nations_db, charterLib, session); // retrieve the documents thru DOM operations System.out.println("\n#Retrieving documents thru DOM operations..."); // count the number of children of the "UN Charter" library int nrChildren = 0; if (charterLib.hasChildNodes()) { Node n = charterLib.getFirstChild(); while (n != null) { nrChildren++; n = n.getNextSibling(); } } System.out.println("library \"UN Charter\" has " + nrChildren + " children"); // retrieve the documents by ID System.out.println("\n#Retrieving documents by ID..."); int anId = 10; Node child = charterLib.get(anId); System.out.println( "document with ID = " + anId + " in \"UN Charter\" has name: " + ((XhiveLibraryChildIf) child).getName()); // retrieve the documents by name System.out.println("\n#Retrieving documents by name..."); String documentName = "UN Charter - Chapter 2"; Document docRetrievedByName = (Document) charterLib.get(documentName); System.out.println( "the ID of the document with name \"" + documentName + "\" is: " + ((XhiveLibraryChildIf) docRetrievedByName).getId()); // retrieve the name of the document by executeFullPathXPointerQuery (FPXPQ) System.out.println("\n#Retrieving documents by executeFullPathXPointerQuery..."); Document docRetrievedByFPXPQ = (Document) rootLibrary.getByPath("/UN Charter/UN Charter - Chapter 2"); System.out.println(docRetrievedByFPXPQ.toString()); // use FPXPQ with a relative path System.out.println( "\n#Retrieving documents by executeFullPathXPointerQuery - using relative path..."); // create a new sub library of UN Charter XhiveLibraryIf newLib = charterLib.createLibrary(XhiveLibraryIf.LOCK_WITH_PARENT); newLib.setName("sub library of UN Charter"); charterLib.appendChild(newLib); // execute the FullPathXPointerQuery relative to the new sub library docRetrievedByFPXPQ = (Document) newLib.getByPath("../UN Charter - Chapter 3"); System.out.println(docRetrievedByFPXPQ.toString()); // and delete the sub library charterLib.removeChild(newLib); session.commit(); } catch (Exception e) { System.out.println("RetrieveDocuments sample failed: "); e.printStackTrace(); } finally { // disconnect and remove the session if (session.isOpen()) { session.rollback(); } if (session.isConnected()) { session.disconnect(); } driver.close(); } }
@Override public void ButtonClicked(GuiObject button, int x, int y) { switch (button.GetName()) { case "LibraryButton": CurrentList = 0; break; case "StoreButton": CurrentList = 4; break; case "ViewAlbums": CurrentList = 1; break; case "ViewAudiobooks": CurrentList = 2; break; case "ViewFilms": CurrentList = 3; break; case "ManagementButton": currentUser = Driver.CurrentUser; if (currentUser.getAdministrator()) { Driver.SetFrame("Management"); } else { JOptionPane.showMessageDialog( null, "Access denied - Admin only", "", JOptionPane.WARNING_MESSAGE); } break; case "Action": // "Buy" or "Play" button pressed. if (button instanceof TextButton && ((TextButton) button).GetText().equals("Buy") && CurrentList >= 1 && CurrentList <= 3) { int id = GetItemIdOfFrame((Frame) button.GetParent()); System.out.println("Pressed buy for item: " + id); boolean success = Driver.CurrentUser.purchaseItem(id); if (success) { ((TextButton) button).SetText("Play"); } else { System.out.println("Buy failed."); } } else if (button instanceof TextButton && ((TextButton) button).GetText().equals("Play") && CurrentList == 0) { int id = GetItemIdOfFrame((Frame) button.GetParent()); if (CurrentPlayingItem != null) { CurrentPlayingItem.stopAudio(); } CurrentPlayingItem = DataLoader.getItemById(id); CurrentPlayingItem.playAudioFull(); } else if (button instanceof TextButton && ((TextButton) button).GetText().equals("Stop") && CurrentPlayingItem != null) { CurrentPlayingItem.stopAudio(); CurrentPlayingItem = null; } else if (button instanceof TextButton && ((TextButton) button).GetText().equals("Play") && CurrentList >= 1 && CurrentList <= 3) { int id = GetItemIdOfFrame((Frame) button.GetParent()); CurrentPlayingItem = DataLoader.getItemById(id); CurrentPlayingItem.playAudioPreview(); } AccountCredit.SetText(String.format("Credit: $%.2f", Driver.CurrentUser.getCredit())); break; case "AccountCredit": MainFrame.AddChild(CreditAdd); Driver.GetGuiMain().GetTextBoxes(); break; case "CreditAdd": double amount = 0; try { amount = Double.parseDouble(((TextBox) CreditAdd.GetChild("Input")).GetText()); } catch (Exception e) { } Driver.CurrentUser.grantCredit(amount); MainFrame.RemoveChild(CreditAdd); Driver.GetGuiMain().GetTextBoxes(); break; case "Input": if (button instanceof TextBox && ((TextBox) button).GetText().equals("Credit")) { ((TextBox) button).SetText(""); } break; case "Action2": if (button instanceof TextButton && ((TextButton) button).GetText().equals("Edit") && CurrentList >= 0 && CurrentList <= 4) { int id = GetItemIdOfFrame((Frame) button.GetParent()); SetModify(id); } else if (button instanceof TextButton && ((TextButton) button).GetText().equals("Rate") && CurrentList == 0) { CurrentRatingId = GetItemIdOfFrame((Frame) button.GetParent()); RatingWindow.SetParent(MainFrame); RatingWindow.SetPosition(new DPair(0, x - RatingWindow.GetSize().xOffset, 0, y)); Driver.GetGuiMain().GetTextBoxes(); } break; case "HiddenInput": ((CheckBox) button).SetText(((CheckBox) button).GetSelected() ? "true" : "false"); break; case "SubmitChanges": Item current = DataLoader.getItemById(CurrentModifyWindowId); if (current != null) { current.setCreator(((TextBox) ModifyItem.GetChild("ArtistInput")).GetText()); current.setName(((TextBox) ModifyItem.GetChild("TitleInput")).GetText()); try { current.setYearOfRelease( Integer.parseInt(((TextBox) ModifyItem.GetChild("YearInput")).GetText())); } catch (Exception e) { } current.setGenre(((TextBox) ModifyItem.GetChild("GenreInput")).GetText()); try { current.setPrice( Double.parseDouble(((TextBox) ModifyItem.GetChild("CostInput")).GetText())); } catch (Exception e) { } int d = 0; try { d += Integer.parseInt(((TextBox) ModifyItem.GetChild("DurationInputH")).GetText()) * 3600; } catch (Exception e) { } try { d += Integer.parseInt(((TextBox) ModifyItem.GetChild("DurationInputM")).GetText()) * 60; } catch (Exception e) { } try { d += Integer.parseInt(((TextBox) ModifyItem.GetChild("DurationInputS")).GetText()); } catch (Exception e) { } current.setDuration(d); current.setPreview(((TextBox) ModifyItem.GetChild("PreviewInput")).GetText()); current.setHidden(((CheckBox) ModifyItem.GetChild("HiddenInput")).GetSelected()); } ModifyItem.SetParent(null); Driver.GetGuiMain().GetTextBoxes(); break; case "CloseModifyWindow": ModifyItem.SetParent(null); Driver.GetGuiMain().GetTextBoxes(); break; case "CloseHelpWindow": Help.SetParent(null); Driver.GetGuiMain().GetTextBoxes(); break; case "Help": Help.SetParent(MainFrame); Driver.GetGuiMain().GetTextBoxes(); break; case "1star": System.out.println("CurrentRatingId: " + CurrentRatingId); Driver.CurrentUser.rateItem(CurrentRatingId, 1); RatingWindow.SetParent(null); Driver.GetGuiMain().GetTextBoxes(); break; case "2star": Driver.CurrentUser.rateItem(CurrentRatingId, 2); RatingWindow.SetParent(null); Driver.GetGuiMain().GetTextBoxes(); break; case "3star": Driver.CurrentUser.rateItem(CurrentRatingId, 3); RatingWindow.SetParent(null); Driver.GetGuiMain().GetTextBoxes(); break; case "4star": Driver.CurrentUser.rateItem(CurrentRatingId, 4); RatingWindow.SetParent(null); Driver.GetGuiMain().GetTextBoxes(); break; case "5star": Driver.CurrentUser.rateItem(CurrentRatingId, 5); RatingWindow.SetParent(null); Driver.GetGuiMain().GetTextBoxes(); break; case "0star": Driver.CurrentUser.rateItem(CurrentRatingId, 0); RatingWindow.SetParent(null); Driver.GetGuiMain().GetTextBoxes(); break; } SetFrames(); }
private void SetFrames() { AccountCredit.SetText(String.format("Credit: $%.2f", Driver.CurrentUser.getCredit())); Frame current; TextLabel rowOne; TextLabel rowTwo; TextButton commandButton; if (LastCurrentListValue != CurrentList) { ArrayList temporaryList = null; ActiveList.clear(); if (CurrentList == 0) { temporaryList = Driver.CurrentUser.getPurchaseHistory(); } else if (CurrentList == 1) { temporaryList = DataLoader.getAlbums(); } else if (CurrentList == 2) { temporaryList = DataLoader.getAudiobooks(); } else if (CurrentList == 3) { temporaryList = DataLoader.getFilm(); } if (CurrentList >= 1 && CurrentList <= 3) { // if the use is looking at a store page, weed out all invisible songs/albums *unless* it is // a administrator. for (int i = 0; i < temporaryList.size(); i++) { if (temporaryList.get(i) instanceof Item && (!((Item) temporaryList.get(i)).isVisible() || Driver.CurrentUser.getAdministrator())) { ActiveList.add(temporaryList.get(i)); } } } else if (CurrentList == 0) { for (int i = 0; i < temporaryList.size(); i++) { ActiveList.add(temporaryList.get(i)); } } else if (CurrentList == 4) { temporaryList = DataLoader.getAlbums(); for (int i = 0; i < temporaryList.size(); i++) { if (temporaryList.get(i) instanceof Item && (!((Item) temporaryList.get(i)).isVisible() || Driver.CurrentUser.getAdministrator())) { ActiveList.add(temporaryList.get(i)); } } temporaryList = DataLoader.getAudiobooks(); for (int i = 0; i < temporaryList.size(); i++) { if (temporaryList.get(i) instanceof Item && (!((Item) temporaryList.get(i)).isVisible() || Driver.CurrentUser.getAdministrator())) { ActiveList.add(temporaryList.get(i)); } } temporaryList = DataLoader.getFilm(); for (int i = 0; i < temporaryList.size(); i++) { if (temporaryList.get(i) instanceof Item && (!((Item) temporaryList.get(i)).isVisible() || Driver.CurrentUser.getAdministrator())) { ActiveList.add(temporaryList.get(i)); } } } LastCurrentListValue = CurrentList; } // this should never happen, but just in case it does, break the function before an error is // thrown. if (ActiveList == null) { return; } int MaximumIndex = ActiveList.size(); LibScroll.SetMax( Math.max( 0, MaximumIndex * (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING) - Driver.GetGuiMain().GetWindow().getHeight() + 50)); PixelOffset = (int) LibScroll.GetValue(); ViewIndex = (int) Math.floor((double) PixelOffset / (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING)); for (int i = 0; i < ScrollList.size(); i++) { // Position the frame appropriately. current = ScrollList.get(i); current.GetPosition().yOffset = i * (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING) - PixelOffset % (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING); rowOne = (TextLabel) current.GetChild("TopText"); rowTwo = (TextLabel) current.GetChild("BottomText"); commandButton = (TextButton) current.GetChild("Action"); // If the index we're looking for is out of bounds, don't display the frame. if (i + ViewIndex >= MaximumIndex) { CenterScrollFrame.RemoveChild(current); } else { CenterScrollFrame.AddChild(current); // Fill the text labels with content based on what view option is selected. if (CurrentList == 0) { if (!current.GetChild("Action2").GetVisible() && !Driver.CurrentUser.getAdministrator()) { current.GetChild("Divider").GetPosition().xOffset = -99; current.GetChild("TopText").GetSize().xOffset = -105; current.GetChild("BottomText").SetSize(current.GetChild("TopText").GetSize()); current.GetChild("Action2").SetVisible(true); ((TextButton) current.GetChild("Action2")).SetText("Rate"); Driver.GetGuiMain().GetTextBoxes(); } Item currentItem = DataLoader.getItemById(((Integer) ActiveList.get(i + ViewIndex)).intValue()); SetListText(rowOne, rowTwo, currentItem); if (CurrentPlayingItem == currentItem) { commandButton.SetText("Stop"); } else { commandButton.SetText("Play"); } } else if (CurrentList >= 1 && CurrentList <= 4) { if (current.GetChild("Action2").GetVisible() && !Driver.CurrentUser.getAdministrator()) { current.GetChild("Divider").GetPosition().xOffset = -52; current.GetChild("TopText").GetSize().xOffset = -58; current.GetChild("BottomText").SetSize(current.GetChild("TopText").GetSize()); current.GetChild("Action2").SetVisible(false); } Item currentItem = (Item) ActiveList.get(i + ViewIndex); SetListText(rowOne, rowTwo, currentItem); if (currentItem.isVisible()) { rowTwo.SetText(rowTwo.GetText() + "; HIDDEN"); } if (Driver.CurrentUser.getPurchaseHistory().contains(currentItem.getId())) { if (CurrentPlayingItem == currentItem) { commandButton.SetText("Stop"); } else { commandButton.SetText("Play"); } } else { commandButton.SetText("Buy"); } } } } }
@Override protected void asyncLoad() { // TODO Auto-generated method stub super.asyncLoad(); new AsyncDataLoader(asyncRemoteLoadListener).execute(); }