How would I make self.character.data().bank the same to all instances of the class
even when using the function setBank? currently when using setBank it only updates self.character.data().bank on the one instance if it makes sense
_G.GetUser = {
users = {},
users_group = {},
userData = {},
CurrentCharacter = {}
}
_G.GetUserMethods = {}
GetUserMethods.__call = function(self, source)
local o = setmetatable({}, {
__index = self
})
o.src = source
o.id = self.users[o.src]
o.rank = self.users_group[o.src]
return o
end
GetUserMethods.__index = {
getCurrentCharacter = function(self)
self.character = {}
self.character.id = self.CurrentCharacter[self.id]
self.character.data = function()
return self.userData[self.character.id]
end
self.character.setBank = function(v)
if self.character.data() then
self.character.data().bank = v
end
end
self.character.getBank = function()
if self.character.data() then
return self.character.data().bank
end
return nil
end
return self.character
end
}
setmetatable(GetUser, GetUserMethods)
Replace
importClass {'getuser'}
with
if not _G.GetUser then
importClass {'getuser'}
end
in each file.
Related
In a JetBrains editor, what is the shortcut (or trick) to duplicate a line on itself without breakline (not like Ctrl + D). In other words, I want to turn this:
constructor(obj: Schema$Car) {
this.brand =
this.id =
this.model =
this.photoBack =
this.photoFront =
this.photoInteriorBack =
this.photoInteriorFront =
this.photoSide =
this.seatCount =
this.year =
}
into this:
constructor(obj: Schema$Car) {
this.brand = obj.brand
this.id = obj.id
this.model = obj.model
this.photoBack = obj.photoBack
this.photoFront = obj.photoFront
this.photoInteriorBack = obj.photoInteriorFront
this.photoInteriorFront = obj.photoInteriorFront
this.photoSide = obj.photoSide
this.seatCount = obj.seatCount
this.year = obj.year
}
I have the following structure of entities:
Route: -one-to-many-> :Stop: <-many-to-many-> :Child: <-many-to-many-> :Contact
And so I've defined the following named entity graphs at the top of each entity class so I can optimize my queries for how far down this heirarchy I'll need to travel:
Route:
#NamedEntityGraphs({
#NamedEntityGraph(name = "Route.stop.child.contact",
attributeNodes = {
#NamedAttributeNode(value = "stops", subgraph = "Stop.child.contact")
}),
#NamedEntityGraph(name = "Route.stop.child",
attributeNodes = {
#NamedAttributeNode(value = "stops", subgraph = "Stop.child")
}),
#NamedEntityGraph(name = "Route.stop",
attributeNodes = {
#NamedAttributeNode(value = "stops", subgraph = "Stop")
})
})
public class Route {...}
Stop:
#NamedEntityGraphs({
#NamedEntityGraph(name = "Stop.child.contact",
attributeNodes = {
#NamedAttributeNode(value = "children", subgraph = "Child.contact")
}),
#NamedEntityGraph(name = "Stop.child",
attributeNodes = {
#NamedAttributeNode(value = "children", subgraph = "Child")
}),
#NamedEntityGraph(name = "Stop", attributeNodes = {})
})
public class Stop {...}
Child:
#NamedEntityGraphs({
#NamedEntityGraph(name = "Child.contact",
attributeNodes = {
#NamedAttributeNode(value = "contacts", subgraph = "Contact")
}),
#NamedEntityGraph(name = "Child", attributeNodes = {})
})
public class Child {...}
Contact:
#NamedEntityGraphs({#NamedEntityGraph(name = "Contact", attributeNodes = {})})
public class Contact {...}
And I use them in my Repository class as such:
#EntityGraph(value = "Route.stop.child.contact", type = EntityGraph.EntityGraphType.LOAD)
Optional<Route> findRouteStopsChildrenContactsByRouteId(short routeId);
However, I can see no join queries being made, and a lazyinit exception is thrown when I try to access children of stops. My understanding was that this is how entity graphs can be used to optimize queries (i.e. n+1 problem when I have to fetch children for each individual stop), but I'm having no luck getting it to work.
Any advice as to what I'm doing wrong?
Try this one it worked for me.
#NamedEntityGraph(name = "Book.details", attributeNodes = #NamedAttributeNode("reviews"))
#Table(name = "Book")
public class Book implements Serializable
{
#OneToMany(cascade = CascadeType.ALL , mappedBy = "book" , fetch = FetchType.EAGER)
//#OrderBy("no ASC")
private List<Review> reviews ;
}
2) Get Record (internally use left outer join).
#EntityGraph(value = "Book.details", type = EntityGraphType.FETCH)
List<Book> getBooksByAuthName(String aname);
I'm trying to get the "id" of the TD Node that a field is in. I created a function, but I am not getting the data out of the loop ... I'm guessing that the variables are out of scope and I can't figure out how to make it work.
function getTD(vStartNm)
{
vNm = document.getElementsByName(vStartNm),
vId = vNm[0].getAttribute('id'),
vNode = document.getElementById(vId),
vTag = vNode.nodeName;
vTDId = '';
for (i = 0; i >10; i++)
{
vPar = vNode.parentNode;
vTag = vPar.nodeName;
vTDId = vPar.id;
vNode = vPar;
if (vTag == 'TD'){return vTDId; break;}
}
}
vTD_id = getTD('udfchar45');
vTD = document.getElementById(vTD_id);
my syntax on the do loop may be wrong. once i changed it to a while loop, it seems to work just fine.
function getTD(vStartNm)
{
vNm = document.getElementsByName(vStartNm),
vId = vNm[0].getAttribute('id'),
vNode = document.getElementById(vId),
vTag = vNode.nodeName;
vTDId = '';
i=0;
while (i < 10)
{
i++;
vPar = vNode.parentNode;
vTag = vPar.nodeName;
vTDId = vPar.id;
vNode = vPar;
if (vTag == 'TD'){return vTDId; break;}
}
}
vTD_id = getTD('udfchar45');
vTD = document.getElementById(vTD_id);
Please check if I print obj then in data array same elements gets inserted twice instead of different. If n =2 then the first element gets pushed twice.
genLLEles(n, orgObj, homeSecObj, defaultElementObj, previousElements, socket) {
let that = this;
let arr = [];
let obj = {
dataArray: [],
socketId: socket.USER_ID,
requestId: "/sync#" + socket.id + socket.USER_ID + "#" + new Date().getTime(),
moduleName: "ORG",
action: "INSERT",
userId: socket.USER_ID
};
console.log("\n\ should be oce");
for (let i = 0; i < n; i++) { //n defines count of how many elements to be created
let temp = defaultElementObj; //selected object to insert
let _id = homeSecObj.KEY_VAL + "_TSK:" + defaultElementObj.SUB_KEY_TYPE + "_" + Date.now() + "_" + Math.floor(Math.random() * (10000 - 1)) + 1;
console.log(obj.dataArray.length);
if (obj.dataArray.length == 0) {
temp.CML_PREVIOUS_ID = previousElements.length <= 0 ? "-1" : that.getPreObj(previousElements).KEY_VAL;
temp.CML_NEXT_ID = "1";
temp.ORG_ID = orgObj.ORG_ID;
temp.DEPT_ID = orgObj.DEPT_ID;
temp.KEY_VAL = _id;
temp.CML_ID = _id;
temp.CML_REF_ID = homeSecObj.KEY_VAL;
temp.ACTIVE_STATUS = "1";
temp.CML_IMAGE_PATH = "";
temp.SYNC_PENDING_STATUS = "1";
} else {
obj.dataArray[obj.dataArray.length - 1].CML_NEXT_ID = _id;
console.log("HERE", obj.dataArray[obj.dataArray.length - 1]);
temp.CML_PREVIOUS_ID = obj.dataArray.length < 0 ? "-1" : obj.dataArray[obj.dataArray.length - 1].KEY_VAL;
temp.CML_NEXT_ID = "1";
temp.ORG_ID = orgObj.ORG_ID;
temp.DEPT_ID = orgObj.DEPT_ID;
temp.KEY_VAL = _id;
temp.CML_ID = _id;
temp.CML_REF_ID = homeSecObj.KEY_VAL;
temp.ACTIVE_STATUS = "1";
temp.CML_IMAGE_PATH = "";
temp.SYNC_PENDING_STATUS = "1";
}
obj.dataArray.push(temp);
}
console.log("\n\genLLEles ==> ", obj, "\n\n");
/*return obj;*/
}
from the above code, the values in both the if and else are coming from same parameters. So you are inserting the same values multiple times into the dataArray.
I have two classes in Lua.
test1 = {test1Data = 123, id= {0,3}}
function test1:hello()
print 'HELLO!'
end
function test1:new (inp)
inp = inp or {}
setmetatable(inp, self)
self.__index = self
return inp
end
test2 = {}
function test2:bye ()
print 'BYE!'
end
function test2:create_inst( baseClass )
local new_class = {}
local class_mt = { __index = new_class }
function new_class:create()
local newinst = {}
setmetatable( newinst, class_mt )
return newinst
end
if baseClass then
setmetatable( new_class, { __index = baseClass } )
end
return new_class
end
a = test1:new({passData='abc'})
print (a.test1Data, a.passData, a:hello())
c = test2:create_inst(a)
print (c.test1Data, c.passData,c:hello(), c:bye())
I want to inherit test2 from test but leave in the specified test2 methods bye.
Everything works except for bye:method.
How can I solve this problem?
You return an empty table in test2:create_inst(), at no point does anything reference test2, so the function test2:bye() is not in the table returned by test2:create_inst()
In your code, test2 actually has nothing to do with the table you are instancing, this new_class table you return from test2:create_inst is the new instance. So naturally it has no field named bye. Simple modification:
function test2:create_inst( baseClass )
...
if baseClass then
setmetatable( new_class, { __index = baseClass } )
end
...
function new_class:bye()
print("bye!")
end
return new_class
end
I think the answer want to implement Multi-Inheritance that new_class inherit "test2" and "baseClass".
local function search(k, objlist)
local i = 0
local v
while objlist[i] then
v = objlist[i][k]
if v then return v end
end
end
function class(...)
local parents = (...)
local object = {}
function object:new(o)
o = o or {}
setmetatable(o, object)
return o
end
object.__index = object
setmetatable(object,
{__index=function(t, k)
search(k, parents)
end})
return object
end
c = class(a, test2)
print(c.test1Data, c.passData,c:hello(), c:bye())