Package com.exedio.cope.misc
Class ConnectToken
- java.lang.Object
-
- com.exedio.cope.misc.ConnectToken
-
- All Implemented Interfaces:
AutoCloseable
public final class ConnectToken extends Object implements AutoCloseable
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
boolean
didConnect()
int
getID()
Date
getIssueDate()
Model
getModel()
String
getName()
static ConnectProperties
getProperties(Model model)
static List<ConnectToken>
getTokens(Model model)
Returns the collection of openConnectToken
s on the model.boolean
isReturned()
static ConnectToken
issue(Model model, ConnectProperties properties, String tokenName)
Deprecated.Useissue(Model, String)
instead.static ConnectToken
issue(Model model, String tokenName)
Connects the model to the database described in the properties, if the model is not already connected.static ConnectToken
issueIfConnected(Model model, String tokenName)
Issues a ConnectToken, if the model is already connected.static ConnectProperties
removeProperties(Model model)
Deprecated.UseremovePropertiesVoid
instead.static void
removePropertiesVoid(Model model)
boolean
returnIt()
Deprecated.UsereturnStrictly()
insteadboolean
returnItConditionally()
Return false, if token was already returned.ConnectToken
returnOnFailureOf(Consumer<ConnectToken> target)
Callstarget
.boolean
returnStrictly()
static void
setProperties(Model model, ConnectProperties properties)
Sets the connect properties for the given model.static void
setProperties(Model model, Supplier<ConnectProperties> properties)
Sets the connect properties for the given model.String
toString()
boolean
wasConditional()
Returns true, if this token was issued byissueIfConnected(Model, String)
.
-
-
-
Method Detail
-
getModel
public Model getModel()
-
getID
public int getID()
-
getIssueDate
public Date getIssueDate()
-
getName
public String getName()
-
wasConditional
public boolean wasConditional()
Returns true, if this token was issued byissueIfConnected(Model, String)
. Returns false, if this token was issued byissue(Model, ConnectProperties, String)
.
-
didConnect
public boolean didConnect()
-
isReturned
public boolean isReturned()
-
returnStrictly
public boolean returnStrictly()
- Throws:
IllegalArgumentException
- if token was already returned. You may want to usereturnItConditionally()
instead.
-
returnItConditionally
public boolean returnItConditionally()
Return false, if token was already returned. You may want to usereturnStrictly()
instead.
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
returnOnFailureOf
public ConnectToken returnOnFailureOf(Consumer<ConnectToken> target)
-
setProperties
public static void setProperties(Model model, ConnectProperties properties)
Sets the connect properties for the given model. Enables usage ofissue(Model, String)
,issueIfConnected(Model, String)
,getTokens(Model)
.
-
setProperties
public static void setProperties(Model model, Supplier<ConnectProperties> properties)
Sets the connect properties for the given model. Enables usage ofissue(Model, String)
,issueIfConnected(Model, String)
,getTokens(Model)
.
-
getProperties
public static ConnectProperties getProperties(Model model)
-
removePropertiesVoid
public static void removePropertiesVoid(Model model)
- See Also:
setProperties(Model, ConnectProperties)
-
removeProperties
@Deprecated public static ConnectProperties removeProperties(Model model)
Deprecated.UseremovePropertiesVoid
instead. This method may fail at computing the result if used together withsetProperties(Model, Supplier)
and the supplier fails.- See Also:
setProperties(Model, ConnectProperties)
-
issue
public static ConnectToken issue(Model model, String tokenName)
Connects the model to the database described in the properties, if the model is not already connected. Can be called multiple times, but only the first time takes effect.Usually you may want to use this method, if you want to connect this model from different servlets with equal properties in an undefined order.
-
issueIfConnected
public static ConnectToken issueIfConnected(Model model, String tokenName)
Issues a ConnectToken, if the model is already connected. Otherwise the method returns null.Usually you may want to use this method, if you want to do something if the model is already connected, but in that case with a guarantee, that the model is not disconnected while doing those things.
Tokens returned by this method always do have
didConnect()
==false.- See Also:
wasConditional()
-
getTokens
public static List<ConnectToken> getTokens(Model model)
Returns the collection of openConnectToken
s on the model.Returns an unmodifiable snapshot of the actual data, so iterating over the collection on a live server cannot cause
ConcurrentModificationException
s.
-
returnIt
@Deprecated public boolean returnIt()
Deprecated.UsereturnStrictly()
instead
-
issue
@Deprecated public static ConnectToken issue(Model model, ConnectProperties properties, String tokenName)
Deprecated.Useissue(Model, String)
instead. Parameterproperties
is ignored.- Parameters:
properties
- is ignored
-
-