canal adapter deal with ddl and dml ,I don't understand the order in which they are executed - asyncdata

the code in com.alibaba.otter.canal.client.adapter.rdb.service.RdbMirrorDbSyncService#sync:
if (dml.getIsDdl() != null && dml.getIsDdl() && StringUtils.isNotEmpty(dml.getSql())) {
// executing DDL
...
executeDdl(mirrorDbConfig, dml);
....
} else {
// DML add to the list
initMappingConfig(dml.getTable(), mirrorDbConfig.getMappingConfig(), mirrorDbConfig, dml);
dmlList.add(dml);
}
}
if (!dmlList.isEmpty()) { // d
// doing dml list
}

Related

How to create a constraints, indexes and nodes in a single procedure/plugin call?

similarly the code is for creating indexes and millions of nodes the respective methods. This is for creating fresh DB from JSON file.
I encounter the following error:
Exception: Cannot perform data updates in a transaction that has performed schema updates. Simple begin transaction and close it doesn't work?
After some time the session crashes in CreateNodes() method?
How exactly we separate the schema creation and data update?
Also refer the question I have posted before trying to get the similar answer, but no success. (I tried both injecting GraphDatabaseService as well as with Bolt Driver the result is the same).
How to use neo4j bolt session/transaction in a procedure as plugin for neo4j server extension?
for (int command = 4; command < inputNeo4jCommands.size(); command++) {
log.info(inputNeo4jCommands.get(command));
NEO4JCOMMANDS cmnd = NEO4JCOMMANDS.valueOf(inputNeo4jCommands.get(command).toUpperCase());
log.info(NEO4JCOMMANDS.valueOf(inputNeo4jCommands.get(command).toUpperCase()).toString());
if (NEO4JCOMMANDS.CONSTRAINT.equals(cmnd)) {
CreateConstraints1();
}
if (NEO4JCOMMANDS.INDEX.equals(cmnd)) {
CreateIndexes();
}
if (NEO4JCOMMANDS.MERGE.equals(cmnd)) {
log.info("started creating nodes........");
CreateNodes();
}
}
private void CreateIndexes1() {
log.info("Adding indexes.....");
log.info("into started adding index ......");
try (Transaction tx = db.beginTx()) {
log.info("got a transaction .....hence started adding index ......");
Iterator<Indx> itIndex = json2neo4j.getIndexes().iterator();
while (itIndex.hasNext()) {
Indx indx = itIndex.next();
Label lbl = Label.label(indx.getLabelname());
Iterable<IndexDefinition> indexes = db.schema().getIndexes(lbl);
if (indexes.iterator().hasNext()) {
for (IndexDefinition index : indexes) {
for (String key : index.getPropertyKeys()) {
if (!key.equals(indx.getColName())) {
db.schema().indexFor(lbl).on(indx.getColName());
}
}
}
} else {
db.schema().indexFor(lbl).on(indx.getColName());
}
tx.success();
tx.close();
}
log.info("\nIndexes Created..................Retured the method call ");
}
}
A lot of context is missing from your question and code examples, so it's hard to give a definite answer. Where is the exception thrown in the code example? There's no CreateNodes() method, so we can't find out why it's failing (Out Of Memory Error due to a transaction too large?).
However, there's an issue with your transaction management in the CreateIndexes1() method (not following the Java naming conventions, by the way):
try (Transaction tx = db.beginTx()) {
// ...
while (/* ... */) {
// ...
tx.success();
tx.close();
}
}
You're closing the transaction multiple times, when it's actually in a try-with-resources block where you don't need to close it yourself at all:
try (Transaction tx = db.beginTx()) {
// ...
while (/* ... */) {
// ...
}
tx.success();
}
I guess json2neo4j is the deserialization of a JSON describing the indices to create on labels. The logic is flawed: you try to create an index for a property as soon as you find an index for another property, when you should find out if an index for the current property exists and only create the index if it's missing then.
for (Indx indx : json2neo4j.getIndexes()) {
Label lbl = Label.label(indx.getLabelname());
boolean indexExists = false;
for (IndexDefinition index : db.schema().getIndexes(lbl)) {
for (String property : index.getPropertyKeys()) {
if (property.equals(indx.getColName())) {
indexExists = true;
break;
}
}
if (indexExists) {
break;
}
}
if (!indexExists) {
db.schema().indexFor(lbl).on(indx.getColName());
}
}

