is c3p0 connection pool thread safe or not..? - c3p0

hai this chandrashekhar,
when I post the multiple requests(100) at a time it creates c3p0 Instances.
Ex::
[AbstractPoolBackedDataSource] Initializing c3p0 pool...
com.mchange.v2.c3p0.PoolBackedDataSource#3b9421d5 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource#8f5cd4d1 [ acquireIncrement -> 5, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> true, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> true, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge2v08pob8zy1nl2rit|1474b36, idleConnectionTestPeriod -> 3600, initialPoolSize -> 10, maxAdministrativeTaskTime -> 600, maxConnectionAge -> 0, maxIdleTime -> 18000, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 50, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource#3a7ecbf6 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1hge2v08pob8zy1nl2rit|87f988, jdbcUrl -> jdbc:mysql://localhost:3306/tiscover, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 600, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1hge2v08pob8zy1nl2rit|6c2668, numHelperThreads -> 10 ]
13:24:16,003 INFO [AbstractPoolBackedDataSource]
Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource#38d1c65b [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource#efa9b134 [ acquireIncrement -> 5, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> true, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> true, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge2v08pob8zy1nl2rit|d46725, idleConnectionTestPeriod -> 3600, initialPoolSize -> 10, maxAdministrativeTaskTime -> 600, maxConnectionAge -> 0, maxIdleTime -> 18000, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 50, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource#f3230993 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1hge2v08pob8zy1nl2rit|b31fb1, jdbcUrl -> jdbc:mysql://localhost:3306/tiscover, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 600, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1hge2v08pob8zy1nl2rit|9861d7, numHelperThreads -> 10 ]
13:24:16,004 INFO [AbstractPoolBackedDataSource]
Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource#3b6dc297 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource#433920d4 [ acquireIncrement -> 5, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> true, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> true, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge2v08pob8zy1nl2rit|3561b9, idleConnectionTestPeriod -> 3600, initialPoolSize -> 10, maxAdministrativeTaskTime -> 600, maxConnectionAge -> 0, maxIdleTime -> 18000, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 50, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource#4084843c [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1hge2v08pob8zy1nl2rit|3f9de3, jdbcUrl -> jdbc:mysql://localhost:3306/tiscover, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 600, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1hge2v08pob8zy1nl2rit|6dfb07, numHelperThreads -> 10 ]
13:24:16,004 INFO [AbstractPoolBackedDataSource]
Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource#3bcf7210 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource#896b85d4 [ acquireIncrement -> 5, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> true, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> true, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge2v08pob8zy1nl2rit|16e47cb, idleConnectionTestPeriod -> 3600, initialPoolSize -> 10, maxAdministrativeTaskTime -> 600, maxConnectionAge -> 0, maxIdleTime -> 18000, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 50, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource#f06dd726 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1hge2v08pob8zy1nl2rit|bd7db5, jdbcUrl -> jdbc:mysql://localhost:3306/tiscover, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 600, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1hge2v08pob8zy1nl2rit|1e616dc, numHelperThreads -> 10 ]
13:24:16,006 INFO [AbstractPoolBackedDataSource]
....etc 100 times.
what is the meaning behind this, is 100 connection pool Instances created..?
is c3p0 connection pool is not thread safe..? if so how we are geoing to handle..?
pls any one help me.
thanks in advance,
ChandraShekhar

Firstly, a connection can only run on interaction with the database at a time. If you share a connection across multiple threads, the behaviour would be random. Ideally, you would just get a connection from the pool when you want to interact with DB like run some INSERT/UPDATE/DELETE statements and get the update counts or run SELECT statements and read the result sets and then you close all the resources (viz. ResultSets, Statements and Connection).
If the connection comes from a connection pooler, then the close() call on such a connection is handled by the pooler to return the connection back to pool.
The statements you printed are INFOs from the pooler about the connection pool created.

Related

How to solve Cannot cast object '0.0' with class 'java.lang.Double' to class 'org.json.JSONObject'

