Gridgain version: 6.5.5
Cache mode: replaced
Cache K-V type: [Integer, Integer []]
Node startup mode: CMD ggstart -v -i
Problem description: When I'm start only one node, it can calculate correctly and the result is right, however, when I'm start multiple node with the example, it doesn't work and the exception information as follows.
SampleComputeNumTask.java:
#Override
public Collection<CbJob<Long, Integer[]>> splitJob(Serializable... args) throws CJobExcuteException {
Collection<CbJob<Long, Integer[]>> list = new ArrayList<CbJob<Long, Integer[]>>();
loadCache(args);
GridCache<Integer, Integer[]> cache = grid.cache("share-hqfx");
for (GridCacheEntry<Integer, Integer[]> entry : cache.entrySet()) {
list.add(new CbJob<Long, Integer[]>(entry.getKey(), new MyCall(), entry.getValue()));
}
return list;
}
#Override
public void loadCache(Serializable... args) throws CJobExcuteException {
GridCache<Integer, Integer[]> cache = grid.cache("share-hqfx");
try {
cache.globalClearAll(0);
} catch (GridException e1) {
e1.printStackTrace();
}
int j = 0;
int a = 0;
int len = args == null ? 1000 : (Integer) args[0];
Integer[] arg = new Integer[len];
for (int i = 1; i < 1000000; i++) {
arg[a] = i;
a++;
if (a == 1000 || i == 1000000) {
++j;
try {
cache.putx(j, arg);
} catch (GridException e) {
e.printStackTrace();
}
a = 0;
arg = new Integer[1000];
}
}
}
Exception trace:
[16:02:03,880][ERROR][gridgain-#60%rest-null%][GridDhtAtomicUpdateFuture] Failed to send update request to backup node (did node leave the grid?): 5e1b14d3-eb17-499d-9f0e-0de9a4a00c90
class org.gridgain.grid.GridException: Failed to deploy class for local deployment [clsName=java.lang.Integer, ldr=GridUriDeploymentClassLoader [urls=[file:/F:/gridgain-fabric-ent/tmp/grid/gg.uri.deployment.tmp/41ed7058-4555-47d7-83e2-773436b2d12e/dirzip_SampleComputeTask5391357847454873740.gar/]]]
For more information see:
Troubleshooting: http://bit.ly/GridGain-Troubleshooting
Documentation Center: http://bit.ly/GridGain-Documentation
at org.gridgain.grid.kernal.processors.cache.GridCacheDeploymentManager.registerClass(GridCacheDeploymentManager.java:624)
at org.gridgain.grid.kernal.processors.cache.GridCacheDeploymentManager.registerClass(GridCacheDeploymentManager.java:562)
at org.gridgain.grid.kernal.processors.cache.GridCacheMessage.prepareObject(GridCacheMessage.java:181)
at org.gridgain.grid.kernal.processors.cache.GridCacheMessage.marshalCollection(GridCacheMessage.java:478)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridDhtAtomicUpdateRequest.prepareMarshal(GridDhtAtomicUpdateRequest.java:576)
at org.gridgain.grid.kernal.processors.cache.GridCacheIoManager.onSend(GridCacheIoManager.java:334)
at org.gridgain.grid.kernal.processors.cache.GridCacheIoManager.send(GridCacheIoManager.java:362)
at org.gridgain.grid.kernal.processors.cache.GridCacheIoManager.send(GridCacheIoManager.java:350)
at org.gridgain.grid.kernal.processors.cache.GridCacheIoManager.send(GridCacheIoManager.java:557)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridDhtAtomicUpdateFuture.map(GridDhtAtomicUpdateFuture.java:324)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateAllAsyncInternal0(GridDhtAtomicCache.java:1005)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateAllAsyncInternal(GridDhtAtomicCache.java:854)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture.mapSingle(GridNearAtomicUpdateFuture.java:740)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture.map0(GridNearAtomicUpdateFuture.java:581)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture.mapOnTopology(GridNearAtomicUpdateFuture.java:454)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture.map(GridNearAtomicUpdateFuture.java:319)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$13.apply(GridDhtAtomicCache.java:662)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$13.apply(GridDhtAtomicCache.java:660)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.asyncOp(GridDhtAtomicCache.java:584)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateAllAsync0(GridDhtAtomicCache.java:660)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.putxAsync(GridDhtAtomicCache.java:343)
at org.gridgain.grid.kernal.processors.cache.GridCacheAdapter.putxAsync(GridCacheAdapter.java:2284)
at org.gridgain.grid.kernal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.putx(GridDhtAtomicCache.java:329)
at org.gridgain.grid.kernal.processors.cache.GridCacheProxyImpl.putx(GridCacheProxyImpl.java:705)
at com.topgether.cbgrid.datagrid.SampleComputeNumTask.loadCache(SampleComputeNumTask.java:64)
at com.topgether.cbgrid.datagrid.SampleComputeNumTask.splitJob(SampleComputeNumTask.java:38)
at com.topgether.cbgrid.datagrid.CGridTask.split(CGridTask.java:53)
at com.topgether.cbgrid.datagrid.CGridTask.split(CGridTask.java:1)
at org.gridgain.grid.compute.GridComputeTaskSplitAdapter.map(GridComputeTaskSplitAdapter.java:111)
at org.gridgain.grid.kernal.processors.task.GridTaskWorker$2.call(GridTaskWorker.java:404)
at org.gridgain.grid.kernal.processors.task.GridTaskWorker$2.call(GridTaskWorker.java:402)
at org.gridgain.grid.util.GridUtils.wrapThreadLoader(GridUtils.java:6078)
at org.gridgain.grid.kernal.processors.task.GridTaskWorker.body(GridTaskWorker.java:401)
at org.gridgain.grid.util.worker.GridWorker.run(GridWorker.java:151)
at org.gridgain.grid.kernal.processors.task.GridTaskProcessor.startTask(GridTaskProcessor.java:607)
at org.gridgain.grid.kernal.processors.task.GridTaskProcessor.execute(GridTaskProcessor.java:365)
at org.gridgain.grid.kernal.GridComputeImpl.execute(GridComputeImpl.java:122)
at org.gridgain.grid.kernal.processors.rest.handlers.task.GridTaskCommandHandler.handleAsyncUnsafe(GridTaskCommandHandler.java:191)
at org.gridgain.grid.kernal.processors.rest.handlers.task.GridTaskCommandHandler.handleAsync(GridTaskCommandHandler.java:138)
at org.gridgain.grid.kernal.processors.rest.GridRestProcessor.handleRequest(GridRestProcessor.java:203)
at org.gridgain.grid.kernal.processors.rest.GridRestProcessor.access$100(GridRestProcessor.java:61)
at org.gridgain.grid.kernal.processors.rest.GridRestProcessor$2.body(GridRestProcessor.java:109)
at org.gridgain.grid.util.worker.GridWorker.run(GridWorker.java:151)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Configuration:
<bean id="grid.cfg" class="org.gridgain.grid.GridConfiguration">
<!-- Cache configurations. -->
<property name="cacheConfiguration">
<list>
<bean class="org.gridgain.grid.cache.GridCacheConfiguration">
<property name="name" value="share-hqfx" />
<property name="cacheMode" value="REPLICATED" />
<property name="queryIndexEnabled" value="true" />
</bean>
</list>
</property>
<property name="restJettyPath" value="#{ systemEnvironment['GRIDGAIN_HOME'] }/config/jetty-config.xml" />
<property name="deploymentSpi">
<bean class="org.gridgain.grid.spi.deployment.uri.GridUriDeploymentSpi">
<property name="temporaryDirectoryPath" value="#{ systemEnvironment['GRIDGAIN_HOME'] }/tmp/grid" />
</bean>
</property>
<property name="discoverySpi">
<bean class="org.gridgain.grid.spi.discovery.tcp.GridTcpDiscoverySpi">
<property name="ipFinder">
<bean class="org.gridgain.grid.spi.discovery.tcp.ipfinder.vm.GridTcpDiscoveryVmIpFinder">
<property name="addresses">
<list>
<!-- In distributed environment, replace with actual host IP address. -->
<value>127.0.0.1:47500..47509</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
<property name="deploymentMode" value="CONTINUOUS" />
</bean>
Related
I'm trying to replace one node containing 3 subnodes with a new node, containing 2 subnodes.
The replaceNode function (http://docs.groovy-lang.org/latest/html/api/groovy/util/slurpersupport/GPathResult.html) only accepts Closure, and not an object like replaceBody does.
However, replaceBody replaces the body of the node, not the actual node.
I made a simplified example, which can be ran in https://groovyconsole.appspot.com/
import groovy.util.slurpersupport.*;
import groovy.xml.XmlUtil;
class swarco_updated_example_replace_node_test_simple {
static void main(def args){
/* Overlapping entries */
String xmlorg3entries = '''
<map>
<value>
<!-- Overlapping registrations -->
<map>
<name>blabla</name>
<fruits>
<map>
<type>pear</type>
<color>green</color>
</map>
<map>
<type>orange</type>
<color>orange</color>
</map>
<map>
<type>cherry</type>
<color>red</color>
</map>
</fruits>
</map>
</value>
</map>
''';
String xmlreplace2entries = '''
<fruits>
<map>
<type>grapes</type>
<color>green</color>
</map>
<map>
<type>apples</type>
<color>green</color>
</map>
</fruits>
''';
printNodeReplace(xmlorg3entries, xmlreplace2entries);
}
static def printNodeReplace(mainNodeAsString, insertNodeAsString){
//https://stackoverflow.com/questions/30352052/inserting-xml-snippet-into-another-xml-document-in-groovy
def bodyNode = new XmlSlurper( false, false, false ).parseText( mainNodeAsString );
def fragmentNode = new XmlSlurper( false, false, false ).parseText( insertNodeAsString );
//fails
//bodyNode.value.map.fruits.replaceNode(fragmentNode);
bodyNode.value.map.fruits.replaceBody(fragmentNode);
println XmlUtil.serialize(bodyNode);
}
}
The result is a duplicated node. What is the proper way to do this? Clear the existing node and use append for each entry?
<?xml version="1.0" encoding="UTF-8"?><map>
<value>
<map>
<name>blabla</name>
<fruits>
<fruits>
<map>
<type>grapes</type>
<color>green</color>
</map>
<map>
<type>apples</type>
<color>green</color>
</map>
</fruits>
</fruits>
</map>
</value>
</map>
use fragmentNode.children() to append children of the fragmentNode
bodyNode.value.map.fruits.replaceBody(fragmentNode.children());
I'm trying to connect to Hive from .netcore (v. 1.0.1) app on linux (Red Hat 7.3 64-bit).
Program.cs code:
using System;
using System.Data.Odbc;
using System.Collections;
using System.Collections.Generic;
namespace app
{
class Program
{
static void Main(string[] args)
{
var connectionString = "DSN=Hadoop Hive";
var createTableCommandText = "CREATE TABLE Searches(searchTerm STRING, userid BIGINT,userIp STRING) " +
"COMMENT 'Stores all searches for data' " +
"PARTITIONED BY(searchTime DATE) " +
"STORED AS SEQUENCEFILE;";
using (var connection = new OdbcConnection(connectionString))
{
using (var command = new OdbcCommand(createTableCommandText, connection))
{
try
{
connection.Open();
// Create a table.
command.ExecuteNonQuery();
// Insert row of data.
command.CommandText = "INSERT INTO TABLE Searches PARTITION (searchTime = '2015-02-08') " +
"VALUES ('search term', 1, '127.0.0.1')";
command.ExecuteNonQuery();
// Reading data from Hadoop.
command.CommandText = "SELECT * FROM Searches";
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
for (var i = 0; i < reader.FieldCount; i++)
{
Console.WriteLine(reader[i]);
}
}
}
}
catch (OdbcException ex)
{
Console.WriteLine(ex.Message);
throw;
}
finally
{
Drop table
command.CommandText = "DROP TABLE Searches";
command.ExecuteNonQuery();
}
}
}
My project settings file:
app.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PackageId>HadoopLibrary</PackageId>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.0.1" />
<PackageReference Include="MSA.NetCore.ODBC" Version="1.0.3" />
</ItemGroup>
When running "dotnet run" I receive the following error:
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'odbc32.dll': The specified module could not be found.
(Exception from HRESULT: 0x8007007E)
at System.Data.Odbc.libodbc.SQLAllocHandle(OdbcHandleType HandleType, IntPtr InputHandle, IntPtr& OutputHandlePtr)
at System.Data.Odbc.OdbcConnection.Open()
at hwapp.Program.Main(String[] args)
Can anyone help how to fix that? The driver (Hortonworks ODBC for Hive) works on this server. There is an issue with the library for ODBC connection here.
it looks like you are trying to build and load it as a 32-bit application and that's what Hortonworks ODBC for Hive may not support. Need to check the documentation of Hortonworks for that.
I have the need to implement an integration flow made of multiple steps, where each step can be performed by a variable number of processors (plugins).
What I have so far:
<!-- gateway -->
<int:gateway default-request-channel="step/1" service-interface="ServiceGateway">
<int:method name="send" />
</int:gateway>
<!-- plugin 1 -->
<int:publish-subscribe-channel id="step/1" apply-sequence="true" />
<int:service-activator input-channel="step/1" output-channel="step/2">
<bean class="Transformer" />
</int:service-activator>
<int:service-activator input-channel="step/1" output-channel="step/2">
<bean class="Transformer2" />
</int:service-activator>
<!-- plugin 2 -->
<int:publish-subscribe-channel id="step/2" apply-sequence="true" />
<int:service-activator input-channel="step/2" output-channel="end">
<bean class="Transformer3" />
</int:service-activator>
<int:service-activator input-channel="step/2" output-channel="end">
<bean class="HttpTransformer4" />
</int:service-activator>
<!-- aggregation -->
<int:channel id="end" />
<int:aggregator input-channel="end" />
The expected behaviour is the following:
send the first request through the gateway
the input is processed by 2 "step/1" plugins
each output of the "step/1" plugins is processed by the "step/2" plugins
the aggregator should aggregate 4 items (1 -> 2 -> 4)
Everything is working fine but the result is not the expected, I receive only 2 (random) items instead of 4.
I suppose the problem is that the aggregator triggers the release after only two items because the "apply-sequence" in the "step/2" channel overwrites the "apply-sequence" in "step/1". So the question is: how can I make the aggregator wait for all the messages?
Thank you in advance.
Custom Release Strategy:
#SuppressWarnings("unchecked")
#Override
public boolean canRelease ( MessageGroup group ) {
MessageHeaders headers = group.getOne ().getHeaders ();
List<List<Object>> sequenceDetails = (List<List<Object>>) headers.get ( "sequenceDetails" );
System.out.println ( sequenceDetails );
int expectedSize = 1;
//map message id, max group size reached (i.e. sequenceNumber==sequenceSize)
for ( List<Object> sequenceItem : sequenceDetails ) {
if ( sequenceItem.get ( 1 ) != sequenceItem.get ( 2 ) ) {
System.err.println ( "--> AGG: no release check, group max not reached" );
return false;
}
expectedSize *= (int) sequenceItem.get ( 2 );//multiplies the group sizes
}
int expectedSize2 = expectedSize * (int) headers.get ( "sequenceSize" );
int currentSize = group.getMessages ().size () * expectedSize;
System.err.println ( "--> AGG: " + expectedSize2 + " : " + currentSize );
boolean canRelease = expectedSize2 == currentSize;
if ( canRelease ) {
System.out.println ( "ok" );
}
return canRelease;
}
Prints out:
[[7099b583-55d4-87d3-4502-993f05bfb388, 1, 2]]
--> AGG: no release check, group max not reached
[[7099b583-55d4-87d3-4502-993f05bfb388, 1, 2]]
--> AGG: no release check, group max not reached
[[7099b583-55d4-87d3-4502-993f05bfb388, 2, 2]]
--> AGG: 4 : 2
[[7099b583-55d4-87d3-4502-993f05bfb388, 2, 2]]
--> AGG: 4 : 4
Aggregation code:
#Aggregator
public Object aggregate ( List<Message<?>> objects ) {
List<Object> res = new ArrayList<> ();
for ( Message<?> m : objects ) {
res.add ( m.getPayload () );
MessageHeaders headers2 = m.getHeaders ();
System.out.println ( headers2.get ( "history" ) );
}
return res;
}
Prints out:
gateway2,core-channel,(inner bean)#57018165,async/step/1,core-channel,(inner bean)#57018165,async/step/2,core-channel,(inner bean)#57018165,end2
gateway2,core-channel,(inner bean)#57018165,async/step/1,core-channel,(inner bean)#57018165,async/step/2,core-channel,(inner bean)#57018165,end2
[102, 202] --> final result list, expected to be made of 4 items
Use a custom release strategy. The correlation data from the first pubsub is pushed onto a stack in the sequenceDetails headers by the second pubsub.
EDIT
The problem is there are two groups; you need to correlate on the initial correlationId. Here's a pure SpEL solution; it might be safer to use custom correlation/release strategies to ensure the data is as expected (and use getOne() instead of the iterator)...
<int:aggregator input-channel="end2"
correlation-strategy-expression=
"headers['sequenceDetails'][0][0]"
release-strategy-expression=
"size() == iterator().next().headers['sequenceSize'] * iterator().next().headers['sequenceDetails'][0][2]" />
I'm using RadGrid in ASPX, .net 4.5. The data comes up and displays in my grid fine, but I cannot update, insert, or delete records. I have followed the sample version as closely as I can:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx
When I try to modify data in the grid, then hit Save, the grid reloads and the data is unchanged. No errors, just no updates.
Originally I had the grid wrapped in ajax panel, but when these problems occurred, I removed it. That made not much difference; though when I was using ajax panel, often times clicking the Save icon did absolutely nothing. Or appeared to do nothing. So with that gone, the page/grid does normal postbacks EXCEPT that none of my event handlers are being called. Page_Load gets called, but nothing else (for example RadGrid1_BatchEditCommand, RadGrid1_ItemUpdated). It seems these should be getting called.
ASPX code:
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<telerik:RadListBox runat="server" ID="SavedChangesList" Width="600px" Height="200px" Visible="false"></telerik:RadListBox>
<telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticDeletes="True"
AllowAutomaticInserts="True" PageSize="10" Skin="Default" OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted"
OnItemUpdated="RadGrid1_ItemUpdated" OnPreRender="RadGrid1_PreRender" AllowAutomaticUpdates="True" AllowPaging="True"
AutoGenerateColumns="False" Width="1000px" OnBatchEditCommand="RadGrid1_BatchEditCommand" DataSourceID="sqlContractMatrix">
<MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="ID" DataSourceID="sqlContractMatrix" HorizontalAlign="NotSet" EditMode="Batch" AutoGenerateColumns="False">
<BatchEditingSettings EditType="Cell" />
<SortExpressions>
<telerik:GridSortExpression FieldName="SiteID,ProductID" SortOrder="Descending" />
</SortExpressions>
<Columns>
<telerik:GridTemplateColumn HeaderText="Site" HeaderStyle-Width="150px" UniqueName="SiteID" DataField="SiteID">
<ItemTemplate>
<%# Eval("SiteName") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownList runat="server" ID="ddlSites" AppendDataBoundItems="true" DataValueField="SiteID" DataTextField="SiteName" DataSourceID="sqlSites">
</telerik:RadDropDownList>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Product" HeaderStyle-Width="150px" UniqueName="ProductID" DataField="ProductID">
<ItemTemplate>
<%# Eval("ProductName") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownList runat="server" ID="ddlProducts" DropDownWidth="250" DropDownHeight="400" DefaultMessage="Product" AppendDataBoundItems="true" DataValueField="ProductID" DataTextField="ProductName" DataSourceID="sqlProducts">
</telerik:RadDropDownList>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridAttachmentColumn DataSourceID="sqlContractMatrix" MaxFileSize="1048576" HeaderStyle-Width="250px"
EditFormHeaderTextFormat="Upload File:" HeaderText="HTML Template" AttachmentDataField="BinaryData"
AttachmentKeyFields="ID" FileNameTextField="TemplateFileBinary" DataTextField="TemplateFileBinary"
UniqueName="TemplateFileBinary">
</telerik:GridAttachmentColumn>
<%--
<telerik:GridBoundColumn DataField="TemplateFile" HeaderStyle-Width="200px" HeaderText="Template"
SortExpression="TemplateFile" UniqueName="TemplateFile">
</telerik:GridBoundColumn>
--%>
<telerik:GridBoundColumn DataField="PDFName" HeaderStyle-Width="200px" HeaderText="PDF Name"
SortExpression="PDFName" UniqueName="PDFName">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn ConfirmText="Delete this record?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" HeaderText="Delete" HeaderStyle-Width="50px" ButtonType="ImageButton"
CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
</telerik:GridButtonColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="sqlContractMatrix" runat="server" ConnectionString="<%$ ConnectionStrings:FitTrack %>"
DeleteCommand="DELETE FROM ContractMatrix WHERE ID = #ID"
InsertCommand="INSERT INTO ContractMatrix (SiteID, ProductID, TemplateFile, PDFName, LastModifiedDate, LastModifiedByID) VALUES (#SiteID, #ProductID, #TemplateFile, #PDFName, #LastModifiedDate, #LastModifiedByID)"
UpdateCommand="UPDATE ContractMatrix SET SiteID = #SiteID, ProductID = #ProductID, TemplateFile = #TemplateFile, PDFName = #PDFName, LastModifiedDate = GETDATE(), LastModifiedByID = #LastModifiedByID WHERE ID = #ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="SiteID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="ProductID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="TemplateFile" Type="String"></asp:Parameter>
<asp:Parameter Name="PDFName" Type="String"></asp:Parameter>
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="SiteID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="ProductID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="TemplateFile" Type="String"></asp:Parameter>
<asp:Parameter Name="PDFName" Type="String"></asp:Parameter>
<asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
<!-- SQL data sources for various lookup tables -->
<asp:SqlDataSource ID="sqlSites" runat="server" ConnectionString="<%$ ConnectionStrings:FitTrack %>" ProviderName="System.Data.SqlClient" SelectCommand="SELECT SiteID, SiteName FROM gym.Site ORDER BY SiteID"></asp:SqlDataSource>
<asp:SqlDataSource ID="sqlProducts" runat="server" ConnectionString="<%$ ConnectionStrings:FitTrack %>" ProviderName="System.Data.SqlClient"></asp:SqlDataSource>
C# code:
protected void RadGrid1_BatchEditCommand(object sender, Telerik.Web.UI.GridBatchEditingEventArgs e)
{
SavedChangesList.Visible = true;
}
protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
{
GridEditableItem item = (GridEditableItem)e.Item;
string id = item.GetDataKeyValue("ID").ToString();
if (e.Exception != null)
{
e.KeepInEditMode = true;
e.ExceptionHandled = true;
NotifyUser("Record with ID " + id + " cannot be updated. Reason: " + e.Exception.Message);
}
else
{
NotifyUser("Record with ID " + id + " is updated!");
}
}
protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
NotifyUser("Product cannot be inserted. Reason: " + e.Exception.Message);
}
else
{
NotifyUser("New product is inserted!");
}
}
protected void RadGrid1_ItemDeleted(object source, GridDeletedEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.Item;
string id = dataItem.GetDataKeyValue("ID").ToString();
if (e.Exception != null)
{
e.ExceptionHandled = true;
NotifyUser("Product with ID " + id + " cannot be deleted. Reason: " + e.Exception.Message);
}
else
{
NotifyUser("Product with ID " + id + " is deleted!");
}
}
Please help. Why are the data updates not occurring? Why are none of the telerik events/methods in the codebehind being called? Only Page_Load() is executing, none of the others.
For me this was down to trying to use OnItemUpdated instead of OnUpdateCommand.
The ItemDeleted, ItemUpdated and ItemInserted events of RadGrid only work in combination with a directly bound ADO type DataSource. I'm using my own DAL so these 3 events weren't firing.
So the fix was to hook up the events OnUpdateCommand and OnDeleteCommand instead. The event handler looks something like this.
protected void radGrid_UpdateCommand(object sender, GridCommandEventArgs e)
{
var gridDataItem = ((GridDataItem)e.Item);
var table = gridDataItem.OwnerTableView;
var keyValues = table.DataKeyValues[gridDataItem.ItemIndex];
// Get key value.
var id = keyValues["id"];
// Get other values
var foo = ((TextBox)gridDataItem["foo"].Controls[0]).Text;
var bar = ((TextBox)gridDataItem["bar"].Controls[0]).Text;
myDAL.Update(id, foo, bar);
}
I'm trying to add several chunks of XML code from one file into another. The problem is, some of these chunks have root tags that don't need to be copied into the destination XML file (that's the case if the root tags equal the pre-defined parent tags). Here's the code I'm currently using to insert the snippet (written in Groovy):
if (addCode.nodeName == parentTags) { //meaning the root tags shouldn't be included
for (org.w3c.dom.Node n : addCode.childNodes) {
//parent is a NodeList
parent.item(parent.length - 1).appendChild(document.importNode(n, true))
}
} else {
parent.item(parent.length - 1).appendChild(document.importNode(addCode, true))
}
And to parse the XML:
Document parseWithoutDTD(Reader r, boolean validating = false, boolean namespaceAware = true) {
FactorySupport.createDocumentBuilderFactory().with { f ->
f.namespaceAware = namespaceAware
f.validating = validating
f.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
f.newDocumentBuilder().with { db ->
db.parse(new InputSource(r))
}
}
}
Here's an example XML file where the root tags shouldn't be included:
<catalogue> <!-- shouldn't be included -->
<message key='type_issuedate'>Date Issued</message>
<message key='type_accessioneddate'>Date Accesioned</message>
</catalogue>
You might have noticed the problem: if I leave out the root tags from the XML files to copy into the other XML file, they throw a parsing exception.
EDIT: here's an (shortened) example of the file to insert to:
<catalogue xml:lang="en" xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
...
<message key="column4">Date</message>
<message key="column5">Summary</message>
<message key="column6">Actions</message>
<message key="restore">Restore</message>
<message key="update">Update</message>
<!-- INSERT XML HERE -->
...
</catalogue>
And an example of XML with root tags to be included (and the corresponding file to insert to):
XML to insert
<dependency>
<groupId>grID</groupId>
<artifactId>artID</artifactId>
<version>${version.number}</version>
</dependency>
XML file to insert into
<?xml version="1.0" encoding="UTF-8"?>
<project>
<dependencies>
<dependency>
<groupId>grID1</groupId>
<artifactId>artID1</artifactId>
<type>jar</type>
<classifier>classes</classifier>
</dependency>
<!-- INSERT XML HERE -->
</dependencies>
</project>
Currently, all of this code isn't working as I want it to work. Can someone help me out?
Much appreciated!
I think (if I understand right), you need something like this:
def insert( parent, data ) {
if( parent.name() == data.name() ) {
data.children().each {
parent.append it
}
}
else {
parent.append data
}
}
So, given
def newdoc = '''<dependency>
| <groupId>grID</groupId>
| <artifactId>artID</artifactId>
| <version>${version.number}</version>
|</dependency>'''.stripMargin()
def doc = '''<?xml version="1.0" encoding="UTF-8"?>
|<project>
| <dependencies>
| <dependency>
| <groupId>grID1</groupId>
| <artifactId>artID1</artifactId>
| <type>jar</type>
| <classifier>classes</classifier>
| </dependency>
| </dependencies>
|</project>'''.stripMargin()
def docnode = new XmlParser().parseText( doc )
def newnode = new XmlParser().parseText( newdoc )
// use head() as I want to add to the first dependencies node
insert( docnode.dependencies.head(), newnode )
println groovy.xml.XmlUtil.serialize( docnode )
You get the output:
<?xml version="1.0" encoding="UTF-8"?><project>
<dependencies>
<dependency>
<groupId>grID1</groupId>
<artifactId>artID1</artifactId>
<type>jar</type>
<classifier>classes</classifier>
</dependency>
<dependency>
<groupId>grID</groupId>
<artifactId>artID</artifactId>
<version>${version.number}</version>
</dependency>
</dependencies>
</project>
And given:
def newdoc = '''<catalogue>
| <message key='type_issuedate'>Date Issued</message>
| <message key='type_accessioneddate'>Date Accesioned</message>
|</catalogue>'''.stripMargin()
def doc = '''<catalogue xml:lang="en" xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
| <message key="column4">Date</message>
| <message key="column5">Summary</message>
| <message key="column6">Actions</message>
| <message key="restore">Restore</message>
| <message key="update">Update</message>
|</catalogue>'''.stripMargin()
def docnode = new XmlParser().parseText( doc )
def newnode = new XmlParser().parseText( newdoc )
insert( docnode, newnode )
println groovy.xml.XmlUtil.serialize( docnode )
you get:
<?xml version="1.0" encoding="UTF-8"?><catalogue xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">
<message key="column4">Date</message>
<message key="column5">Summary</message>
<message key="column6">Actions</message>
<message key="restore">Restore</message>
<message key="update">Update</message>
<message key="type_issuedate">Date Issued</message>
<message key="type_accessioneddate">Date Accesioned</message>
</catalogue>
Edit
Ok, given the extra info, does this help? Given the same newdoc and doc strings as above, this script seems to do what you want...
import groovy.xml.*
import groovy.xml.dom.*
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
Document parseWithoutDTD(Reader r, boolean validating = false, boolean namespaceAware = true) {
FactorySupport.createDocumentBuilderFactory().with { f ->
f.namespaceAware = namespaceAware
f.validating = validating
f.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
f.newDocumentBuilder().with { db ->
db.parse(new InputSource(r))
}
}
}
def addCode = parseWithoutDTD( new StringReader( newdoc ) ).documentElement
def document = parseWithoutDTD( new StringReader( doc ) )
def parent = document.documentElement
def parentTags = 'catalogue'
use( DOMCategory ) {
if( addCode.nodeName == parentTags ) {
addCode.childNodes.each { node ->
parent.appendChild( document.importNode( node, true ) )
}
}
else {
parent.appendChild( document.importNode( addCode, true ) )
}
}