Including the max and offset criteria inside GORM criteriaBuilder returns an error

Can I make this code shorter?
if(count == null && from = null) {
creditAdviceList = CreditAdvice.findAll {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
}
}
else if(count != null && from == null) {
creditAdviceList = CreditAdvice.findAll(max: count) {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
}
}
else if(count == null && from != null) {
creditAdviceList = CreditAdvice.findAll(offset: from) {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
}
}
else if(count != null && from != null) {
creditAdviceList = CreditAdvice.findAll(max: count, offset: from) {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
}
}
You see, its a series if statement for each possible scenario. Imagine if one would to use also order and cache in the parameter- there will be basically 16 unique if statements!
I've tried this [more] shorter code:
creditAdviceList = CreditAdvice.findAll {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
if(count != null) {
maxResults(count)
}
if(from != null) {
firstResult(from)
}
}
But it gives me an error:
...No signature of method: grails.gorm.DetachedCriteria.maxResults() is applicable for argument types: (java.lang.Integer)...
I tried to convert offset to int, Integer, String, etc. I also omit the if statement inside the criteria, but the same error message occur.
findAll with a closure passed is using a DetachedCriteria internally, which is not the same as the result you would get from createCriteria mentioned in the docs. If groovy would find "something close" enough, it would tell you in the error message. The easiest way to deal with your max/from demands would be with simply with a map (which is the first argument passed). E.g.:
def qcfg = [:]
if (count) {
qcfg.count = count
}
if (from) {
qcfg.offset = from
}
creditAdviceList = CreditAdvice.findAll(qcfg) { ... }
mix, match, extract, shorten as you see fit
As far as I see, the only difference is the pagination options. If my eyes are not tricking me, yes, you can:
Map paginationArgs = [max: count, offset: from].findAll {
it.value != null
}
List<CreditAdvice> creditAdviceList = CreditAdvice.findAll(paginationArgs) {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
}
You can style it differently, but basically you can build the pagination arguments first, and pass them to the findAll. No duplicated code, clearer responsability of the conditions. To clarify, I'm adding all the options and then filtering them to exclude the ones that are null.

If statement not calling all methods returning BOOL

I have code like this:
-(IBAction)send {
if ([self isCorrect1] && [self isCorrect2] && ...) {
[self sendRequest];
}
}
-(BOOL)isCorrect1 {
...
}
-(BOOL)isCorrect2 {
...
}
Every isCorrect method is checking some condition showing some message in the view and returning result of the checking. I noticed that if first condition is false it will only show error message for the first method (and I need all of them to be checked) and no breakpoint is triggered inside these methods. I thought it was some kind of LLVM optimization so I created code like this:
-(IBAction)send {
BOOL correct = [self isCorrect1];
correct = correct && [self isCorrect2];
...
if (correct) {
[self sendRequest];
}
}
And is still not working correctly. Do I have to create new BOOL variable to store result for the check or is there some other way?
Since the first condition is evaluated to false, it won't check for the rest of the conditions and will go to the else part straightaway.
Try this.
BOOL finalResult = [self isCorrect1];
finalResult = [self isCorrect2] && finalResult;
finalResult = [self isCorrect3] && finalResult;
finalResult = [self isCorrect4] && finalResult;
...
if (finalResult) {
}
This will go through all of the isCorrect tests and will let you know if it passed all of them in the end or not.
The behaviour you see is the expected behaviour of the &&, namely, it "short-circuits" the evaluation, if it can determine the result in advance, before having evaluated all conditions:
expression-yielding-false && something-else
The result of the above is completely determined by the first part; regardless of what the second operand yields, the final result is false. This allows you to write something like:
if (obj != null && obj->count == 3)
{
...
}
If the && did not have the short-circuit behaviour, you'd have to write
if (obj != null)
{
if (obj->count == 3)
{
...
}
}
The || has a similar behaviour. In case of
something-yielding-true || anything
the right-hand side cannot affect the result value, as the left-hand side already returned true.
One possible work-around would be:
int succeeses = 0;
succeesses += [self isCorrect1]? 1 : 0;
succeesses += [self isCorrect2]? 1 : 0;
succeesses += [self isCorrect3]? 1 : 0;
if (successes == 3)
{
// All tests did succeed
}
else
{
// At least one failed.
}
If you need to know, which tests passed, and which failed, you can try:
BOOL passed1 = [self isCorrect1];
BOOL passed2 = [self isCorrect2];
BOOL passed3 = [self isCorrect3];
if (passed1 && passed2 && passed3)
{
// All tests did succeed
}
else
{
// At least one failed.
}
A more dense version of the above would be
int passed = 0;
passed |= [self isCorrect1]? (1 << 0) : 0;
passed |= [self isCorrect2]? (1 << 1) : 0;
passed |= [self isCorrect3]? (1 << 2) : 0;
if (passed == 7)
{
// All tests did succeed
}
else
{
if (passed & (1 << 0))
{
// First test passed
}
else
{
// First test failed
}
if (passed & (1 << 1))
{
// Second test passed
}
else
{
// Second test failed
}
if (passed & (1 << 2))
{
// Third test passed
}
else
{
// Third test failed
}
}
which is simply a more occult formulation of the version with a boolean variable per test tried.