This is some part of my input json :-
"orderLine": {
"agreementHeaderId": [
null
],
"agreementNumber": [
null
],
"customerProductId": null,
"displayLineNumber": "2",
"estimateFulfillmentCost": 9.97,
"extendedAmount": null,
"fulfilledQuantity": null,
"fulfillToleranceAbove": null,
"inventoryOrganizationCode": "107",
"inventoryOrganizationId": "107",
"jobName": null,
"orderedQuantity": 1.0,
"orderedUom": null,
"origSystemDocumentLineReference": "2",
"paymentTerms": "CASH ON DEMAND",
"paymentTermsCode": "COD",
"productId": "4065412*107",
"productNumber": "4065412",
"productDescription": "20 DFU AAV W/ 1-1/2-2 PVC ADPT",
"purchasingUom": null,
"quantityPerModel": 0.0,
"requestedShipDate": "2022-12-19T05:00:00.000Z",
"requestedSupplierNumber": null,
"requisitionInventoryOrganizationId": "107",
"rmaDeliveredQuantity": null,
"scheduleShipDate": null,
"shippedQuantity": 1.0,
"shippingCarrier": "OT",
"shippingInstructions": null,
"shippingMode": "OUR TRUCK",
"shippingModeCode": "OT",
"subInventory": null,
"transactionLineTypeCode": null,
"transactionCategoryCode": null,
"transactionLineType": "MP",
"unitListPrice": 33.23,
"unitQuantity": 1.0,
"unitSellingPrice": 44.0,
Few values are double type not string
So, while giving this JSONObject oldQty = (JSONObject) orderLine.get("orderedQuantity")
I'm getting Cannot cast object '0.0' with class 'java.lang.Double' to class 'org.json.JSONObject' this error

Two different nodes giving same call to same MYSQL Database giving different responses

I have my first NodeJS API running. I have two API's now running (TEST and PROD).
These files are DIRECT copies of each other and running via App Manager in Cpanel.
Weirdly, one of the calls (Prod) is giving incorrect information on some of the calls... like it is giving 'old' data.
eg. a record was changed for an 'order' and a locationID was added to the database.
I have checked the database and it was added.
The test call:
https://www.myAPI.com.au/TEST/orders/myOrders/1709
Response:
{
"Result": true,
"order": {
"orderID": 1709,
"chemOrderID": 1243,
"firstName": "test",
"lastName": "test",
"phone": "04123456",
"email": null,
"prefContact": 1,
"itemName": "KN95 Box Of 30 ",
"itemQuantity": 1,
"plu": null,
"modelNumber": null,
"colour": null,
"itemDetails": null,
"supplier": "avacare",
"itemSize": null,
"amountPaid": 0,
"receiptNumber": "00",
"quotedPrice": 69.99,
"orderComments": null,
"reorder": 0,
"isNDIS": 0,
"isNDISPaid": 0,
"onHold": 0,
"requestedBy": 35,
"orderedBy": 35,
"receivedBy": 35,
"finalisedBy": 0,
"overdueBy": 0,
"NDISBy": 0,
"deletedBy": 0,
"requestedByName": "Jac",
"orderedByName": "Jac",
"receivedByName": "Jac",
"finalisedByName": null,
"overdueByName": null,
"deletedByName": null,
"requestedDateShort": "18 Jan",
"orderedDateShort": "18 Jan",
"receivedDateShort": "18 Jan",
"finalisedDateShort": null,
"overdueDateShort": null,
"deletedDateShort": null,
"requestedDate": "2022-01-18T09:40:21",
"orderedDate": "2022-01-18T09:50:33",
"receivedDate": "2022-01-18T12:21:41",
"finalisedDate": null,
"overdueDate": null,
"deletedDate": null,
"etaMaxDateShort": "Thu, 20 Jan",
"etaCode": 2,
"locationID": 199,
"supplierRef": null,
"locationOther": null,
"categoryID": 5,
"categoryName": "GENERAL SHOP"
}
}
Now this is correct. The locationID is updated, the receivedDate, recivedByName and receivedBy are all correct and updated.
The same call on copied API: (same mysql user login. literally a duplicate of the api)
Call:
https://www.myAPI.com.au/prod/orders/myOrders/1709
Response:
{
"Result": true,
"order": {
"orderID": 1709,
"chemOrderID": 1243,
"firstName": "test",
"lastName": "test",
"phone": "04123456",
"email": null,
"prefContact": 1,
"itemName": "KN95 Box Of 30 ",
"itemQuantity": 1,
"plu": null,
"modelNumber": null,
"colour": null,
"itemDetails": null,
"supplier": "avacare",
"itemSize": null,
"amountPaid": 0,
"receiptNumber": "00",
"quotedPrice": 69.99,
"orderComments": null,
"reorder": 0,
"isNDIS": 0,
"isNDISPaid": 0,
"onHold": 0,
"requestedBy": 35,
"orderedBy": 35,
"receivedBy": 0,
"finalisedBy": 0,
"overdueBy": 0,
"NDISBy": 0,
"deletedBy": 0,
"requestedByName": "Jac",
"orderedByName": "Jac",
"receivedByName": null,
"finalisedByName": null,
"overdueByName": null,
"deletedByName": null,
"requestedDateShort": "18 Jan",
"orderedDateShort": "18 Jan",
"receivedDateShort": null,
"finalisedDateShort": null,
"overdueDateShort": null,
"deletedDateShort": null,
"requestedDate": "2022-01-18T09:40:21",
"orderedDate": "2022-01-18T09:50:33",
"receivedDate": null,
"finalisedDate": null,
"overdueDate": null,
"deletedDate": null,
"etaMaxDateShort": "Thu, 20 Jan",
"etaCode": 2,
"locationID": null,
"supplierRef": null,
"locationOther": null,
"categoryID": 5,
"categoryName": "GENERAL SHOP"
}
}
As can be seen, the aforementioned fields aren't filled!?
It's like the call is getting an old version of the database or something...
I can't understand this at all.
There is only one DB, i haven't created a test db, in reality this whole thing is testing (even the prod version), as I am learning and trying to understand how I will go about everything once it is actually live.

How to compare rows from JSON file in angular?

I have this items in a JSON file that I need to compare wherever I have Curr or Prev values and compare if they are equals. this algorithm is with angular 5 but I'm being unable to do this, I did the load function with httpClient
Example :
[{
"id": 1,
"comparisonDate": "2017-06-22",
"milestone": "CURR_PREV",
"udDomain": "BASIS",
"udIdentifier": "332A251000.01",
"rpt": "D70",
"approvedCurr": true,
"approvedPrev": null,
"commercialReferenceCurr": "BASIS - 01.01.2007",
"commercialReferencePrev": null,
"customizationImpactCurr": null,
"customizationImpactPrev": null,
"deliveryTypeCurr": null,
"deliveryTypePrev": null,
"aircraftId": 184,
"aircraftSapId": "580652",
"aircraftName": "BUL 011",
"aircraftSerialNumber": "02713",
"quantityCurr": "1",
"quantityPrev": null,
"statusCurr": "O",
"statusPrev": null,
"typeModification": "CREATION",
"validityCurr": "V",
"validityPrev": null
}, {
"id": 2,
"comparisonDate": "2017-06-22",
"milestone": "CURR_PREV",
"udDomain": "BASIS",
"udIdentifier": "332A270028.01",
"rpt": "E15",
"approvedCurr": true,
"approvedPrev": null,
"commercialReferenceCurr": "BASIS - 01.01.2007",
"commercialReferencePrev": null,
"customizationImpactCurr": null,
"customizationImpactPrev": null,
"deliveryTypeCurr": null,
"deliveryTypePrev": null,
"aircraftId": 184,
"aircraftSapId": "580652",
"aircraftName": "BUL 011",
"aircraftSerialNumber": "02713",
"quantityCurr": "1",
"quantityPrev": null,
"statusCurr": "O",
"statusPrev": null,
"typeModification": "CREATION",
"validityCurr": "V",
"validityPrev": null
}]
this should be with using lodash.
i assume your want something like this
for each object in your array
filter keys that end with "Curr"
for each get Prev property
compare it with curr property
let obj = [{
"id": 1,
"comparisonDate": "2017-06-22",
"milestone": "CURR_PREV",
"udDomain": "BASIS",
"udIdentifier": "332A251000.01",
"rpt": "D70",
"approvedCurr": true,
"approvedPrev": null,
"commercialReferenceCurr": "BASIS - 01.01.2007",
"commercialReferencePrev": null,
"customizationImpactCurr": null,
"customizationImpactPrev": null,
"deliveryTypeCurr": null,
"deliveryTypePrev": null,
"aircraftId": 184,
"aircraftSapId": "580652",
"aircraftName": "BUL 011",
"aircraftSerialNumber": "02713",
"quantityCurr": "1",
"quantityPrev": null,
"statusCurr": "O",
"statusPrev": null,
"typeModification": "CREATION",
"validityCurr": "V",
"validityPrev": null
}, {
"id": 2,
"comparisonDate": "2017-06-22",
"milestone": "CURR_PREV",
"udDomain": "BASIS",
"udIdentifier": "332A270028.01",
"rpt": "E15",
"approvedCurr": true,
"approvedPrev": null,
"commercialReferenceCurr": "BASIS - 01.01.2007",
"commercialReferencePrev": null,
"customizationImpactCurr": null,
"customizationImpactPrev": null,
"deliveryTypeCurr": null,
"deliveryTypePrev": null,
"aircraftId": 184,
"aircraftSapId": "580652",
"aircraftName": "BUL 011",
"aircraftSerialNumber": "02713",
"quantityCurr": "1",
"quantityPrev": null,
"statusCurr": "O",
"statusPrev": null,
"typeModification": "CREATION",
"validityCurr": "V",
"validityPrev": null
}];
obj.forEach(x=>{
Object.keys(x)
.filter(y=>y.endsWith("Curr"))
.forEach(y=>{
let prevProp = y.replace("Curr", "Prev")
console.log(y, x[y]);
console.log(prevProp ,x[prevProp ]);
if(x[y]===x[prevProp ]){
//equal
}else{
//not equal
}
})
})
you could use lodash's _.forEach, _.Keys, _.filter but i think there is not much point on this.

What is wrong with my JSON?

{
“id”: 0,
“isfname”: null,
“islname”: null,
“csfname”: null,
“cslname”: null,
“snf”: null,
“dateadmit”: null,
“csaddress”: null,
“cscsz”: null,
“cstelephone”: null,
“csemail”: null,
“datemaneed”: null,
“csownrent”: null,
“csage”: 0,
“isage”: 0,
“isincome”: [
{
“type”: null,
“gross”: 0,
“deducts”: 0,
“net”: 0
}
],
“csincome”: [
{
“type”: null,
“gross”: 0,
“deducts”: 0,
“net”: 0
}
],
“banks”: [
{
“type”: null,
“desc”: null,
“owner”: null,
“amt”: 0
}
],
“inv”: [
{
“type”: null,
“desc”: null,
“owner”: null,
“amt”: 0
}
],
“csira”: 0,
“isira”: 0,
“csli”: [
{
“type”: null,
“desc”: null,
“cv”: 0,
“fv”: 0
}
],
“isli”: [
{
“type”: null,
“desc”: null,
“cv”: 0,
“fv”: 0
}
],
“veh”: [
{
“type”: null,
“makemodel”: null,
“amt”: 0
}
],
“realty”: [
{
“desc”: null,
“home”: true,
“amt”: 0
}
],
“totals”: [
{
“banks”: 0,
“inv”: 0,
“csli”: 0,
“isli”: 0,
“veh”: 0,
“realty”: 0,
“exemptli”: 0,
“exemptira”: 0,
“exempthome”: 0,
“totalgross”: 0,
“totalexempt”: 0,
“totalcountable”: 0,
“csra”: 0,
“isretained”: 0,
“totalretained”: 0,
“totalspenddown”: 0
}
],
“shelters”: {
“rent”: 0,
“mortgage”: 0,
“retaxes”: 0,
“hoins”: 0,
“sua”: 0,
“shelterstd”: 0
},
“ismedins”: 0,
“isincavail”: 0,
“isinctosnf”: 0,
“isinctocs”: 0,
“spenddown”: {
“snfbill”: 0,
“legal”: 0,
“mortgage”: 0,
“ppf”: 0,
“newvehicle”: 0,
“repairs”: 0
},
“otherspenddown”: [
{
“annuity”: 0,
“other”: null
}
],
“manos”: {
“minmmna”: 0,
“maxmmna”: 0,
“mincsra”: 0,
“maxcsra”: 0,
“pna”: 0,
“incomelimit”: 0
}
}
The quotes are all wrong:
“islname”
Should be
"islname"
Did you copy it from MS Word document or something? Don't do that.
according to JSON parser: Unrecognized token '?'
http://json.parser.online.fr
Bad quotes.

convert binary 16 id to 36 character uuid in juggler models

Here is my question in brief:
I am using StrongLoop to work with an existing MySQL database. The database uses binary 16 datatypes to store primary keys and foreign keys. When I create the models using Strongloop tools, the data is sent to the client as string arrays in the JSON. I would like the JSON to contain the converted 36 character string. In the database, I have bintouuid and uuidtobin functions that will convert the data to/from the 36 character format. Can anyone provide the code I would use in the model or REST services to extend it to convert the arrays (or binary data) into the needed string format?
Here are details around the scenario:
The table script looks like this:
CREATE TABLE `alert` (
`ID` binary(16) NOT NULL,
`Subject` varchar(255),
`Text` text NOT NULL,
`Read` int(11) DEFAULT '0',
`AddedDate` timestamp NULL DEFAULT NULL,
`LastUpdated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`IsDeleted` bit(1) NOT NULL DEFAULT b'0',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
I have functions for creating and converting uuids to/from binary format:
newUuidToBin()
CREATE DEFINER=`root`#`localhost` FUNCTION `newuuidtobin`() RETURNS binary(16)
BEGIN
DECLARE UUID char(37);
SET UUID = UUID();
RETURN uuidtobin(UUID);
END
uuidToBin(UUID char(36))
CREATE DEFINER=`root`#`localhost` FUNCTION `uuidtobin`(UUID char(36)) RETURNS binary(16)
BEGIN
RETURN CONCAT(UNHEX(LEFT(UUID,8)),UNHEX(MID(UUID,10,4)),UNHEX(MID(UUID,15,4)),UNHEX(MID(UUID,20,4)),UNHEX(RIGHT(UUID,12)));
END
binToUuid(UUID BINARY(16))
CREATE DEFINER=`root`#`localhost` FUNCTION `bintouuid`(UUID BINARY(16)) RETURNS char(36) CHARSET utf8
BEGIN
RETURN concat(HEX(LEFT(uuid,4)),'-', HEX(MID(uuid,5,2)),'-', HEX(MID(uuid,7,2)),'-',HEX(MID(uuid,9,2)),'-',HEX(RIGHT(uuid,6)));
END
I have a trigger that creates the binary uuid when a record is created:
CREATE TRIGGER before_insert_alert
BEFORE INSERT
ON road.alert
FOR EACH ROW
SET new.id = newuuidtobin();
My default Alert.json for the model looks like this:
{
"name": "Alert",
"base": "PersistedModel",
"idInjection": false,
"mysql": {
"schema": "messaging",
"table": "alert"
},
"properties": {
"id": {
"type": "Binary",
"id": true,
"required": true,
"length": 16,
"precision": null,
"scale": null,
"mysql": {
"columnName": "ID",
"dataType": "binary",
"dataLength": 16,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"subject": {
"type": "String",
"required": false,
"length": 65535,
"precision": null,
"scale": null,
"mysql": {
"columnName": "Subject",
"dataType": "text",
"dataLength": 65535,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"text": {
"type": "String",
"required": true,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "Text",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"read": {
"type": "Number",
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "Read",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "Y"
},
"_selectable": true
},
"addeddate": {
"type": "Date",
"required": false,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "AddedDate",
"dataType": "timestamp",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"lastupdated": {
"type": "Date",
"required": true,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "LastUpdated",
"dataType": "timestamp",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"isdeleted": {
"type": "Binary",
"required": true,
"length": null,
"precision": 1,
"scale": null,
"mysql": {
"columnName": "IsDeleted",
"dataType": "bit",
"dataLength": null,
"dataPrecision": 1,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
When accessing the REST endpoint with a get,
http://localhost:3000/api/Alerts
...I get this result. Note: the id comes back in the form of an array.
[
{
"id": [
97,
55,
50,
102,
52,
49,
50,
48,
45,
57,
53,
54,
97,
45,
49,
49
],
"subject": "uuids",
"text": "my message",
"read": 0,
"addeddate": null,
"lastupdated": "2015-01-05T23:10:03.000Z",
"isdeleted": [
0
]
},
.
.
.
]
...but I want the result to look like this:
[
{
"id": "C39BC3A2-381F-5568-11C3-A0C2B66E64EF"
"subject": "uuids",
"text": "my message",
"read": 0,
"addeddate": null,
"lastupdated": "2015-01-05T23:10:03.000Z",
"isdeleted": [
0
]
},
.
.
.
]
On update, the REST endpoint should convert the string using the mysql function:
update alert set `read` = 1 where id = uuidtobin('C39BC3A2-381F-5568-11C3-A0C2B66E64EF');
How would I extend the model to use the mysql functions to select data showing the ids as uuid strings in the json result, and update records using the uuid 36 character string?
You can use a remote hook to manipulate the response before sending it back. See http://docs.strongloop.com/display/LB/Remote+hooks
Another possible solution is using model hooks to modify the data before/after saving it. See http://docs.strongloop.com/display/LB/Model+hooks