I'm wondering what is the best way to confirm a delete operation is successful via the Java client? Just because we get a successful status after the API call does not mean the resources, in my case a pod, has been finally deleted.
Currently my approach to do a delete api call, then to do a list pods with watch waiting for a delete event. This feels a bit brittle to me.
I have a couple questions:
Do watches on delete calls work? I tried to add one but all my items were null. Which is why I do a list call afterwards.
Is there a more streamlined way to check for the complete deletion of a pod?
Below is a rough example of what I've been trying.
clientConfig.deleteCollectionNamespacedPod(entity.getNamespace(), null, null, null,
String.format(NAME_FIELD_SELECTOR, entity.getName()), null, null, null, null, null);
Call call = clientConfig.listNamespacedPodCall(entity.getNamespace(), null, null, null,
String.format(NAME_FIELD_SELECTOR, entity.getName()), null, null, null, null, Boolean.TRUE,
null, null);
Watch<V1Pod> watch = Watch.createWatch(BaseClient.newBaseClient(clientConfig), call, new TypeToken<Watch.Response<V1Pod>>() {
}.getType());
for (Watch.Response<V1Pod> item : watch) {
if (item.type == "DELETED") {
// return that the deletion of the object was successful
}
}
Related
I am using DatabaseClient for building a custom Repository. After I insert or update an Item I need that Row data to return the saved/updated Item. I just can´t wrap my head around why .all(), .first(), .one() are not returning the Result Map, although I can see that the data is inserted/updated in the database. They just signal onComplete. But .rowsUpdated() returns 1 row updated.
I observed this behaviour with H2 and MS SQL Server.
I´m new to R2dbc. What am I missing? Any ideas?
#Transactional
public Mono<Item> insertItem(Item entity){
return dbClient
.sql("insert into items (creationdate, name, price, traceid, referenceid) VALUES (:creationDate, :name, :price, :traceId, :referenceId)")
.bind("creationDate", entity.getCreationDate())
.bind("name", entity.getName())
.bind("price", entity.getPrice())
.bind("traceId", entity.getTraceId())
.bind("referenceId", entity.getReferenceId())
.fetch()
.first() //.all() //.one()
.map(Item::new)
.doOnNext(item -> LOGGER.info(String.format("Item: %s", item)));
}
The table looks like this:
CREATE TABLE [dbo].[items](
[creationdate] [bigint] NOT NULL,
[name] [nvarchar](32) NOT NULL,
[price] [int] NOT NULL,
[traceid] [nvarchar](64) NOT NULL,
[referenceid] [int] NOT NULL,
PRIMARY KEY (name, referenceid)
)
Thanks!
This is the behavior of an insert/update statement in database, it does not return the inserted/updated rows.
It returns the number of inserted/updated rows.
It may also return some generated values by the database (such as auto increment, generated uuid...), by adding the following line:
.filter(statement -> statement.returnGeneratedValues())
where you may specify specific generated columns in parameter. However this has limitations depending on the database (for example MySql can only return the last generated ID of an auto increment column even if you insert multiple rows).
If you want to get the inserted/updated values from database, you need to do a select.
Inside the drools rule file, I'm trying to match the request object against inserted facts using a query (backward chaining). How do I check for null for the request object attribute? If the attribute is not null, I want to pass it to the query. If the attribute is null, I want to keep it unbound so that it will match all results. Since there are many request attributes, I'm looking for a generic solution instead of different rules for each attribute.
To give an example, lets assume I have two attributes currency and country in the goal: Goal() object and I want to call the query isMatching(String country,String currency)
if goal.getCountry() and goal.getCurrency() is not null, I want to call isMatching with goal.getCountry()and goal.getCurrency().
isMatching(goal.getCountry(),goal.getCurrency())
if goal.getCountry() is null and goal.getCurrency() is not null, I want to call isMatching with unbound variable country and goal.getCurrency()
isMatching(country,goal.getCurrency())
if goal.getCountry() is not null and goal.getCurrency() is null, I want to call isMatching with goal.getCountry() and unbound variable currency
isMatching(goal.getCountry(),currency)
if both goal.getCountry() and goal.getCurrency() are null, I want to call isMatching with unbound variable country and currency
isMatching(country,currency)
Best practice is to have a separate rule for each combination.
rule "both country and currency"
when
Goal( $country: country != null, $currency: currency != null )
$isMatching: Boolean() from isMatching( $country, $currency )
then
//
end
Not sure what you're referring to as an "unbound" variable in your question for your other use cases.
If you insist on not following best practices and try to kludge all of this into a single rule, you could either do your null check on the right hand side, or possibly abuse conditional and named consequences to do this. Doing it in the rule consequences ("then") will cause you to lose all of the performance optimization done by the Drools engine, which is done on the left hand side only.
Alternatively you could just update the query to handle the null case.
query isMatching( String $country, String $currency) {
$country := String( this == null )
or
$currency := String( this == null )
or
( actual implementation )
}
rule "example"
when
Goal( $country: country, $currency: currency )
isMatching( $country, $currency )
then
// ...
end
Actual implementation may vary; I have no idea how you'd implement a currency <-> country check.
Thank you in advance for your help.
This issue has been driving me crazy for the past couple of days. I have searched every site that Google has returned and still the resolutions haven't helped.
I am attempting to create a Sq3Lite database using Dart and keeping getting a DatabaseException error when trying to create a table that uses foreign keys. I've tried turning foreign key use on with 'PRAGMA foreign_keys = ON' as well but no luck. I am also using an IOS simulator in Android Studio and delete the app before running the code with attempted fixes.
Here is my code:
final int version = 1;
Database db;
Future<Database> openDb() async {
if (db == null) {
db = await openDatabase(join(await getDatabasesPath(), 'skeema.db'), onCreate: (database, version) {
database.execute('CREATE TABLE Account(id INTEGER PRIMARY KEY, Name TEXT NOT NULL, CurrencyType TEXT NOT NULL, ' + 'Balance REAL NOT NULL, IsPrimary TEXT NULL)');
database.execute('CREATE TABLE BudgetItem(id INTEGER PRIMARY KEY, Name TEXT NOT NULL, Icon TEXT NOT NULL, Budget REAL NOT NULL, ' + 'IsPrimary TEXT NULL)');
database.execute('CREATE TABLE TransactionType(id INTEGER PRIMARY KEY, Type TEXT NOT NULL)');
database.execute('CREATE TABLE Transaction(id INTEGER PRIMARY KEY, Account_id INTEGER NOT NULL, BudgetItem_id INTEGER NOT NULL, ' +
'TransactionType_id INTEGER NOT NULL, Amount REAL NOT NULL, Date TEXT NOT NULL, Party TEXT NOT NULL, Note TEXT NULL, ' +
'FOREIGN KEY(Account_id) REFERENCES Account(id), ' +
'FOREIGN KEY(BudgetItem_id) REFERENCES BudgetItem(id), ' +
'FOREIGN KEY(TransactionType_id) REFERENCES TransactionType(id))');
}, version: version);
}
return db;
}
Here is the error:
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: DatabaseException(Error Domain=FMDatabase Code=1 "near "Transaction": syntax error" UserInfo={NSLocalizedDescription=near "Transaction": syntax error}) sql 'CREATE TABLE Transaction(id INTEGER PRIMARY KEY, Account_id INTEGER NOT NULL, BudgetItem_id INTEGER NOT NULL, TransactionType_id INTEGER NOT NULL, Amount REAL NOT NULL, Date TEXT NOT NULL, Party TEXT NOT NULL, Note TEXT NULL, FOREIGN KEY(Account_id) REFERENCES Account(id), FOREIGN KEY(BudgetItem_id) REFERENCES BudgetItem(id), FOREIGN KEY(TransactionType_id) REFERENCES TransactionType(id))' args []}
#0 wrapDatabaseException (package:sqflite/src/exception_impl.dart:11:7)
<asynchronous suspension>
#1 SqfliteDatabaseFactoryImpl.wrapDatabaseException (package:sqflite/src/factory_impl.dart:27:7)
#2 SqfliteDatabaseMixin.safeInvokeMethod (package:sqflite_common/src/database_mixin.dart:208:15)
#3 SqfliteDatabaseMixin.invokeExecute (package:sqflite_common/src/database_mixin.dart:370<…>
The first 3 tables get created successfully every time but the last table throws the error. Any help is greatly appreciated.
Thank you.
Transaction is a Sq3Lite keyword, so you can't name your table that. So give it any other name and it will work.
There may be ways to use that name anyway if you escape it, but the easy solution is just to choose a different name.
List of all keywords: https://www.sqlite.org/lang_keywords.html
I need to dispatch and Create a new DragEvent
var dispatchedDragEvent = DOM.createEvent('DragEvent');
dispatchedDragEvent.initDragEvent('dragstart', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
DOM.dispatchEvent(this.htmlElement, dispatchedDragEvent);
but I get the error initDragEvent is not a function, because DOM.createEvent('DragEvent') returns a object of Event and not 'DragEvent'
Can someone help me to create manually a DragEvent and dispatch it?
I need to convert a TouchStart to a DragStart.
Here's what I have done:
#HostListener('touchstart', ['$event'])
onTouchStart(event) {
let event1 = new DragEvent('dragstart');
this._renderer.invokeElementMethod(this._elementRef.nativeElement, 'dispatchEvent', [event1]);
}
This might give a warning on compile, but works nonetheless.
I am trying to post something on a facebook users feed and then afterwards redirect the user to another page, but it seems like the page just keeps reloading without any promt for sending user feed.
FB.Connect.showFeedDialog(1111111, null, null, null, null, null, redirectTo(), null, null);
function redirectTo()
{
window.top.location = "/mywebsite";
}
If I just call the show feed with the id it works properly.
FB.Connect.showFeedDialog(1111111, null, null, null, null, null, redirectTo(), null, null);
Anyone who knows why the first lines of code keeps reloading the page in an infinitive loop?
When registering the callback function, you want to pass the reference to the function and not actually call the function. Remove the parentheses from redirectTo in your first line:
FB.Connect.showFeedDialog(1111111, null, null, null, null, null, redirectTo, null, null);
function redirectTo(){
window.top.location = "/mywebsite";
}