zf2 How to var_dump the result of select

I am trying to var_dump the result (only database rows) of select query.
I have a simple TableGateway (facotry service_manager)
public function shwoContactFormMessages)
{
$select = new Select();
$select->from(self::$tableName);
return $this->selectWith($select);
}
MY Controller:
public function fooAction()
{
$test = $this->contactFormTable->shwoContactFormMessages();
var_dump($test);
// This will show the results the column and it is working
while ($item = $test->current())
{
echo $item->messageFrom . "<br>";
}
return $view;
}
Result of var_dump($test):
object(Zend\Db\ResultSet\ResultSet)#327 (8) {
["allowedReturnTypes":protected]=>
array(2) {
[0]=>
string(11) "arrayobject"
[1]=>
string(5) "array"
}
["arrayObjectPrototype":protected]=>
object(ArrayObject)#302 (1) {
["storage":"ArrayObject":private]=>
array(0) {
}
}
["returnType":protected]=>
string(11) "arrayobject"
["buffer":protected]=>
NULL
["count":protected]=>
int(5)
["dataSource":protected]=>
object(Zend\Db\Adapter\Driver\Pdo\Result)#326 (8) {
["statementMode":protected]=>
string(7) "forward"
["resource":protected]=>
object(PDOStatement)#307 (1) {
["queryString"]=>
string(49) "SELECT `hw_contact_form`.* FROM `hw_contact_form`"
}
["options":protected]=>
NULL
["currentComplete":protected]=>
bool(false)
["currentData":protected]=>
NULL
["position":protected]=>
int(-1)
["generatedValue":protected]=>
string(1) "0"
["rowCount":protected]=>
int(5)
}
["fieldCount":protected]=>
int(8)
["position":protected]=>
int(0)
}
I would like to var_dump the database rows only instead of the above object.
This is because the ResultSet is designed to give you each item "On Demand" rather than loading them all at once, which can cause you to use huge amounts of memory if the resultset is large.
You can get the full resultset as an array of items if you need:
var_dump($test->toArray()):

Issue with DevExpress XtraTabControl

I am having a DevExpress XtraTabControl with 3 XtraTabPages.
I am trying to remove a Tabpage based on a condition and after removing for the last iteration,it is getting error.
My Code is
foreach (DevExpress.XtraTab.XtraTabPage ptp in tabContactsDetails.TabPages)
{
if (tabContactsDetails.TabPages.Contains(ptp))
{
if (ptp.Name == "tabPTP")
{
if (maxid == String.Empty || maxid == null || maxid == "lblHiddenDebtorID")
{
tabContactsDetails.TabPages.Remove(ptp);
}
else
{
}
}
}
}
and I am getting an error like
Collection was modified; enumeration operation may not execute.
You cannot change a collection while iterating through it!
What I do is the following:
List<XtraTabPage> tabPagesToBeRemoved = new List<XtraTabPage>();
foreach (XtraTabPage ptp in tabContactsDetails.TabPages)
{
if (shouldBeRemoved())
{
tabPagesToBeRemoved.Add(ptp);
}
}
foreach (XtraTabPage pageToBeRemoved in tabPagesToBeRemoved)
{
tabContactsDetails.TabPages.Remove(pageToBeRemoved);
}

Resources